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

Android app crashes when generating list-view

Frameworks/Tools used for app development: jQuery Mobile 1.0.1 PhoneGap 1.3 Device/s used used for testing: Lenovo Thinkpad (Android 3.1) Sony experia (Android 2.3) Issue: App will always crash when dynamically generating a page (jQuery Mobile)…
ghostCoder
  • 1
  • 9
  • 49
  • 72
2
votes
6 answers

40 easy lines, 1 annoying segmentation fault. I really don't know where else to turn now

I apologize if this is a waste of time and/or not what should be on this site, but I'm kind of out of ideas... I'm still a novice at programming, can't get a hold of my teacher for guidance, so... TO THE…
fmdub
  • 17
  • 6
2
votes
1 answer

Segfault in recursive function

I'm getting a segfault when I run this code and I'm not sure why. Commenting out a particular line (marked below) removes the segfault, which led me to believe that the recursive use of the iterator "i" may have been causing trouble, but even after…
xyzzy
  • 23
  • 1
  • 4
2
votes
1 answer

C++: Why does dereferencing this vector iterator segfault?

void insert_string( std::vector & strings, const std::string &s ) { std::vector::iterator it=lower_bound(strings.begin(),strings.end(),s); if(strings.size()>0) std::cout<<*it<<" is found\n"; // **** …
Joseph
  • 12,678
  • 19
  • 76
  • 115
2
votes
3 answers

What are some common ways to debug segmentation faults in multi-threaded c++ applications?

I am new to threads and have put together a basic command line application using pthread's. I use pthread_create passing a struct as the final param; starting a new thread which calls "void *thread_routine (void *arg)". I have made a few…
Joemie
  • 31
  • 4
2
votes
1 answer

segmentation fault when deleting a map with struct being the keys

In my code I have a struct that I use as a map key: struct index{ int x; int y; int z; bool operator<(const index &b){ bool out = true; if ( x == b.x ){ if ( y == b.y ){ out = z < b.z; } else out = y < b.y; }…
Yotam
  • 10,295
  • 30
  • 88
  • 128
2
votes
1 answer

Segmentation fault on QPixmap::load

This is the code: void MainWindow::setPic(QString loc, int panel) { if(panel == 1) { loc1 = loc; QPixmap pmap; facedetect(loc1.toStdString(), 1, "CAND1.jpg"); qDebug() << "Loading : " << loc1; …
Rek
  • 571
  • 1
  • 6
  • 14
2
votes
4 answers

Segmentation fault backtracked to vfprintf?

I get a segmentation fault and using gdb and backtrace, it is thrown at vprintf. #0 0x006e8779 in vfprintf () from /lib/libc.so.6 #1 0x006f265f in fprintf () from /lib/libc.so.6 #2 0x08049fd1 in write_tofile (logfile=0x9843090 "~/www/log") at…
Kobi
  • 1,395
  • 4
  • 17
  • 23
2
votes
1 answer

Linux NASM OUTSB SegFault

I'm trying to write byte 0xff to the parallel port at 0x378. It compiles and links without issue, but segfaults at the OUTSB instruction. section .text global _start _err_exit: mov eax, 1 mov ebx, 1 …
tMC
  • 18,105
  • 14
  • 62
  • 98
2
votes
7 answers

Segmentation fault in hpricot

I'm using hpricot to read HTML. I got a segmentation fault error, I googled and some say upgrade to latest version of Ruby. I am using rails 2.3.2 and ruby 1.8.7. How to resolve this error?
user85748
  • 1,213
  • 3
  • 14
  • 21
2
votes
5 answers

Segfault when deleting pointer

I've been experiencing segfaults when running some C++ code. I've isolated the problem to a line in the program that deletes a pointer. Here's a simple example that produces the same error: int main() { int* pointer=0; int number = 3; …
rnorris
  • 1,571
  • 2
  • 17
  • 23
2
votes
2 answers

why segmentation fault occurs when using a window in a QSharedPointer?

I am developing a gui proram using Qt 4.7.4 (64 bit). I have tried to isolate the problem as follows: I have a window: class PreferencesWindow : public QMainWindow and in another class I initialize and show it as QSharedPointer
destan
  • 4,301
  • 3
  • 35
  • 62
2
votes
1 answer

MonoTouch Update Beta Chan / mono_handle_native_sigsegv

My app crashes on my device with the exception mono_handle_native_sigsegv I read that this is fixed in 5.1.1+ betas. How can I update my MonoTouch to 5.1.1+? Currently Im using MonoTouch 5.08 and MonoDevelop 2.8. I dont see the option to update on…
DarthVadar123451
  • 619
  • 1
  • 6
  • 14
2
votes
4 answers

Segmentation fault while reading file

My file looks like: 123456789 My code gives me segmentation fault: #include int main(){ FILE *f; char ch[5]; f = open("a.txt", "r"); fgets( ch, 4, f); ch[4] = NULL; printf("%s", ch); //Fixed return…
yetanotherstacker
  • 285
  • 2
  • 4
  • 12
2
votes
3 answers

Binary Search Tree root is working, but it can't have any children?

So I'm trying to create my own BST for a spellchecker because I want to additional functionality (find nearby nodes for suggestions). Anyways, I can create the root node, but after that it doesn't work. For example, if I have the following code: BST…
user114518