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

C++ DLL crashes upon allocating memory

I have created my own DLL and am calling methods using LoadLibrary/GetProcAddress. The application crashes whenever "new" is used. Below is the complete code. test_app.cpp #include int main() { typedef int (*Test)(); HINSTANCE…
2
votes
3 answers

Segmentation fault after defining my own malloc?

Why does this result in a segmentation fault? #include void *malloc(size_t s) { }; int main() { printf("lol"); …
2
votes
1 answer

std::pair returned by std::transform resulting in segfault

I'm trying to transform a vector of strings to a vector of pairs of strings, and I was getting segfault. I've tried to narrow it down to a simple test case (below), and I'm sure it's likely to do with the memory allocation: #include…
abbe
  • 123
  • 4
2
votes
0 answers

Seg Fault when running fgets() in a function outside of main() on ESXi

I am creating a tool for managing my VMs on my ESXi servers. I am parsing the output from popen() from running vim-cmd commands. The issue is when calling fgets() in a function outside of main(). If I call it inside of main() it works without…
2
votes
2 answers

segmentation fault after building rgl on R 4.2.0 and Ubuntu 18.04

I'm trying to install rgl on a R 4.2.0 installation that I have installed from source, on a Ubuntu 18.04 system. The package seems to be building correctly, however I get a Segmentation fault when R tries to test whether it can load the package.…
tmt
  • 83
  • 4
2
votes
1 answer

c: catch a segfault in exec() which was run in a child process

EDIT: I am trying to write a simple smoketest, where all options and reasonable parameters are tested. I used popen() to execute the program that should be tested. Using this approach does not work, because if the process dies with a signal (SIGINT,…
Florian
  • 512
  • 1
  • 6
  • 12
2
votes
3 answers

Segmentation fault, can you help me?

Im getting a segmentation fault when trying to display an element of type (int) template void Lista::imprimir() { NodoL *ptr = new NodoL; ptr->sig = pri->sig; cout << *ptr->sig->elem; //THIS DISPLAYS CORRECTLY cout <<…
HoNgOuRu
  • 717
  • 4
  • 13
  • 26
2
votes
0 answers

SIGSEGV handler receives strange address in info->si_addr on arm

This is on Android 12 on a Pixel 6. I am installing a SIGSEGV handler to catch and handle on purpose generated segmentation faults. This works as expected but I am observing a single case where the info->si_addr passed to the handler is not what I…
hiddenbit
  • 333
  • 1
  • 2
  • 11
2
votes
2 answers

I have written this Merge Sort program in C. It shows "Segmentation fault (core dumped)" after implementation of arrays

#include void mergesort(); void merge(); int main() { int a[40], n; printf("\nEnter the number of elements:"); scanf("%d", &n); printf("\nEnter the %d elements:", n); for (int i = 0; i < n; i++) { …
2
votes
1 answer

How to solve Assertion Fail in GCC Compiler, C++

Hello dudes and dudettes! When I compile my C++ program on Ubuntu (a VirtualMachine in VirtualBox), which previously ran without errors under Windows, I get a segmentation fault. /usr/bin/ld: BFD (GNU Binutils for Ubuntu) 2.38 assertion fail…
rafa
  • 35
  • 5
2
votes
0 answers

FFMPEG SIGSEGV error after firebase deploy

I am trying to deploy a node project to firebase. The project uses Fluent-FFMPEG and works fine when using the firebase emulator. However, after deploying to firebase and running the function I get an error saying "ffmpeg was killed with signal…
2
votes
3 answers

Segmentation fault on vector class implementation

As for many coding tests STL is not allowed so I am trying to implement vector class. To represent the graph I am using an adjacency list. It's giving me segmentation fault at new_allocation method. Also sometimes I get correct output when I run…
2
votes
3 answers

Segmentation fault and run time error

Possible Duplicate: Modifying value of char pointer in c produces segfault This is a piece of code ... void main() { char *p="Hello"; *p= 'h'; // Segmentation fault . } I understand the fact that there is a…
progammer
  • 1,951
  • 11
  • 28
  • 50
2
votes
2 answers

Segmentation fault when calling printf from C function called from assembly

I tried to implement the quicksort in x86-64 Assembler, on Linux. Since I'm not fully comfortable with it yet, I wrote the partition algorithm in C. It seems to work but something must be off, because adding a call to fprintf in my C code (that the…
2
votes
1 answer

Idiomatic way to handle signals in a shared library

I have a shared library that occasionally throws SIGSEGV by design. I can find out if a SIGSEGV is caused by me, and if it is then handle it. However I ran into some problems when implementing the other branch (ie. when it isn't my SIGSEGV). My…
1 2 3
99
100