From owner-freebsd-current Sat Nov 23 3:19:22 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 0A57937B401 for ; Sat, 23 Nov 2002 03:19:21 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 011FD43E3B for ; Sat, 23 Nov 2002 03:19:20 -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 WAA16835; Sat, 23 Nov 2002 22:19:01 +1100 Date: Sat, 23 Nov 2002 22:32:17 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: David Schultz Cc: "M. Warner Losh" , , Subject: Re: malloc(0) broken? In-Reply-To: <20021123104135.GA13619@HAL9000.homeunix.com> Message-ID: <20021123221927.I49462-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 Sat, 23 Nov 2002, David Schultz wrote: > Thus spake Bruce Evans : > > ... 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). > > In FreeBSD, malloc(0) returns a distinct pointer each time by > making a 16-byte allocation. I seem to recall that it may have > returned a single magic pointer at one time, so what you say might > have been correct some time ago. Actually, it is correct now. malloc(0) returns the constant invalid pointer ZEROSIZEPTR (0x800 on i386's), but it returned a distinct pointer before the ZEROSIZEPTR stuff was added in rev.1.60 of libc/stdlib/malloc.c. (All this is without the malloc option V which causes malloc(0) to return a null pointer.) Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message