segmentation-fault
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
What is a segmentation fault on Linux?
A segmentation fault is when your program attempts to access memory it has either not been assigned by the operating system, or is otherwise not allowed to access. “segmentation” is the concept of each process on your computer having its own distinct virtual address space. Thus, when Process A reads memory location 0x877, it reads … Read more
Pycharm debugger instantly exits with 139 code
I’ve fixed it by disabling PyQt compatible option in PyCharms’s debugger settings (Build, Execution, Deployment > Python Debugger). I don’t use PyQt, so I have not met any troubles
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
Returning this pointer from a function
Allocate memory before using the pointer. If you don’t allocate memory *point = 12 is undefined behavior. int *fun() { int *point = malloc(sizeof *point); /* Mandatory. */ *point=12; return point; } Also your printf is wrong. You need to dereference (*) the pointer. printf(“%d”, *ptr); ^