Date: Sat, 14 Jun 1997 11:56:35 +1000 From: Bruce Evans <bde@zeta.org.au> To: ac199@hwcn.org, freebsd-bugs@hub.freebsd.org Subject: Re: bin/3451: vasprintf() doesn't work. Message-ID: <199706140156.LAA12946@godzilla.zeta.org.au>
next in thread | raw e-mail | index | archive | help
> realloc() can fail, resulting in a null pointer dereference. That's > undesirable. > > Try, instead, >... > *str = realloc(h.base, (size_t)(h.size - h.left + 1)); > if (*str == NULL) /* failed to realloc it to actual size */ > ! return (-1); > ! (*str)[h.size - h.left] = '\0'; > return (ret); > } One more problem: realloc() can fail, resulting in a leaking the memory pointed to by h.base. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199706140156.LAA12946>