[prog] Segmentation fault :-(
Kathryn Hogg
kjh at flyballdogs.com
Tue Sep 24 10:20:35 EST 2002
>
> The main program runs like this :
>
> if (GetStatus() != SOCK_HS_SUCCESS)
> return BaseSocket::Receive(data, dataLen, flags);
>
> And the declaration for Receive is :
> int BaseSocket::Receive(unsigned char *buff, int len, int flags)
> {
> return recv(sd, buff, len, flags);
> }
>
Something isn't adding up here. BaseSocket::Receive() is using a variable
'sd' as the file descriptor to read data from. Since this wasn't passed
in as a parameter, it must either be a) a global variable, b) static data
member of BaseSocket (or a class it is derived from), or c) a data member
of BaseSocket.
Since the first two would effectively limit your program to a single
BaseSocket, I will assume that sd is a member of BaseSocket. This means
that you can only call BaseSocket::Recv through an instance of BaseSocket.
That implies that the code we are seeing that is calling
BaseSocket::Recv() must be a subclass of BaseSocket. Is it?
When you are in the debugger, right before the call to BaseSocket::Recv()
take a look at 'this' and '*this', In gdb do
p this
and then if the pointer looks ok (perhaps it is zero).
p *this
to make sure that the contents of the object look good.
Is this the first call to BaseSocket::Recv()? It is entirely likely that
some other read was called incorrectly and you've overwritten memory in
such a way that you've mangled the vtable for the object that is inherited
from BaseSocket.
> (I hate functions that do nothing but call other functions!!)
> recv is a standard SSL function, I think?
recv(2) it part of the BSD socket interface.
--
Kathryn
More information about the Programming
mailing list