Why glibc’s fclose(NULL) cause segmentation fault instead of returning error?

fclose requires as its argument a FILE pointer obtained either by fopen, one of the standard streams stdin, stdout, or stderr, or in some other implementation-defined way. A null pointer is not one of these, so the behavior is undefined, just like fclose((FILE *)0xdeadbeef) would be. NULL is not special in C; aside from the … Read more

Why stack overflow on some machines, but segmentation fault on another?

Why is it I get segmentation faults instead? The segmentation fault, what you’re seeing, is a side-effect of the stack overflow. The reason is stack overflow, the result is segmentation fault. From the wikipedia article for “stack overflow” (emphasis mine) …. When a program attempts to use more space than is available on the call … Read more

Can one use libSegFault.so to get backtraces for SIGABRT?

env SEGFAULT_SIGNALS=”abrt segv” LD_PRELOAD=/lib/libSegFault.so someapp Note that the actual path to the preload library may differ. On my machine, I’d use env SEGFAULT_SIGNALS=”abrt segv” LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so some-64bit-app or env SEGFAULT_SIGNALS=”abrt segv” LD_PRELOAD=/lib/i386-linux-gnu/libSegFault.so some-32bit-app depending whether the application I was running was compiled 64-bit or 32-bit. (You can use file to check.) The source tells us there … Read more

strcpy()/strncpy() crashes on structure member with extra space when optimization is turned on on Unix?

What you are doing is undefined behavior. The compiler is allowed to assume that you will never use more than sizeof int64_t for the variable member int64_t c. So if you try to write more than sizeof int64_t(aka sizeof c) on c, you will have an out-of-bounds problem in your code. This is the case … Read more

techhipbettruvabetnorabahisbahis forumu