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.

13352 questions
856
votes
17 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
  • 19,218
  • 15
  • 59
  • 57
342
votes
17 answers

What is a bus error? Is it different from a segmentation fault?

What does the "bus error" message mean, and how does it differ from a segmentation fault?
raldi
  • 21,344
  • 33
  • 76
  • 86
337
votes
19 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,491
  • 3
  • 18
  • 6
313
votes
32 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
  • 6,660
  • 8
  • 41
  • 68
238
votes
9 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
158
votes
57 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,371
  • 5
  • 34
  • 69
135
votes
7 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,481
  • 2
  • 10
  • 4
131
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
  • 5,391
  • 20
  • 65
  • 79
130
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,339
  • 5
  • 25
  • 29
117
votes
8 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
  • 3,396
  • 4
  • 31
  • 46
114
votes
7 answers

What causes a SIGSEGV?

What is the root cause of the segmentation fault (SIGSEGV), and how to handle it?
Vaibhav
  • 6,620
  • 11
  • 47
  • 72
112
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
  • 42,307
  • 41
  • 144
  • 212
112
votes
2 answers

What is SEGV_MAPERR?

What is SEGV_MAPERR, why does it always come up with SIGSEGV?
Geek
  • 23,089
  • 20
  • 71
  • 85
111
votes
16 answers

Why is a segmentation fault not recoverable?

Following a previous question of mine, most comments say "just don't, you are in a limbo state, you have to kill everything and start over". There is also a "safeish" workaround. What I fail to understand is why a segmentation fault is inherently…
Gulzar
  • 23,452
  • 27
  • 113
  • 201
109
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
  • 25,042
  • 81
  • 346
  • 663
1
2 3
99 100