This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

__xpg_strerror_r should not clobber strerror buffer


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

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]