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

Initializing the D runtime on OS X

Edit: this seems to be a longrunning issue with no imminent solution: …
John_C
  • 788
  • 5
  • 17
3
votes
2 answers

How are OpenGL programs debugged?

I'm trying to find what is causing a segfault when glDrawArrays is called (as gdb says) in my simple program. When I use the OpenGl calls directly, the program runs fine. But when I wrap them up into two classes (under construction, of vao and vbo)…
manasij7479
  • 1,665
  • 1
  • 14
  • 22
3
votes
1 answer

iOS Mapkit crash when using selectannotation

I am having trouble figuring out the cause of this crash. I have an iPad application with a MapView and Tableview on the same screen. I am trying to allow the user to select a row in the table to then highlight the corresponding pin in the map or…
3
votes
4 answers

Why is this reverse string function giving a seg fault?

I want to make a reverse string function and I have done it like this: void reverse_str(char s[]) { int i, j; char ch; for(i = 0, j = strlen(s) - 1; i < j; i++, j--) { ch = s[i]; s[i] = s[j]; s[j] = ch; } …
user804371
3
votes
1 answer

Segmentation fault when using taps to export database from heroku

I'm using taps to export PostgreSql database from Heroku to my locally Mysql2 database, when I run the following commands in terminal, heroku db:pull mysql2://root:@127.0.0.1/spendon_dev --app huanarle it says…
jimhj
  • 53
  • 6
3
votes
3 answers

c++ linux monitor processes for sigsegv

I want to write a c++ program for linux which monitors all processes running and write to a log file when any of those processes crashes due to sigsegv. Is it possible to do this and if so what should I learn in order to implement it in c++?
chamal
  • 1,103
  • 1
  • 8
  • 6
3
votes
3 answers

Why does strcpy fail with char *s but not with char s[1024]?

Why does the following happen: char s[2] = "a"; strcpy(s,"b"); printf("%s",s); --> executed without problem char *s = "a"; strcpy(s,"b"); printf("%s",s); --> segfault Shouldn't the second variation also allocate 2 bytes of memory for s and thus…
erikbstack
  • 12,878
  • 21
  • 81
  • 115
3
votes
3 answers

C: Array initialization segfaults depending on size and call to printf()

Another student asked me what could be wrong with his C code. I successfully reproduced the erroneous behavior and have completely no idea why this segfaults. Consider this tiny C programm: #include int main(void) { int N = 590; …
f4lco
  • 3,728
  • 5
  • 28
  • 53
3
votes
3 answers

How can I "catch" a seg fault while importing an F2Py module?

Some background, the relevance of which may fluctuate: I am currently in possesion of some F2Py libraries - Python modules compiled by F2Py from some Fortran code. For all intents and purposes, you can regard these modules as "third party"; I…
JimmidyJoo
  • 10,503
  • 7
  • 27
  • 30
3
votes
1 answer

segmentation fault implementing linkedlist

I have the following simple code but it is throwing segmentation fault. Can someone point what I am doing wrong? The segmentation fault comes after I input the first number. #include #include struct linked_list { …
Richa Sachdev
  • 2,937
  • 3
  • 17
  • 12
3
votes
0 answers

websocketpp/boost: SIGSEGV on endpoint.get_connection(uri)

I'm working on a loadtest app in C++ which is intended to test - among other things - the streaming capabilities of our audio servers. For this client, I'm using websocketpp and followed this example. I always get a sigsegv in the line con =…
Rip-Off
  • 358
  • 1
  • 4
  • 14
3
votes
3 answers

C string literal handling

What's wrong with the following piece of code that the program crashes - give segmentation fault. I am using gcc. uint8_t result = 1 InsertRow("Name","Details of work",result); void InsertRow(char *Name, char *Description,uint8_t…
user1377944
  • 425
  • 2
  • 5
  • 12
3
votes
1 answer

pthread: do other threads stop while the SIGSEGV handler runs?

I develop a program on Solaris 10. I want it to print stack trace on crash. I found this example: static void pstack() { char buf[256]; sprintf(buf, "/usr/proc/bin/pstack %d |/bin/tee traceback.txt\n", (int)getpid()); /* undefine LD_PRELOAD…
basin
  • 3,949
  • 2
  • 27
  • 63
3
votes
3 answers

linux: where's the "real" segmentation fault handler?

If I read/write/jump to an ummapped address ie. .text .global _start _start: movl $1,%edx jmp *%edx this causes a segmentation fault. I wonder, what's the actual part of the system (kernel) that intercepts reads/writes to…
gpilotino
  • 13,055
  • 9
  • 48
  • 61
3
votes
1 answer

How can I figure out where and why this segmentation fault occurs?

I'm having trouble figuring out the problem with my code...I'm in the early stages of prototyping a game (my first serious project). It frequently, but not always, crashes with a segmentation fault. Here's the flow of the program... title screen…
rzrscm
  • 89
  • 8