3 ms·
I don't want to test on somebody's server and cause them to have a bad day, but does this thing have proper stack overflow/memory protection? #include <stdio
by onewland 17y ago
I don't want to test on somebody's server and cause them to have a bad day, but does this thing have proper stack overflow/memory protection?
#include <stdio.h>
int evil(int y)
{
char *x = (char *) malloc(y);
return(evil(y+1)-evil(y+2));
}
int main(int argc, char **argv)
{
int a = evil(1);
return 0;
}
- onewland 17y agoI'm getting an infinite (>5m wait time) "waiting for compilation" message with the above code. Are you trying to traverse function calls before compilation? You'll eventually run into the halting problem (http://en.wikipedia.org/wiki/Halting_problem http://en.wikipedia.org/wiki/Halting_problem) if this is your approach, though there may be a way to determine cases as simple as mine.
- gacek 17y agoIt won't compile ;) (no stdlib.h/string.h) And it won't crash the server (at least... should not). There is a fixed limit on how much memory a process can allocate. This program will crash, but not because of malloc, just because the recursion gets too deep (stack overflow).
- onewland 17y agoMaybe it won't compile, but: /spoj/c_run: line 5: 3844 Segmentation fault ./prog is the error I got, and that doesn't look like a compile error. (Also, just to be pedantic, I had noted the stack overflow possibility in my original post). http://ideone.com/view/09u9091w9h# http://ideone.com/view/09u9091w9h# is the snippet.
- deleted 17y ago[deleted]