From owner-freebsd-bugs@FreeBSD.ORG Mon Jun 28 22:21:20 2010 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 90E9D1065670; Mon, 28 Jun 2010 22:21:20 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail08.syd.optusnet.com.au (mail08.syd.optusnet.com.au [211.29.132.189]) by mx1.freebsd.org (Postfix) with ESMTP id 1579E8FC16; Mon, 28 Jun 2010 22:21:19 +0000 (UTC) Received: from besplex.bde.org (c122-106-145-25.carlnfd1.nsw.optusnet.com.au [122.106.145.25]) by mail08.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id o5SMLHRG023747 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 29 Jun 2010 08:21:18 +1000 Date: Tue, 29 Jun 2010 08:21:17 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Jaakko Heinonen In-Reply-To: <201006282020.o5SKK3OG063671@freefall.freebsd.org> Message-ID: <20100629081501.K2710@besplex.bde.org> References: <201006282020.o5SKK3OG063671@freefall.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-bugs@freebsd.org Subject: Re: kern/144307: ENOENT set unnecessarily under certain circumstances when malloc is called / fails X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jun 2010 22:21:20 -0000 On Mon, 28 Jun 2010, Jaakko Heinonen wrote: > On 2010-06-28, Garrett Cooper wrote: > > Or the malloc(3) call could be fixed with the couple of lines I > > noted (well, adlibbed of course... > > > > Which I agree with, but shouldn't we fix malloc(3) (and any other > > function calls that depend on malloc(3) for sensible results)? > > It's not required for POSIX compliance at least. Did you actually read > the quotes from POSIX? > > "The value of errno should only be examined when it is indicated to be > valid by a function's return value." > > "The setting of errno after a successful call to a function is > unspecified unless the description of that function specifies that errno > shall not be modified." > > In other words the value of errno is undefined and shouldn't be unspecified > examined unless malloc(3) returns NULL. Not quite even then. malloc(0) may return NULL, so errno shouldn't be examined unless malloc() returns NULL and its arg (when converted to a size_t) is nonzero. Maybe more of these bugs could be found by setting errno to EDOOFUS in malloc() and other commonly used library functions :-). This is easier to recognize than say ENOTTY from isatty() in stream initialization on non-ttys. Bruce