Why does const int main = 195 result in a working program but without the const it ends in a segmentation fault?

Observe how the value 195 corresponds to the ret (return from function) instruction on 8086 compatibles. This definition of main thus behaves as if you defined it as int main() {} when executed. On some platforms, const data is loaded into an executable but not writeable memory region whereas mutable data (i.e. data not qualified … Read more

Can a stack overflow result in something other than a segmentation fault?

Yes, even on a standard OS (Linux) and standard hardware (x86). void f(void) { char arr[BIG_NUMBER]; arr[0] = 0; // stack overflow } Note that on x86, the stack grows down, so we are assigning to the beginning of the array to trigger the overflow. The usual disclaimers apply… the exact behavior depends on more … Read more

segmentation fault vs page fault

These two things are very dissimilar, actually. A segmentation fault means a program tried to access an invalid or illegal memory address: for example, 0, or a value larger than any valid pointer. A page fault is when a pointer tries to access a page of address space that’s currently not mapped onto physical memory, … Read more

Segfault on declaring a variable of type vector

Given the point of crash, and the fact that preloading libpthread seems to fix it, I believe that the execution of the two cases diverges at locale_init.cc:315. Here is an extract of the code: void locale::_S_initialize() { #ifdef __GTHREADS if (__gthread_active_p()) __gthread_once(&_S_once, _S_initialize_once); #endif if (!_S_classic) _S_initialize_once(); } __gthread_active_p() returns true if your program is … Read more

Segfaults in malloc() and malloc_consolidate()

From http://www.gnu.org/s/libc/manual/html_node/Heap-Consistency-Checking.html#Heap-Consistency-Checking: Another possibility to check for and guard against bugs in the use of malloc, realloc and free is to set the environment variable MALLOC_CHECK_. When MALLOC_CHECK_ is set, a special (less efficient) implementation is used which is designed to be tolerant against simple errors, such as double calls of free with the same … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)