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
22
votes
1 answer

How to test if an address is readable in linux userspace app

For debugging purposes I need to test a pointer to see if it points to a valid readable page. Currently I am parsing /proc/[pid]/maps to see if the address is mapped ok, but this seems a bit long-winded. Is there a better way? Thanks.
gimmeamilk
  • 2,016
  • 5
  • 24
  • 36
22
votes
12 answers

Xcode 11.4 - Archiving project - Segmentation Fault 11

I Just updated Xcode to 11.4 and when archiving a project it shows me 'Segmentation Fault 11' This project would archive with Xcode 11.3.1 but now it doesn't.. Anyone else ran into the same issue? Edit: April 15th 2020 Apple just released Xcode…
Artur Marchetto
  • 646
  • 1
  • 5
  • 17
22
votes
11 answers

How to solve Android Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid xxxxx (Thread-X)?

I'm using Opencv sdk for Android to develop a real time processing and matching. The main Opencv traitment logic is in a JNI function. The problem is that sometimes (just sometimes) my app crashes without error, so I ignored the problem until I'm…
Amine
  • 2,241
  • 2
  • 19
  • 41
21
votes
1 answer

How does Rust guarantee memory safety and prevent segfaults?

I was looking for a language to learn, and I saw that Rust is getting quite popular. Two things impressed me about Rust, memory safety and preventing segfaults. How does Rust achieve this? What differences between Rust and Java for example enable…
Myra
  • 321
  • 1
  • 2
  • 7
21
votes
4 answers

Empty core dump file after Segmentation fault

I am running a program, and it is interrupted by Segmentation fault. The problem is that the core dump file is created, but of size zero. Have you heard about such a case and how to resolve it? I have enough space on the disk. I have already…
Ali
  • 9,440
  • 12
  • 62
  • 92
21
votes
6 answers

Catch Segmentation fault in c++

Does a try-catch block catch segmentation fault errors? I am reading a text file using the function given below but sometimes the file is empty and the program crashes. I would like the program to continue running and provide another file when this…
rajat
  • 3,415
  • 15
  • 56
  • 90
21
votes
4 answers

Why does malloc not work sometimes?

I'm porting a C project from Linux to Windows. On Linux it is completely stable. On Windows, it's working well most times, but sometimes I got a segmentation fault. I'm using Microsoft Visual Studio 2010 to compile and debug and looks like sometimes…
Pedro Alves
  • 1,667
  • 4
  • 17
  • 37
20
votes
2 answers

Why does java app crash in gdb but runs normally in real life?

Attempting to run java app from gdb results in segfault, yet running app alone does not. This app is a .JAR which uses JOGL and a bit of memory-mapping to talk to the GPU. Stacktrace below hints at some sort of memory access problem but I don't…
user515655
  • 989
  • 2
  • 10
  • 24
20
votes
3 answers

Capture "Segmentation fault" message for a crashed subprocess: no out and err after a call to communicate()

I have problems using the subprocess module to obtain the output of crashed programs. I'm using python2.7 and subprocess to call a program with strange arguments in order to get some segfaults In order to call the program, I use the following…
Tic
  • 421
  • 1
  • 5
  • 14
19
votes
8 answers

strtok segmentation fault

I am trying to understand why the following snippet of code is giving a segmentation fault: void tokenize(char* line) { char* cmd = strtok(line," "); while (cmd != NULL) { printf ("%s\n",cmd); cmd = strtok(NULL, " "); }…
user1162954
  • 267
  • 2
  • 4
  • 7
19
votes
3 answers

App crashes (sometimes) with Fatal signal 11 (SIGSEGV), code 1

I am developing an app with the HERE SDK, and everything worked fine until now. I get errors like this one: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x750057 in tid 10206 (FinalizerDaemon) or this one: Fatal signal 11 (SIGSEGV), code 1, fault…
David Seroussi
  • 1,650
  • 2
  • 17
  • 34
18
votes
2 answers

Weird SIGSEGV segmentation fault in std::string::assign() method from libstdc++.so.6

My program recently encountered a weird segfault when running. I want to know if somebody had met this error before and how it could be fixed. Here is more info: Basic info: CentOS 5.2, kernal version is 2.6.18 g++ (GCC) 4.1.2 20080704 (Red Hat…
yaobin
  • 2,436
  • 5
  • 33
  • 54
18
votes
5 answers

C: How to pass a double pointer to a function

I am getting an segmentation fault when I pass the double pointers to the function to initialize the memory int main() { double **A; initialize(A, 10, 10); ...... } void initialize(double **A, int r, int c) { A = (double…
veda
  • 6,416
  • 15
  • 58
  • 78
18
votes
3 answers

Meaning of Exit Code 11 in C?

What's the general meaning of an exit code 11 in C? I've looked around and can not find a definitive answer so I thought I would ask here. It comes when i try to add an element to a vector.
user3593148
  • 505
  • 1
  • 3
  • 14
18
votes
6 answers

Segmentation Fault when using strtok_r

Can anyone explain why I am getting segmentation fault in the following example? #include #include int main(void) { char *hello = "Hello World, Let me live."; char *tokens[50]; strtok_r(hello, " ,", tokens); int i = 0; …