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

Segfaulting calling a function

I have the following class heirarchy: ICSL::ISystemModel ICSL::ISystemModelAffine : public ISystemModel ICSL::Quadrotor::SystemModelQuadrotor : public QObject, ISystemModelAffine ICSL::Quadrotor::SystemModelQuadrotorSimulated : public public…
ryan0270
  • 1,135
  • 11
  • 33
2
votes
1 answer

Boost::Thread function leading to a segmentation fault on an embedded ARM

I'm having a weird problem with a threaded class using Boost::threads. Here is a brief summary of what I'm doing: A routine creates a bunch of objects that are made up of a handler class with a private data member that is a shared pointer to a base…
bencpeters
  • 149
  • 1
  • 10
2
votes
3 answers

Whats wrong with the given code

I am just learning some pointers stuff in C and I happened to learn that using the * one can dereference the pointer. So I wrote the following code to check for that. #include #include char *findChar(char *s, char c){ …
Abhishek
  • 2,543
  • 4
  • 34
  • 46
2
votes
2 answers

Why is gcc 4.7.0 giving me a segfault on this code while online ideone(gcc 4.5.1) doesnt?

I have the following code (works only on gcc): #include #include #include #include #include const std::string demangle (const char* name) { int status = -4; char* res =…
Jesse Good
  • 50,901
  • 14
  • 124
  • 166
2
votes
1 answer

how to determine libraries involved in segfault

I have nagios 3.2.3 running on CentOS 5.7, and something is causing it to segfault. recently many servers were added to the configuration so its hard to tell what additional directive is triggering the problem. However the nagios 3.2.3 package comes…
Tom
  • 3,324
  • 1
  • 31
  • 42
2
votes
5 answers

Not getting Segmentation Fault in C

here is the c code: char **s; s[334]=strdup("test"); printf("%s\n",s[334]);` i know that strdup does the allocation of "test", but the case s[334] where we will put the pointer to the string "test" is not allocated,however,this code works like a…
Amine Hajyoussef
  • 4,381
  • 3
  • 22
  • 26
2
votes
7 answers

Segmentation fault on typecasting void pointer to int

Seeing this thread I wrote the following: How do I convert from void * back to int #include #include using namespace std; int main (int argc, char *argv[]) { void* port = (void*) atoi (argv[1]); cout << "\nvalue: \n"…
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
2
votes
5 answers

Compiling C++ using -pthreads for Openwrt Linux-Get segmentation fault

I´m pretty new to programming in C++ and I´m using pthreads. I´m cross compiling my code for OpenWRT but for some reason I get segmentation fault when I run the program on my board but it runs fine on my PC. I suspect that the error occurs in the…
Stulli
  • 177
  • 1
  • 3
  • 9
2
votes
4 answers

freeing argument in function specified in pthread_create

I am writing a small server which creates a new thread to handle each new connection. I need to pass the socket to the function using the fourth argument of pthread_create. When trying to free the memory used for the socket i get a segfault. The…
tommyo
  • 531
  • 4
  • 10
2
votes
2 answers

segmentation fault when executing C code in ubuntu

When I compile the c file, gcc returns no errors, but a segmentation fault occurs at runtime. The debugger showed that the fault occurs in this part of the code: int q=size[current]; int *temp; temp = malloc ( sizeof(int)*q); …
Marwan Tushyeh
  • 1,505
  • 4
  • 24
  • 47
2
votes
5 answers

Weird segmentation fault in a C++ program before main

During some memory tests I did I got a segfault from the following program: #include #include using namespace std; int main() { cout << "Beginning Test" << endl; const int N = 2000000; string sArray[N]; return…
infokiller
  • 3,086
  • 1
  • 21
  • 28
2
votes
3 answers

Invalid read/write sometimes creates segmentation fault and sometimes does not

Example code: int main () { char b[] = {"abcd"}; char *c = NULL; printf("\nsize: %d\n",sizeof(b)); c = (char *)malloc(sizeof(char) * 3); memcpy(c,b,10); // here invalid read and invalid write printf("\nb: %s\n",b); printf("\nc:…
Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
2
votes
1 answer

SIGSEGV on Submission

i was solving the problem https://www.spoj.pl/problems/ACPC11A/ and here is my code : #include #include #include #include using namespace std; int main() { int tc,i,n; scanf("%d",&tc); while(tc--) { …
Amol Sharma
  • 1,521
  • 7
  • 20
  • 40
2
votes
2 answers

QTCreator segfault after 1st run

I've recently had a horrible problem with QTCreator. After the first time of running the program, ALL debugging instances segfault upon constructing the MainWindow object. Even if i make a blank QTwidget project and run in debug (without editing a…
jecjackal
  • 1,407
  • 2
  • 20
  • 35
2
votes
3 answers

Segmentation fault when pointer is local

I´m getting a segmentation fault with a pointer when it´s declared as local. The program is too long to copy it here, but it´s something like this: void f(){ int* p; int n = 0; for (...) { n++; p = realloc(p, n *…
Evans
  • 1,589
  • 1
  • 14
  • 25