0
votes

I'm getting this in my program, C++

Program received signal SIGSEGV, Segmentation Fault. 0xb7d62153 in __strtol_l_internal () from /lib/libc.so.6

I got that by using GDB. CC compiled it fine along with G++

    sockf = openSocket(domainname, portc);
    if(sockf > 0){
        log("ZONTRECK","COMPLETED SOCKET!");
        int newsockfd;
        newsockfd = openListen(sockf,portc);
        log("ZONTRECK","Starting console!");
4
It may well mean you've failed to terminate a string and/or overflowed, but without seeing some code it's impossible to say. - Flexo
I was about to edit to add code, I have to grab it - Tyler McMaster
If you can keep the code as small as possible (but complete still) to show the problem you're having it might help you spot the problem and even if it doesn't it'll make it easier for us to spot it. - Flexo
The code above doesn't compile -- there's no main -- so its impossible to see what is going wrong. Try looking at the stack trace to see how its getting to where the fault is (where command in gdb). If the stack trace makes no sense, you're probably smashing the stack somewhere. Try using valgrind to see if that can help. - Chris Dodd
openListen and openSocket are in different files - Tyler McMaster

4 Answers

2
votes

It's an internal function within libc, related to strtol() -- if I had to hazard a guess, I'd say you're trying to read in a number, and something is blowing up.

2
votes

Use the backtrace command in gdb to see how the program got to that point from your code - that will help find what parameter is being passed that's causing the problem (probably a NULL or otherwise invalid pointer).

0
votes

Maby you are trying here to read memory corrupted by some code ran before this. If this is the case than the best way is to debug it by Valgrind.

0
votes

I had to edit a file i didn't post on this site. Its my file that contains openSocket,openListen.

The atoi function requires const char, not char.

I was passing a char to it instead of a const char.

I fixed this issue by changing the char in int main() to const char.