From owner-freebsd-current Sat Nov 23 1: 4:27 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6816F37B401 for ; Sat, 23 Nov 2002 01:04:26 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3625D43EA3 for ; Sat, 23 Nov 2002 01:04:25 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id UAA08360; Sat, 23 Nov 2002 20:03:48 +1100 Date: Sat, 23 Nov 2002 20:16:35 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: "M. Warner Losh" Cc: marc@informatik.uni-bremen.de, Subject: Re: malloc(0) broken? In-Reply-To: <20021122.193635.99607054.imp@bsdimp.com> Message-ID: <20021123195334.W48944-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, 22 Nov 2002, M. Warner Losh wrote: > In message: <79620000.1037978720@leeloo.intern.geht.de> > Marc Recht writes: > : A malloc(0) returns always 0x800 on my system. This causes some third-party > : software to fail, because they expect malloc(0) to return NULL. Is this a > : bug or a feature? malloc(3) doesn't mention anything. > > malloc(0) is undefined. If people expect it to return NULL, that > software is not standard conforming. Er, malloc(0) is defined as returning either a null pointer or a pointer to 0 bytes of allocated space. Which one it chooses to return is implementation-defined, not undefined. C90 has a bogus requirement that the pointer for malloc(0) be "unique", whatever that means. C99 only requires that the objects pointed to by the results of malloc() be disjoint, and this is satisfied by FreeBSD's behaviour of returning the same magic pointer for each instance of malloc(0). Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message