My application is suspending on a line of code that appears to have nothing wrong with it, however my IDE appears to be suspending on that line with the error:
gdb/mi (24/03/09 13:36) (Exited. Signal ‘SIGSEGV’ received. Description: Segmentation fault.)
The line of code simply calls a method which has no code in it. Isn’t a segmentation fault when you have a null reference? If so, how can an empty method have a null reference?
This piece of code, seems to be causing the issue:
#include <sys/socket.h> #define BUFFER_SIZE 256 char *buffer; buffer = (char*)GetSomePointer()->SomeStackMemoryString.c_str(); int writeResult = write(socketFD, buffer, BUFFER_SIZE); bzero(buffer, BUFFER_SIZE); int readResult = read(socketFD, buffer, BUFFER_SIZE);
When the line using the read(...) method is commented out, the problem goes away.
Update:
I have changed the question to point toward the actual problem, and I have removed all the irrelevant code – and I also answered my own question so that people reading this know specifically what the issue is, please read my answer before saying "you’re a moron!".
Your code is bogus: buffer points to some random piece of memory. I’m not sure why the line with bzero is not failing.
The correct code is:
or you can use calloc(1, BUFFER_SIZE) to get some memory allocated (and zeroed out).