Questions tagged [segmentation-fault]

Segmentation faults occur when accessing memory which does not belong to your process. Use this tag along with a tag indicating the language and a tag indicating the operating system. Segmentation faults are typically the result of a dereference operation with pointer variables (most often containing an invalid address) or a buffer overflow. The root cause for an invalid pointer value may be far from the location generating the segmentation fault.

Segmentation faults occur when accessing memory which does not belong to your process. They are common and typically the result of:

  • using a pointer to something that has been deallocated;
  • using an uninitialized hence bogus pointer;
  • using a pointer;
  • overflowing a buffer; or
  • attempting to write to read-only memory

The error does not arise when manipulating the pointer variable itself (copying or assigning the pointer variable), but when accessing the memory the variable points to (i.e. dereferencing the pointer variable). To generate the segmentation fault, will deliver 11 to the process which has made illegal memory access. The default action of having segmentation fault is , generating a coredump file with basic process information.

Since the point where the segmentation fault is triggered may be far from the location where the environment and actions that generate the conditions for the segmentation fault, finding the root cause can be difficult, especially in a complex, multi-threaded application.

Segmentation fault is descriptive phrase from Unix and Linux families of operating systems labeling a general class of behavior in which the operating system detects a memory access by a process outside of the process' assigned memory resulting in the operating system terminating the process.

This behavior requires hardware support for protected memory which may not be available in some microprocessors.

Additional information can be found on...

If the program crashed due to

  1. unauthorized memory access
  2. using out-of-bound memory location
  3. using of uninitialized memory

and it has received SIGSEGV and/or a coredump file is getting generated, mark your questions using this tag.

12123 questions
690
votes
16 answers

What is a segmentation fault?

What is a segmentation fault? Is it different in C and C++? How are segmentation faults and dangling pointers related?
Rajendra Uppal
  • 16,504
  • 15
  • 55
  • 57
308
votes
17 answers

Why do I get a segmentation fault when writing to a "char *s" initialized with a string literal, but not "char s[]"?

The following code receives seg fault on line 2: char *str = "string"; str[0] = 'z'; // could be also written as *str = 'z' printf("%s\n", str); While this works perfectly well: char str[] = "string"; str[0] = 'z'; printf("%s\n", str); Tested…
Markus
  • 3,201
  • 3
  • 16
  • 6
290
votes
15 answers

What is a bus error?

What does the "bus error" message mean, and how does it differ from a segfault?
raldi
  • 19,496
  • 29
  • 73
  • 85
263
votes
26 answers

Android Fatal signal 11 (SIGSEGV) at 0x636f7d89 (code=1). How can it be tracked down?

I've been reading the other posts on tracking down the reasons for getting a SIGSEGV in an Android app. I plan to scour my app for possible NullPointers related to Canvas use, but my SIGSEGV barfs up a different memory address each time. Plus I've…
dubmojo
  • 5,753
  • 8
  • 36
  • 61
181
votes
6 answers

Determine the line of code that causes a segmentation fault?

How does one determine where the mistake is in the code that causes a segmentation fault? Can my compiler (gcc) show the location of the fault in the program?
user319824
152
votes
56 answers

Command failed due to signal: Segmentation fault: 11

I'm getting the error ... Command failed due to signal: Segmentation fault: 11 ... when trying to compile my Swift app. I'm using Xcode 6.1, trying to build for an iPhone 5 on iOS 8.1. My Code import UIKit class ViewController: UIViewController…
Alec.
  • 5,128
  • 4
  • 27
  • 63
124
votes
6 answers

Segmentation fault on large array sizes

The following code gives me a segmentation fault when run on a 2Gb machine, but works on a 4GB machine. int main() { int c[1000000]; cout << "done\n"; return 0; } The size of the array is just 4Mb. Is there a limit on the size of an array…
Mayank
  • 1,361
  • 2
  • 9
  • 4
116
votes
3 answers

Why does this code segfault on 64-bit architecture but work fine on 32-bit?

I came across the following C puzzle: Q: Why does the following program segfault on IA-64, but work fine on IA-32? int main() { int* p; p = (int*)malloc(sizeof(int)); *p = 10; return 0; } I know that the size of int on…
user7
  • 2,159
  • 5
  • 24
  • 29
105
votes
6 answers

Fixing Segmentation faults in C++

I am writing a cross-platform C++ program for Windows and Unix. On the Window side, the code will compile and execute no problem. On the Unix side, it will compile however when I try to run it, I get a segmentation fault. My initial hunch is that…
Elpezmuerto
  • 4,891
  • 19
  • 60
  • 78
97
votes
2 answers

What is SEGV_MAPERR?

What is SEGV_MAPERR, why does it always come up with SIGSEGV?
Geek
  • 21,584
  • 19
  • 68
  • 85
93
votes
4 answers

How can I catch SIGSEGV (segmentation fault) and get a stack trace under JNI on Android?

I'm moving a project to the new Android Native Development Kit (i.e. JNI) and I'd like to catch SIGSEGV, should it occur (possibly also SIGILL, SIGABRT, SIGFPE) in order to present a nice crash reporting dialog, instead of (or before) what currently…
89
votes
7 answers

What causes a Python segmentation fault?

I am implementing Kosaraju's Strong Connected Component(SCC) graph search algorithm in Python. The program runs great on small data set, but when I run it on a super-large graph (more than 800,000 nodes), it says "Segmentation Fault". What might be…
xiaolong
  • 2,876
  • 3
  • 23
  • 38
88
votes
5 answers

How to catch segmentation fault in Linux?

I need to catch segmentation fault in third party library cleanup operations. This happens sometimes just before my program exits, and I cannot fix the real reason of this. In Windows programming I could do this with __try - __catch. Is there…
Alex F
  • 39,172
  • 34
  • 138
  • 200
79
votes
2 answers

Compile and run program without main() in C

I'm trying to compile and run following program without main() function in C. I have compiled my program using the following command. gcc -nostartfiles nomain.c And compiler gives warning /usr/bin/ld: warning: cannot find entry symbol _start;…
msc
  • 30,333
  • 19
  • 96
  • 184
76
votes
5 answers

How to debug a Python segmentation fault?

How can I debug a Python segmentation fault? We are trying to run our python code on SuSE 12.3. We get reproducible segmentation faults. The python code has been working on other platforms without segmentation faults, for years. We only code Python,…
guettli
  • 26,461
  • 53
  • 224
  • 476
1
2 3
99 100