Fix off-by-one error

PR: 3451
Submitted by: Tim Vanderhoek <ac199@hwcn.org>
This commit is contained in:
Peter Wemm 1997-07-06 07:54:56 +00:00
parent 85d2c81156
commit 3c55a3f243

View File

@ -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);
}