[ee122] weird error, possibly stack corruption, need expert
haley.ng at gmail.com
Thu Dec 6 21:14:40 PST 2007
This is a follow-up of another post with the title "address family not
supported by protocol family." I couldn't quite solve the problem, but I
discover another problem that may cause the problem in the above post.
In a nutshell, I have a receiver program which waits to receive data from a
sender program, and send an ack back. Because I couldn't solve the above
problem, I reduced the program to an earlier version that worked and traced
my code additions, and I got this: the simple receiver was working, then I
added a declaration of a dummy variable in the main function, and the
program stopped working. The error was thrown in another function whose
caller's caller's is called by main. The error is thrown by a sendto(), and
it was "Invalid argument".
Since there was a post from the last project about "segfault madness" in
which a segfault appeared after a declaration of a dummy variable, I
followed the suggestions in that post. Therefore, I compiled my code with -g
-Wall, and got a bunch of warnings about unused variables, and several print
functions where I didn't print with the right flags (e.g. print void* with
%x or %c, or something else with %ld, can this be the issue?).
I ignored the warnings and ran the program with gdb. Since the error was
invalid arguments, I checked the argument passed to sendto() namely the
socket file descriptor, the sockaddr_in and the addrlen (didn't check the
buffer and its size closely, but the buffer is not null, and the size is the
right non-zero number). By printing these variables with gdb (and gdb on my
computer let me see the content of the variable in a nice format with all
the field names in front of the data), I can visually verify that the data
passed to sendto() is the same data that was returned by the recvfrom() in
main(). (Recall that the receiver receives something then send and ack.) At
this point, I'm stuck because the arguments appear valid to me.
Any clue about how to debug this thing or where the bug can be would be much
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the ee122