discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in +[NSError _lastError] ?


From: Jens Alfke
Subject: Bug in +[NSError _lastError] ?
Date: Tue, 28 Feb 2012 16:43:26 -0800

One of the first Base calls I make returns an NSError (which is expected) but 
the error description is a garbage string. I tracked this down to the 
implementation of +[NSError _lastError] in NSError+GNUstepBase.m. It calls 
strerror_r to get an error message, but that call isn’t filling in the buffer.

Reading the man page tells me that there are two versions of strerror_r (a GNU 
one and a POSIX one) with different return types — the GNU version returns the 
string its return value and doesn’t always copy it into the buffer. What seems 
to be happening is that the method thinks it’s calling the POSIX version, but 
it’s actually calling the GNU version. So the error message in the return value 
is ignored, and instead it uses the buffer which wasn’t initialized.

I’m not sure what the best way is to fix this. It looks like one could either 
add
        #undef _GNU_SOURCE
near the top of the file where it defines _XOPEN_SOURCE; or one could use an 
#if around the call to strerror_r to call either version depending on which one 
is available.

For now I’m going to try the first option since it’s simpler.

—Jens


reply via email to

[Prev in Thread] Current Thread [Next in Thread]