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

Segmentation fault after sudo commands

I've modified (in some wrong way) the file etc/sudoers in my Mac OS X 10.6.8. For this reason I've erased the wrong line and replaced the original file. But now whenever I type sudo commands the output is: sudo: /etc/sudoers is owned by uid 501,…
Baduel
  • 531
  • 3
  • 12
  • 30
2
votes
1 answer

Segmentation Fault - Could not Access Memory, Kern_Invalid_Address

Im getting this error, what could this be??? Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000 0x00007fff86703c00 in strlen () I RAN THIS IN GDB and its the first thing that…
drodri420
  • 191
  • 2
  • 6
  • 14
2
votes
1 answer

Why doesn't this program segfault?

What causes the output "Hello" when I enable -O for gcc ? Shouldn't it still segfault (according to this wiki) ? % cat segv.c #include int main() { char * s = "Hello"; s[0] = 'Y'; puts(s); return 0; } % gcc segv.c &&…
vikraman
  • 358
  • 7
  • 14
2
votes
2 answers

SIGSEGV within std::sort, how to narrow it down

This is a related post to this one as it deals with the same program, but i now implemented it iterative and not recursive anymore, but I still get SIGSEGV (but later) while running the program. I did some other changes to my program to narrow it…
Sim
  • 4,199
  • 4
  • 39
  • 77
2
votes
1 answer

Why am I getting a segfault when trying to use Dr Brian Gladman's AES-GCM?

I am trying to use Dr Brian Gladman's famous AES encryption routines, in this case the Galois Counter Mode version, and I'm getting a segfault and can't find the cause. I've written a little demo program that shows what I'm trying to do and in fact…
John Lawrence Aspden
  • 17,124
  • 11
  • 67
  • 110
2
votes
4 answers

Big array gives segmentation error in C

I am really new to C, so I am sorry if this is a absolute beginner question, but I am getting a segmentation error when I am building large array, relevant bits of what I am doing is: unsigned long long ust_limit; unsigned long long arr_size; /*…
yasar
  • 13,158
  • 28
  • 95
  • 160
2
votes
1 answer

Meaning of casting the address of a void pointer

Lately, while working in C, I was developing a generic function. Here is the layout of structure: typedef struct student_{ char name[32]; int roll_no; unsigned int height; } student_t; and below is my function. What all the function…
stardep
  • 129
  • 1
  • 13
2
votes
1 answer

R crashes immediately on startup : caught segfault, address (nil), cause 'memory not mapped'

I recently installed R via conda install -c conda-forge r-base, but it crashes as soon as I try to launch it from terminal (see below). I've reserved 15G of memory for my session (should be plenty). Any suggestions would be much…
Jabber1
  • 69
  • 5
2
votes
1 answer

Calling an instance method only once

I am trying to write a class which has a method that can only be called once per object (well, it can be called multiple times, but it will only do something the first time). My example code is #include #include #include…
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
2
votes
1 answer

Why is loading ELF64 headers causing a segmentation fault?

I am trying to create an ELF64 file from scratch; the program I'm using to test it right now just calls the exit() syscall using assembly; there's no linking of libraries etc. Here's the output of "dumpelf": #include /* * ELF dump of…
2
votes
1 answer

Why this quicksort implementation gives correct output instead of garbage value?

In this code for quicksort, if input array is decreasing, for example 5 4 3 2 1 , variable i goes on incrementing without check and go out of array bound. Shouldn't that give segmentation error? As pointed out in replies, even if it doesnt give…
2
votes
1 answer

How do I troubleshoot a segmentation fault(core dumped) error in my cs50 speller code?

So I know it is shameless to ask someone on the internet to debug my code, but I have drained my pea-sized brain to the limit and I still can't solve this (my rubber duck has fled my desk in order to get some peace). All joking aside, I am having…
Gianluca
  • 33
  • 3
2
votes
3 answers

segfault when using mmap

I'm trying to use mmap for the first time to store a tree object with a lot of data in it. The tree class basically contains a pointer to the root of class Node, and each Node instance has an array of pointers to it's children. I think mmap is doing…
madshov
  • 653
  • 3
  • 9
  • 15
2
votes
3 answers

Segmentation fault when adding a vector. (C++)

So I've got a pretty basic class that has a few methods and some class variables. Everythings working great up until I add a vector to the member variables in the header file: std::vector vectorofstuff; If all I do is add this line…
adammenges
  • 7,848
  • 5
  • 26
  • 33
2
votes
0 answers

Sigsegv when executing 32bit programs

I am having problem when executing majority of 32bit software on my Linux. This problem happens when running any dynamically linked c++ software and also dynamic linked c programs that uses any libs outside standard c libs. Only statically linked…
user2752471
  • 444
  • 1
  • 6
  • 14