From owner-svn-src-all@FreeBSD.ORG Mon Jan 11 02:16:33 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7DD601065692 for ; Mon, 11 Jan 2010 02:16:33 +0000 (UTC) (envelope-from max@love2party.net) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.186]) by mx1.freebsd.org (Postfix) with ESMTP id 12BC08FC1E for ; Mon, 11 Jan 2010 02:16:33 +0000 (UTC) Received: from vampire.homelinux.org (dslb-088-066-024-221.pools.arcor-ip.net [88.66.24.221]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0MY28S-1NPsTf3rRg-00UuA8; Mon, 11 Jan 2010 03:16:32 +0100 Received: (qmail 52355 invoked from network); 11 Jan 2010 02:16:31 -0000 Received: from f8x64.laiers.local (192.168.4.188) by laiers.local with SMTP; 11 Jan 2010 02:16:31 -0000 From: Max Laier Organization: FreeBSD To: David Schultz Date: Mon, 11 Jan 2010 03:16:29 +0100 User-Agent: KMail/1.12.4 (FreeBSD/8.0-RELEASE; KDE/4.3.4; amd64; ; ) References: <200910041943.n94JhaDg083487@svn.freebsd.org> In-Reply-To: <200910041943.n94JhaDg083487@svn.freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201001110316.29816.max@love2party.net> X-Provags-ID: V01U2FsdGVkX1/hgVnFg0r0RIbI6VYADb6UAvpj26CGvZhScW8 Bt0C4z5klYfjKvYEcDGZQD+6SYmMt8cS0uuUemjth0jNjQFnbZ PbthwsDTQTv3RMxbwo1Cw== Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r197752 - head/lib/libc/stdio X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jan 2010 02:16:33 -0000 On Sunday 04 October 2009 21:43:36 David Schultz wrote: > Author: das > Date: Sun Oct 4 19:43:36 2009 > New Revision: 197752 > URL: http://svn.freebsd.org/changeset/base/197752 > > Log: > Better glibc compatibility for getline/getdelim: > > - Tolerate applications that pass a NULL pointer for the buffer and > claim that the capacity of the buffer is nonzero. > > - If an application passes in a non-NULL buffer pointer and claims the > buffer has zero capacity, we should free (well, realloc) it > anyway. It could have been obtained from malloc(0), so failing to > free it would be a small memory leak. > > MFC After: 2 weeks > Reported by: naddy > PR: ports/138320 > > Modified: > head/lib/libc/stdio/getdelim.c > > Modified: head/lib/libc/stdio/getdelim.c > =========================================================================== > === --- head/lib/libc/stdio/getdelim.c Sun Oct 4 19:03:32 2009 (r197751) > +++ head/lib/libc/stdio/getdelim.c Sun Oct 4 19:43:36 2009 (r197752) @@ > -120,8 +120,8 @@ getdelim(char ** __restrict linep, size_ > goto error; > } > > - if (*linecapp == 0) > - *linep = NULL; > + if (*linep == NULL) > + *linecapp = 0; > > if (fp->_r <= 0 && __srefill(fp)) { > /* If fp is at EOF already, we just need space for the NUL. */ I think we should have kept the original if case here, as well. Otherwise something like this might fail: char *line; /* note uninitialized */ size_t len = 0; getline(&line, &len, fd); and I think it is a reasonable thing to pass in an uninitialized pointer if you tell that there is no space associated with it, yet. I don't know if there are many (ab)uses of getline like this, but I was just bitten by it. -- Max