From 1ecfa643a967dee7271e7b64d29613493dfa1be4 Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 1 Jan 1998 20:15:58 +0000 Subject: 1. EOF was returned when the buffer size was larger than INT_MAX. This case has very little to do with the output size being larger than INT_MAX. 2. The new #include of was disordered. 3. The new declaration of `on' was disordered (integer types go together). 4. Testing an unsigned value for > 0 was fishy. Submitted by: bde --- lib/libc/stdio/snprintf.c | 10 +++++----- lib/libc/stdio/vsnprintf.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c index aa70bb2..a4c04d9 100644 --- a/lib/libc/stdio/snprintf.c +++ b/lib/libc/stdio/snprintf.c @@ -39,16 +39,16 @@ static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93"; #endif static const char rcsid[] = - "$Id: snprintf.c,v 1.9 1997/12/24 23:02:40 ache Exp $"; + "$Id: snprintf.c,v 1.10 1997/12/24 23:54:13 ache Exp $"; #endif /* LIBC_SCCS and not lint */ +#include #include #if __STDC__ #include #else #include #endif -#include #if __STDC__ int @@ -62,16 +62,16 @@ snprintf(str, n, fmt, va_alist) va_dcl #endif { + size_t on; int ret; va_list ap; FILE f; - size_t on; on = n; - if (n > 0) + if (n != 0) n--; if (n > INT_MAX) - return (EOF); + n = INT_MAX; #if __STDC__ va_start(ap, fmt); #else diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index 0f43d81..6cf2d76 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -39,11 +39,11 @@ static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93"; #endif static const char rcsid[] = - "$Id: vsnprintf.c,v 1.9 1997/12/24 23:02:47 ache Exp $"; + "$Id: vsnprintf.c,v 1.10 1997/12/24 23:54:19 ache Exp $"; #endif /* LIBC_SCCS and not lint */ -#include #include +#include int vsnprintf(str, n, fmt, ap) @@ -52,15 +52,15 @@ vsnprintf(str, n, fmt, ap) const char *fmt; _BSD_VA_LIST_ ap; { + size_t on; int ret; FILE f; - size_t on; on = n; - if (n > 0) + if (n != 0) n--; if (n > INT_MAX) - return (EOF); + n = INT_MAX; f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; -- cgit v1.1