+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
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);
#endif
ret = vfprintf (&f, fmt, ap);
va_end (ap);
- *f._p = 0;
+ if (size > 0)
+ *f._p = 0;
return (ret);
}
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);
#endif
ret = vfprintf (&f, fmt, ap);
va_end (ap);
- *f._p = 0;
+ if (size > 0)
+ *f._p = 0;
return (ret);
}
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;
}
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;
}