From owner-cvs-lib Sun Jul 6 01:48:30 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id BAA15268 for cvs-lib-outgoing; Sun, 6 Jul 1997 01:48:30 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id BAA15102; Sun, 6 Jul 1997 01:42:54 -0700 (PDT) From: Peter Wemm Received: (from peter@localhost) by freefall.freebsd.org (8.8.6/8.8.5) id BAA19937; Sun, 6 Jul 1997 01:42:38 -0700 (PDT) Date: Sun, 6 Jul 1997 01:42:38 -0700 (PDT) Message-Id: <199707060842.BAA19937@freefall.freebsd.org> To: cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG, cvs-lib@FreeBSD.ORG Subject: cvs commit: src/lib/libc/stdio vasprintf.c Sender: owner-cvs-lib@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 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