Date: Sun, 6 Jul 1997 01:42:38 -0700 (PDT) From: Peter Wemm <peter@FreeBSD.ORG> To: cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG, cvs-lib@FreeBSD.ORG Subject: cvs commit: src/lib/libc/stdio vasprintf.c Message-ID: <199707060842.BAA19937@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
peter 1997/07/06 01:42:38 PDT Modified files: lib/libc/stdio vasprintf.c Log: Rework previous commit.. I was confused by the number of diffs in the PR and forgot what I was trying to do originally and accidently zapped a feature. :-] The problem is that we are converting a counted buffer in a malloc pool into a null terminated C-style string. I was calling realloc originally to shrink the buffer to the desired size. If realloc failed, we still returned the valid buffer - the only thing wrong was it was a tad too large. The previous commit disabled this. This commit now handles the three cases.. 1: the buffer is exactly right for the null byte to terminate the string (we don't call realloc). 2: it's got h.left = 0, so we must expand it to make room. If realloc fails here, it's fatal. 3: if there's too much room, we realloc to shrink it - a failed realloc is not fatal, we use the original buffer which is still valid. Revision Changes Path 1.7 +29 -8 src/lib/libc/stdio/vasprintf.c
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199707060842.BAA19937>