__xpg_strerror_r should not clobber strerror buffer
Eric Blake
eblake@redhat.com
Sun May 22 01:26:00 GMT 2011
POSIX says that no other function in the standard should clobber the
strerror buffer. Our strerror_r is a GNU extension, so it can get away
with clobbering the buffer (but if we wanted to fix it, we would have to
separate _my_tls.locals.strerror_buf into two different buffers).
perror() is still broken, but that needs to be fixed in newlib. But
__xpg_strerror_r, which is our POSIX strerror_r variant, has to be fixed
in cygwin.
Meanwhile, glibc just patched strerror this week to print negative
errnum as a negative 32-bit int, rather than as a positive unsigned
long; cygwin should do likewise.
2011-05-21 Eric Blake <eblake@redhat.com>
* errno.cc (strerror): Print unknown errno as int.
(__xpg_strerror_r): Likewise, and don't clobber strerror buffer.
Index: errno.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/errno.cc,v
retrieving revision 1.82
diff -u -p -r1.82 errno.cc
--- errno.cc 18 May 2011 01:25:41 -0000 1.82
+++ errno.cc 22 May 2011 01:22:17 -0000
@@ -382,8 +382,8 @@ strerror (int errnum)
char *errstr = strerror_worker (errnum);
if (!errstr)
{
- __small_sprintf (errstr = _my_tls.locals.strerror_buf, "Unknown
error %u",
- (unsigned) errnum);
+ __small_sprintf (errstr = _my_tls.locals.strerror_buf, "Unknown
error %d",
+ errnum);
errno = _impure_ptr->_errno = EINVAL;
}
return errstr;
@@ -409,10 +409,10 @@ __xpg_strerror_r (int errnum, char *buf,
return ERANGE;
int result = 0;
char *error = strerror_worker (errnum);
+ char tmp[sizeof "Unknown error -2147483648"];
if (!error)
{
- __small_sprintf (error = _my_tls.locals.strerror_buf, "Unknown
error %u",
- (unsigned) errnum);
+ __small_sprintf (error = tmp, "Unknown error %d", errnum);
result = EINVAL;
}
if (strlen (error) >= n)
--
Eric Blake eblake@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20110522/cd4ba51f/attachment.sig>
More information about the Cygwin-patches
mailing list