1
I created a program that keeps allocating 4 in 4 bytes of memory successively through a recursive function:
#include <stdio.h>
#include <stdlib.h>
#define BUF 2
void overflow(int payload){
payload = payload - 1;
int stack = (int)malloc(payload * sizeof(int));
payload = payload + 1;
overflow(payload);
}
int main(void){
overflow(BUF);
return 0;
}
It turns out that it stops working before it can consume all the memory this would be some kind of control of Windows itself to ensure the integrity of the system or is programming error even?
How could I get around this and let the program consume memory all the way to the top and when I get to the top stop allocating memory?
I’m using windows 7 64 bits
Stop working you mean it closes alone? Appears any message if run via CMD?
– Guilherme Nascimento
yes, it can only allocate up to 90% of the memory and to
– user45474
Okay, but you just answered "yes" ... I did two questions, I do not know if the yes was for first or second. So it closes alone? Yes or no? Have you tried running your program by calling/compiling via CMD? For example:
c:\Users\projeto>g++ meu.cpp -o meu.exe && meu.exe
. If you tried which error message appears when it ends?– Guilherme Nascimento
does not return me any error in compiling this code this functional seems to me that something related to language same dynamic allocation data structure and such it runs normal but when it arrives at 90% to allocate memory and windows cancels the execution of the program
– user45474
Have Antivirus on your PC?
– Guilherme Nascimento
I believe your problem may be stack overflow, due to several recursions involved. It seems to me that the standard size is 1 Mbytes: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686774(v=vs.85). aspx
– user5299
Here gave this problem: https://i.stack.Imgur.com/iolXN.png
– Guilherme Nascimento
@Guilhermenascimento does not have Antivirus only windows defend that this enabled
– user45474
I think the problem was in recursion even I put inside a while and it worked
– user45474
What version of mingw are you using? So I can test.
– Guilherme Nascimento
@Guilhermenascimento 6.3.0
– user45474