OSDN Git Service

2000-08-08 Jeff Johnston <jjohnstn@redhat.com>
authorjjohnstn <jjohnstn>
Tue, 8 Aug 2000 19:01:02 +0000 (19:01 +0000)
committerjjohnstn <jjohnstn>
Tue, 8 Aug 2000 19:01:02 +0000 (19:01 +0000)
        * libc/stdio/snprintf.c (snprintf, _snprintf_r): Fixed code
        so size of 0 results in nothing being written to string.
        Also fixed code so that when size is non-zero, there is only
        a maximum of size - 1 characters written to the array and
        a nul terminator is appended at the end.
        * libc/stdio/vsnprintf.c (vsnprintf, _vsnprintf_r): Ditto.

newlib/ChangeLog
newlib/libc/stdio/snprintf.c
newlib/libc/stdio/vsnprintf.c

index a830dd7..caee23f 100644 (file)
@@ -1,3 +1,12 @@
+2000-08-08  Jeff Johnston <jjohnstn@redhat.com>
+
+       * libc/stdio/snprintf.c (snprintf, _snprintf_r): Fixed code
+       so size of 0 results in nothing being written to string.
+       Also fixed code so that when size is non-zero, there is only
+       a maximum of size - 1 characters written to the array and
+       a nul terminator is appended at the end.
+       * libc/stdio/vsnprintf.c (vsnprintf, _vsnprintf_r): Ditto.
+
 2000-08-01  DJ Delorie  <dj@redhat.com>
 
        * libc/include/sys/config.h: define __IMPORT appropriately
index 333e808..c67f8e4 100644 (file)
@@ -47,7 +47,7 @@ _snprintf_r (ptr, str, size, fmt, va_alist)
 
   f._flags = __SWR | __SSTR;
   f._bf._base = f._p = (unsigned char *) str;
-  f._bf._size = f._w = size;
+  f._bf._size = f._w = (size > 0 ? size - 1 : 0);
   f._data = ptr;
 #ifdef _HAVE_STDC
   va_start (ap, fmt);
@@ -56,7 +56,8 @@ _snprintf_r (ptr, str, size, fmt, va_alist)
 #endif
   ret = vfprintf (&f, fmt, ap);
   va_end (ap);
-  *f._p = 0;
+  if (size > 0)
+    *f._p = 0;
   return (ret);
 }
 
@@ -79,7 +80,7 @@ snprintf (str, size, fmt, va_alist)
 
   f._flags = __SWR | __SSTR;
   f._bf._base = f._p = (unsigned char *) str;
-  f._bf._size = f._w = size;
+  f._bf._size = f._w = (size > 0 ? size - 1 : 0);
   f._data = _REENT;
 #ifdef _HAVE_STDC
   va_start (ap, fmt);
@@ -88,7 +89,8 @@ snprintf (str, size, fmt, va_alist)
 #endif
   ret = vfprintf (&f, fmt, ap);
   va_end (ap);
-  *f._p = 0;
+  if (size > 0)
+    *f._p = 0;
   return (ret);
 }
 
index 18df586..5ca0ff2 100644 (file)
@@ -45,10 +45,11 @@ vsnprintf (str, size, fmt, ap)
 
   f._flags = __SWR | __SSTR;
   f._bf._base = f._p = (unsigned char *) str;
-  f._bf._size = f._w = size;
+  f._bf._size = f._w = (size > 0 ? size - 1 : 0);
   f._data = _REENT;
   ret = vfprintf (&f, fmt, ap);
-  *f._p = 0;
+  if (size > 0)
+    *f._p = 0;
   return ret;
 }
 
@@ -65,9 +66,10 @@ vsnprintf_r (ptr, str, size, fmt, ap)
 
   f._flags = __SWR | __SSTR;
   f._bf._base = f._p = (unsigned char *) str;
-  f._bf._size = f._w = size;
+  f._bf._size = f._w = (size > 0 ? size - 1 : 0);
   f._data = ptr;
   ret = vfprintf (&f, fmt, ap);
-  *f._p = 0;
+  if (size > 0)
+    *f._p = 0;
   return ret;
 }