Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2000-08-08 23:01:02 +0400
committerJeff Johnston <jjohnstn@redhat.com>2000-08-08 23:01:02 +0400
commitbefe0fb3e142e287f79e0589c2e50996d9f10944 (patch)
tree2f7b26a471166e65ac697426fd3996be261322d0 /newlib/libc
parent0e882d4f29d54bc21a3147609d2caadb2d3a4c0f (diff)
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.
Diffstat (limited to 'newlib/libc')
-rw-r--r--newlib/libc/stdio/snprintf.c10
-rw-r--r--newlib/libc/stdio/vsnprintf.c10
2 files changed, 12 insertions, 8 deletions
diff --git a/newlib/libc/stdio/snprintf.c b/newlib/libc/stdio/snprintf.c
index 333e808e4..c67f8e49b 100644
--- a/newlib/libc/stdio/snprintf.c
+++ b/newlib/libc/stdio/snprintf.c
@@ -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);
}
diff --git a/newlib/libc/stdio/vsnprintf.c b/newlib/libc/stdio/vsnprintf.c
index 18df5864a..5ca0ff27b 100644
--- a/newlib/libc/stdio/vsnprintf.c
+++ b/newlib/libc/stdio/vsnprintf.c
@@ -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;
}