<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40028 >
> [EMAIL PROTECTED] - Mon Jan 28 05:22:53 2008]: > > William Allen Simpson wrote: > ... > > 2) Madeline reported the problem was in mystrerror(), so that's a > > good target, > > Ahh yes, I see that now. Obviously I had only remembered it > subconsciously before :). Speaking of which, Madeline, what is the > mystrsocketerror function you mention? It is something added in the warclient codebase to deal with the fact that on win32 strerror/GetLastError does not return error codes for socket operation errors. It is identical to mystrerror except that the call to GetLastError is replaced by a call to WSAGetLastError. It's not really a pressing issue for the network code in the freeciv codebase; I had concocted a characteristically over-done asynchronous networking subsystem for metaserver communications for the client for which to debug (plagued by all manner of difficult to track down heisenbugs) on win32 it was necessary to have precise error reporting. In the end it was a nice learning experience, but not terribly worthwhile for the project as a whole. ;) > > 3) By definition, mystrerror() can only be called once, so > > there's no > > technical reason to use a dynamic buffer. > > Yes. Naturally the first thing I considered was making the change > directly within mystrerror, as that is far far easier. But, if one > mystrerror call is done before the previous one's return value > has been > discarded the result will be erroneous. Given that some of the > returned > strings are passed off into arbitrary callbacks this is a rather > risky > thing to assume IMO. However the error if this happened would be > non-fatal so I suppose if we want to accept that bug it's okay. I don't see how an invocation of mystrerror could trigger another invocation of itself (I certainly wouldn't expect that to happen). As far as I can tell mystrerror is only used in calls to printf like functions. So the return value of mystrerror is immediately copied to the buffers in those functions and once there, it is safe from being corrupted by further calls to mystrerror. But if there are indeed complicated callbacks that just store the pointer returned by strerror and use it later on after other operations have been performed, then indeed, that is a dangerous situation and should be avoided. I would always put a big warning in the comment header for functions returning pointers to static data that the programmer should take care not to abuse the return value in this way. _______________________________________________ Freeciv-dev mailing list [email protected] https://mail.gna.org/listinfo/freeciv-dev
