diff options
author | peter <peter@FreeBSD.org> | 1997-07-06 07:54:56 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1997-07-06 07:54:56 +0000 |
commit | 46a29e5b571b09773a111640c22089d8196c8641 (patch) | |
tree | 6860a52cd8ac4f09891dc6ffca439aacc0e015ee /lib/libc | |
parent | 18fa8ff2b470b736a50fb803e1e891bc2f4d247b (diff) | |
download | FreeBSD-src-46a29e5b571b09773a111640c22089d8196c8641.zip FreeBSD-src-46a29e5b571b09773a111640c22089d8196c8641.tar.gz |
Fix off-by-one error
PR: 3451
Submitted by: Tim Vanderhoek <ac199@hwcn.org>
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/vasprintf.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c index 8030e11..fde3d8b 100644 --- a/lib/libc/stdio/vasprintf.c +++ b/lib/libc/stdio/vasprintf.c @@ -24,7 +24,7 @@ */ #if defined(LIBC_RCS) && !defined(lint) -static char rcsid[] = "$Id$"; +static char rcsid[] = "$Id: vasprintf.c,v 1.5 1997/02/22 15:02:39 peter Exp $"; #endif /* LIBC_RCS and not lint */ #include <stdio.h> @@ -111,9 +111,11 @@ vasprintf(str, fmt, ap) if (h.base == NULL) /* failed to realloc in writehook */ return (-1); - h.base[h.size - h.left] = '\0'; *str = realloc(h.base, (size_t)(h.size - h.left + 1)); - if (*str == NULL) /* failed to realloc it to actual size */ - *str = h.base; /* return oversize buffer */ + if (*str == NULL) { /* failed to realloc it to actual size */ + free(h.base); + return (-1); + } + (*str)[h.size - h.left] = '\0'; return (ret); } |