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

Why Does This Function Segfault?

This has been troubling me for some time; this function doesn't even return, it just segfaults. I specify a correct file location, I check for errors at every possible point in the function, I don't understand? GLchar* getShaderString(const GLchar*…
Shokwav
  • 654
  • 8
  • 19
3
votes
4 answers

x86_64 printf segfault after brk call

While i was trying do use brk (int 0x80 with 45 in %rax) to implement a simple memory manager program in assembly and print the blocks in order, i kept getting segfault. After a while i could only reproduce the error, but have no idea why is this…
gmb11
  • 33
  • 6
3
votes
2 answers

Segmentation Fault in SSL_CTX_new

I am trying to connect as a client over SSL and am seeing some strange behavior. I am getting an intermittent segmentation fault inside SSL_CTX_new when trying to create a new SSL context. It should also be noted that this is a fCGI demon, and only…
Stephen
  • 1,154
  • 11
  • 27
3
votes
2 answers

Segfault when mysql_stmt_close

I'm trying to query mysql 5.5 using C API. dbutil.c contains boilerplate code: #include "../include/dbutil.h" #include "../include/logging.h" #include "../include/common.h" MYSQL get_connection(char *host, char *user, char *passwd, char *db) { …
mkvcvc
  • 1,515
  • 1
  • 18
  • 41
3
votes
4 answers

String copy in C causing segmentation fault

I am trying to copy a string into another char pointer variable using strcpy function.But I always get segmentation fault.Here is my code. /* strcat example */ #include #include int main() { char str[100]=""; char *pch3; …
Teja
  • 13,214
  • 36
  • 93
  • 155
3
votes
2 answers

c++ floats and valgrind strange behaviour

I have valgrind 3.6.0, I've searched everywhere and found nothing. The problem is that when I'm trying to access a float number while using valgrind, I get a segfault, but when I run the program as is, without valgrind, everythings goes as…
3
votes
3 answers

Why does the cin extraction operator cause a segfault?

#include using namespace std; int main() { char * c; cin >> c; return 0; } I'm trying to get a C string line from the user whose length is not known. I know that if I declared c as char c[80] instead of char * c then it…
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
3
votes
2 answers

Very strange Segmentation fault analysis in GDB

I have application (server) written in C++ that are crashing around few hours, looks random probably. Worst part is i trying to debug any of core file using gdb and i see that result: gdb --core=core.668 --symbols=selectserver GNU gdb 6.8 Copyright…
Svisstack
  • 16,203
  • 6
  • 66
  • 100
3
votes
2 answers

Hide a Segmentation Fault Perl 5.8.8 with Threads and Perl TK

I've written a GUI using Perl TK and Threads. Everything works wonderfully until the program is exited. At this time I get a segmentation fault. I believe I'm managing my threads as well as I can and that the segmentation fault is simply due to…
3
votes
1 answer

Python PyEnchant Segmentation fault or invalid pointer

I have a multi-threaded Python application which calls PyEnchant. I am no Python expert and much of the code comes from a third party. What I have done is to add code to call PyEnchant from the multi-threaded application. Since I made the change the…
Dan-Dev
  • 8,957
  • 3
  • 38
  • 55
3
votes
1 answer

Segfault calling virtual method on initialized object

I'm getting a seg fault that I do not understand. I'm using the Wt library and doing some fancy things with signals (which I only mention because it has enabled me to attempt to debug this). I'm getting a pointer to one of my widgets from a vector…
Thomas Thorogood
  • 2,150
  • 3
  • 24
  • 30
3
votes
4 answers

Segmentation fault while emitting signal from other thread in Qt

When I am trying to emit a signal from another thread it causes a segfault, not sure why. Both the signal and slot are defined in the same class and running under the main GUI thread, but I call the emit in another function which is being controlled…
TopGun
  • 31
  • 1
  • 3
3
votes
1 answer

Android NDK C library causes seg fault

I'm having some trouble with c code from a library that I use with Android NDK. It works on the emulator, but not on a real device. It gives me a "libc - Fatal signal 11" (SIGSEGV) I have traced the problem to a piece of code in the library, but I'm…
Phaestion
  • 63
  • 8
3
votes
3 answers

Android NDK Segmentation Error

In my application when I try to print my logs into file at that Time facing Segmentation Error . I am facing Fatal Signal 11 . My log function is into Native part , I called it from Java . Logcat: 01-01 00:09:38.968: A/libc(3905): Fatal signal 11…
NovusMobile
  • 1,813
  • 2
  • 21
  • 48
3
votes
2 answers

printf %f Segmentation fault

I have this piece of code in a function. I want to print the value of y here. if (x1 < 0 || y1 < 0) { // Vertical lign outside of layer if (dx == 0 && y1 < 0) { return GKIT_NOERR; } float m = dy / dx; float t = y1 - m *…
Niklas R
  • 16,299
  • 28
  • 108
  • 203