segmentation-fault

Segfault on stack overflow

Why does the linux kernel generate a segfault on stack overflow? This can make debugging very awkward when alloca in c or fortran creation of temporary arrays overflows. Surely it mjust be possible for the runtime to produce a more helpful error. ...

Why does strcpy trigger a segmentation fault with global arguments?

So I've got some C code: #include <stdio.h> #include <string.h> /* putting one of the "char*"s here causes a segfault */ void main() { char* path = "/temp"; char* temp; strcpy(temp, path); } This compiles, runs, and behaves as it looks. However, if one or both of the character pointers is declared as global variable, strcpy res...

Why does simple C code receive segmentation fault?

The following code receives seg fault on line 2: char *str = "string"; str[0] = 'z'; printf("%s", str); While this works perfectly well: char str[] = "string"; str[0] = 'z'; printf("%s", str); Tested with MSVC and GCC. ...

Infinite loop in FreeBSD

I have a script that constantly segfaults - the problem that I can't solve as segfault is in python libxml bindings - didn't write those. Ok, so in Linux I used to run an inf.loop so that when script dies - it restarts, like so: #!/bin/bash while [ 1 ] do nice -n 19 python server.py sleep 1 done Well, I can't seem to find /bin/bash in...

Segmentation Fault (C)

I'm getting a segmentation fault in the following C code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <netdb.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #define PORT 6667 #define MAXDATASIZE 1024 int bot_connect(char *h...

C Pointer confusion

Hi! I want to store a string in memory and read it later: $$->desc.constant->base.id = (char*)malloc(200); sprintf($$->desc.constant->base.id, "%f", $1); printf("->%s\n", $$->desc.constant->base.id); //LINE A printf("->%i\n", $$->desc.constant); //LINE B //SOME OTHER CODE //Then, later on in a function call: printf("%i", expr->desc...

sprintf access violation

Hi, I have a problem with the following code: for(i = 0;(i - 1)< n;i++) { char* b; sprintf(b, "%d", i); } It compiles fine but when I run it it give me the infamous "0XC0000005 Access Violation" error. I have tried setting b to NULL, "", "0", 0 and a bunch of other stuff but then I get the "0XC0000005 Access Violation" error or "Expre...

Python threads stack_size and segfaults

A web crawler script that spawns at most 500 threads and each thread basically requests for certain data served from the remote server, which each server's reply is different in content and size from others. i'm setting stack_size as 756K's for threads threading.stack_size(756*1024) which enables me to have the sufficient number of t...

Segfault from adding a variable

I'm admittedly a straight-C newbie, but this has got me stumped. I'm working on a linked list implementation for practice, and I'm getting a segfault by simply adding a variable to the split_node function: #include <stdio.h> #include <string.h> #include <stdlib.h> struct Node { struct Node *child; char *content; }; void print_list(s...

Weird ruby segmentation fault with DBI and MySQL

[Edited to use much simpler code which shows the problem] The following code gives a segmentation fault on the last line require 'rubygems' gem 'mysql' gem 'dbi' require 'dbi' require 'mysql' dsn = "DBI:Mysql:DATABASE:www.HOST.net" # redacted dbh = DBI.connect(dsn, "USERNAME", "PASSWORD") # redacted sth = dbh.execute("select * from ...

Passing an array of strings as parameter to a function in C

I want a simple function that receives a string and returns an array of strings after some parsing. So, this is my function signature: int parse(const char *foo, char **sep_foo, int *sep_foo_qty) { int i; char *token; ... strcpy(sep_foo[i], token); /* sf here */ ... } Then I call it like this: char sep_foo[MAX_QTY...

Why Does This Pointer-Pointer Initialization Seg Fault?

I create a pointer-to-pointer of a class object and when I try to create a new object using the pointers it seg-faults. Why does this happen? struct Level { int SoldierCount; Soldier **soldier; int taskCount; int *taskPercentage; int *taskBitmapX; int *taskBitmapY; }level; void createM...

Line number of segmentation fault

Is there any gcc option I can set that will give me the line number of the segmentation fault? I know I can : Debug line by line Put printfs in the code to narrow down. Thanks! Edits: bt / where on gdb give No stack. Helpful suggestion ...

Try/Catch a segmentation fault on Linux

I have a Linux C++ application and I'd like to test an object pointer for validity before dereferencing it. However try/catch doesn't work for this on Linux because of the segmentation fault. How can this be done? ...

Segfault when using printf

I am debugging some Linux C code in a signal handler for floating point exceptions. The goal is to check the floating point registers, print some information, and then abort. I get a segmentation fault when attempting to printf the result of (char)('0' + phyreg). struct ucontext * uc = (struct ucontext *) data; fpregset_t fp = uc ...

Debug-compiled executable: Why not abort gracefully on invalid write to NULL?

What I don't understand about C/C++ is: Yes, everyone uses it to get blazingly fast executables, so they compile with optimization turned on. But for compilation with debug information turned on, we don't care about speed. So why not include more information in that compile mode, for example detect some segfaults before they happen? E...

Catching segfaults in C

I have a program that segfaults from pointer arithmetic sometimes. I know this happens, but I can't easily check ahead of time to see whether it segfaults or not - either I can "pre-scan" input data to see if it will cause a segfault (which can be impossible to determine), or I can refit it to not use pointer arithmetic, which would requ...

boost::thread: Segfault when running optimized version

I have trouble getting boost:thread to work. It runs fine when compiling without optimization: g++ -o test-thread test-thread.cpp -lboost_thread-gcc-mt-s -lpthread ./test-thread But a version that's compiled with optimizations crashes g++ -O2 -o test-thread test-thread.cpp -lboost_thread-gcc-mt-s -lpthread ./test-thread Segmentation ...

Adding an int member to a C struct causes a segfault

I'm still learning C, and have started using it to generate images. I can't figure out why one of my programs is segfaulting. Here's the source code, cut down to 40 lines: #include <stdio.h> #include <stdlib.h> struct color { unsigned char r, g, b; }; struct image { int w, h/*, o*/; struct color **data; }; int ma...

Machine regularly segfaults

When I use apt-get to install or upgrade my Ubuntu hardy system, I often get messages like this: $ sudo apt-get install foo Reading package lists... Done Segmentation faulty tree... 50% $ sudo apt-get install foo Reading package lists... Done Building dependency tree Reading state information... Done Segmentation fault $ sudo a...