From owner-freebsd-standards@FreeBSD.ORG Sat Aug 29 11:30:02 2009 Return-Path: Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BE82A106566B for ; Sat, 29 Aug 2009 11:30:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 9B6AB8FC13 for ; Sat, 29 Aug 2009 11:30:02 +0000 (UTC) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n7TBU2hJ060281 for ; Sat, 29 Aug 2009 11:30:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n7TBU2Dk060280; Sat, 29 Aug 2009 11:30:02 GMT (envelope-from gnats) Resent-Date: Sat, 29 Aug 2009 11:30:02 GMT Resent-Message-Id: <200908291130.n7TBU2Dk060280@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-standards@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Rafaël Carré Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2FA84106566B for ; Sat, 29 Aug 2009 11:24:15 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 1E9798FC0C for ; Sat, 29 Aug 2009 11:24:15 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n7TBOEeB097279 for ; Sat, 29 Aug 2009 11:24:14 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id n7TBOEKl097272; Sat, 29 Aug 2009 11:24:14 GMT (envelope-from nobody) Message-Id: <200908291124.n7TBOEKl097272@www.freebsd.org> Date: Sat, 29 Aug 2009 11:24:14 GMT From: Rafaël Carré To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: standards/138307: posix_memalign has incorrect behaviour if size == 0 X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Aug 2009 11:30:02 -0000 >Number: 138307 >Category: standards >Synopsis: posix_memalign has incorrect behaviour if size == 0 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Aug 29 11:30:02 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Rafaël Carré >Release: 8-BETA2 >Organization: >Environment: FreeBSD kru 8.0-BETA2 FreeBSD 8.0-BETA2 #1: Thu Aug 13 15:49:26 CEST 2009 fun@kru:/usr/obj/usr/src/sys/GENERIC amd64 >Description: http://www.opengroup.org/onlinepubs/9699919799/functions/posix_memalign.html quotes: "If the size of the space requested is 0, the behavior is implementation-defined; the value returned in memptr shall be either a null pointer or a unique pointer." The behaviour is different using differents alignements: posix_memalign either returns EINVAL, either asserts. Sample test program is attached, output is: --8<-- % ./a.out malloc 0 align 4 Invalid argument align 8 Assertion failed: (size != 0), function arena_malloc, file /usr/src/lib/libc/stdlib/malloc.c, line 3349. zsh: abort (core dumped) ./a.out --8<-- call stack: #2 0x000000080071c225 in __assert () from /lib/libc.so.7 #3 0x00000008006be011 in malloc_usable_size () from /lib/libc.so.7 #4 0x00000008006c1228 in posix_memalign () from /lib/libc.so.7 I got a report that it functions correctly on "FreeBSD turbine 7.1-RELEASE-p5 FreeBSD 7.1-RELEASE-p5 #7 r191765: Thu Aug 20 12:26:09 CEST 2009" but I can't test myself >How-To-Repeat: #include #include #include #include int main(void) { void *p; int i; errno = 0; printf("malloc 0\n"); p = malloc(0); if(!p) printf("%s\n", strerror(errno)); printf("\n"); printf("align 4\n"); i = posix_memalign(&p, 4, 0); printf("%s\n\n", strerror(i)); printf("align 8\n"); i = posix_memalign(&p, 8, 0); printf("%s\n\n", strerror(i)); return 0; } >Fix: >Release-Note: >Audit-Trail: >Unformatted: