From owner-freebsd-current@FreeBSD.ORG Wed Dec 1 05:19:10 2004 Return-Path: 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 D009F16A652 for ; Wed, 1 Dec 2004 05:19:10 +0000 (GMT) Received: from shuttle.wide.toshiba.co.jp (shuttle.wide.toshiba.co.jp [202.249.10.124]) by mx1.FreeBSD.org (Postfix) with ESMTP id 45CE843D54 for ; Wed, 1 Dec 2004 05:19:10 +0000 (GMT) (envelope-from jinmei@isl.rdc.toshiba.co.jp) Received: from ocean.jinmei.org (unknown [2001:200:0:8002:200:39ff:fed7:e2e4]) by shuttle.wide.toshiba.co.jp (Postfix) with ESMTP id 3451C15210 for ; Wed, 1 Dec 2004 14:19:05 +0900 (JST) Date: Wed, 01 Dec 2004 14:19:15 +0900 Message-ID: From: JINMEI Tatuya / =?ISO-2022-JP?B?GyRCP0BMQEMjOkgbKEI=?= To: current@FreeBSD.org User-Agent: Wanderlust/2.10.1 (Watching The Wheels) Emacs/21.3 Mule/5.0 (SAKAKI) Organization: Research & Development Center, Toshiba Corp., Kawasaki, Japan. MIME-Version: 1.0 (generated by SEMI 1.14.5 - "Awara-Onsen") Content-Type: text/plain; charset=US-ASCII Subject: malloc(0) returns an invalid address X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Dec 2004 05:19:11 -0000 On FreeBSD 5.3 Release (for i386), malloc(3) seems to return an invalid pointer, while the man page says: V Attempting to allocate zero bytes will return a NULL pointer instead of a valid pointer. (The default behavior is to make a minimal allocation and return a pointer to it.) This option is provided for System V compatibility. This option is incompatible with the ``X'' option. In fact, if you compile the following code, #include #include main() { char *p = malloc(0); printf("address of p is %p\n", p); *p = 0; /* XXX */ } the result of the execution would be as follows: % ./a.out address of p is 0x800 zsh: 794 segmentation fault (core dumped) ./a.out Is this a malloc bug? Or is this the intended behavior and the man page description is old? (For that matter, I don't have /etc/malloc.conf or MALLOC_OPTIONS in the local environment.) JINMEI, Tatuya Communication Platform Lab. Corporate R&D Center, Toshiba Corp. jinmei@isl.rdc.toshiba.co.jp