strtok segmentation fault

The problem is that you’re attempting to modify a string literal. Doing so causes your program’s behavior to be undefined. Saying that you’re not allowed to modify a string literal is an oversimplification. Saying that string literals are const is incorrect; they’re not. WARNING : Digression follows. The string literal “this is a test” is of an expression of type char[15] (14 … Read more

Segmentation fault- strcat

You don’t have enough space in fn. By strcat’ing on to it you overwrite the end of its stack allocation and into the stack .. hence the segmentation fault. You could try the following instead: You just have to be sure that the whole path and filename can fit into 255 characters. Alternatively you could … Read more

segmentation fault using scanf

You need to initialize your pointers. Alternatively, use stack-allocated arrays. For example, instead of char *name, do char name[20]. (Note that this will limit your input to 19 characters; use a larger buffer if necessary.) Right now, you are passing uninitialized pointers into scanf() which effectively means that scanf() is going to write to an … Read more

Fixing Segmentation faults in C++

Compile your application with -g, then you’ll have debug symbols in the binary file. Use gdb to open the gdb console. Use file and pass it your application’s binary file in the console. Use run and pass in any arguments your application needs to start. Do something to cause a Segmentation Fault. Type bt in the gdb console to get a stack trace of the Segmentation Fault.

What causes a Python segmentation fault?

This happens when a python extension (written in C) tries to access a memory beyond reach. You can trace it in following ways. Add sys.settrace at the very first line of the code. Use gdb as described by Mark in this answer.. At the command promptgdb python (gdb) run /path/to/script.py ## wait for segfault ## (gdb) backtrace ## stack trace of the c code