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
18
votes
3 answers

sort function C++ segmentation fault

In this code, for vector size, n >=32767, it gives segmentation fault, but upto 32766, it runs fine. What could be the error? This is full…
avd
  • 13,993
  • 32
  • 78
  • 99
18
votes
1 answer

String literals: pointer vs. char array

In this statement: char *a = "string1" What exactly is string literal? Is it string1? Because this thread What is the type of string literals in C and C++? says something different. Up to my knowledge int main() { char *a = "string1"; //is a…
Jeyaram
  • 9,158
  • 7
  • 41
  • 63
17
votes
5 answers

How do I debug Segfaults occurring in the JVM when it runs my code?

My Java application has started to crash regularly with a SIGSEGV and a dump of stack data and a load of information in a text file. I have debugged C programs in gdb and I have debugged Java code from my IDE. I'm not sure how to approach C-like…
Hanno Fietz
  • 30,799
  • 47
  • 148
  • 234
17
votes
5 answers

Why won't my code segfault on Windows 7?

This is an unusual question to ask but here goes: In my code, I accidentally dereference NULL somewhere. But instead of the application crashing with a segfault, it seems to stop execution of the current function and just return control back to the…
Trevor
  • 719
  • 1
  • 6
  • 15
17
votes
3 answers

configure: error: cannot run C compiled programs

I'm trying to install different software onto my Raspberry Pi with Debian Wheezy OS. When I run try to configure software I'm trying to install I get this output checking for C compiler default output file name... a.out checking for suffix of…
user2748943
  • 533
  • 2
  • 9
  • 20
17
votes
1 answer

Empty program segfaulting

I have an empty program (module Main where main = return ()) which segfaults if I include a specific library in build-depends, in cabal file. The library is my own, and the segfault is some sort of interaction of bumblebee drivers with opengl and…
Karolis Juodelė
  • 3,708
  • 1
  • 19
  • 32
17
votes
1 answer

Determining if a python subprocess segmentation faults

I am writing a program that grades student programs, and as I am sure you can imagine, they sometimes segmentation fault. The problem I am having is that when the student programs segmentation fault, there is no indication that is what…
zelinka
  • 3,271
  • 6
  • 29
  • 42
17
votes
5 answers

Pointer initialisation gives segmentation fault

I wrote a C program as follows: CASE 1 int *a; /* pointer variable declaration */ int b; /* actual variable declaration */ *a=11; a=&b;/* store address of b in pointer variable*/ It gives a segmentation fault when running the program. I changed…
EnterKEY
  • 1,180
  • 3
  • 11
  • 25
17
votes
2 answers

SIGSEGV SEGV_ACCERR Crash Reports - What to do?

I've just released an app on the AppStore with Crittercism crash reporting and I've been getting quite a few crash reports pertaining to a SIGSEGV error. Crittercism gives me a StackTrace and a few handy details about usage statistics, etc. however,…
Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
16
votes
4 answers

GDB doesn't show function names

I am debugging from an embedded device using gdbserver: ./gdbserver HOST:5000 /home/test_app In my PC, I execute gdb in this way: arm-none-linux-gnueabi-gdb test_app Once the application is executing, I receive the Segfault I want to debug, but…
funkadelic
  • 311
  • 1
  • 2
  • 10
16
votes
2 answers

python/pycharm project produces segmentation fault in debug mode, but not in run mode

Oddly, in debug mode, if the script is stopped (via a breakpoint) where the segfault would normally occur (without the breakpoint), and then resumed, the segmentation fault will not happen. Very strange right? This project uses pycharm and pygame.…
Frank Larry
  • 161
  • 6
16
votes
2 answers

Sun JVM (JRE jre1.6.0_24) segfault NET_Read

Our JVM crashes with segmentation fault from time to time in production with what feels like a race condition of some sort. Setups to reproduce: - JRE jre1.6.0_24 on Linux Ubuntu 9.10 and Debian 4.x 64 bit multicore AMD - Apache tomcat 6.0.24 ...…
Hisham
  • 593
  • 5
  • 13
16
votes
5 answers

Getting Segmentation Fault

I saw many questions about getting segmentation fault in C program here in SO, and I thought it would be great to have a reference to those here, a question with some cases that are causing segmentation fault. My answer is posted below. As written…
MByD
  • 135,866
  • 28
  • 264
  • 277
16
votes
2 answers

Nasm - Symbol `printf' causes overflow in R_X86_64_PC32 relocation

I am trying to create a simple program in nasm that should display the letter a. however, It is giving me a Segfault and saying this: ./a.out: Symbol `printf' causes overflow in R_X86_64_PC32 relocation Segmentation fault (core dumped) Basically,…
Unknown
  • 181
  • 1
  • 1
  • 6
16
votes
13 answers

Coming back to life after Segmentation Violation

Is it possible to restore the normal execution flow of a C program, after the Segmentation Fault error? struct A { int x; }; A* a = 0; a->x = 123; // this is where segmentation violation occurs // after handling the error I want to get back…
Marc Andreson
  • 3,405
  • 5
  • 35
  • 51