From owner-freebsd-standards@FreeBSD.ORG Thu Sep 3 14:10:07 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 2FE56106568B for ; Thu, 3 Sep 2009 14:10:07 +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 1EC5F8FC08 for ; Thu, 3 Sep 2009 14:10:07 +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 n83EA7IM020591 for ; Thu, 3 Sep 2009 14:10:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n83EA64m020590; Thu, 3 Sep 2009 14:10:06 GMT (envelope-from gnats) Date: Thu, 3 Sep 2009 14:10:06 GMT Message-Id: <200909031410.n83EA64m020590@freefall.freebsd.org> To: freebsd-standards@FreeBSD.org From: Kostik Belousov Cc: Subject: Re: standards/138307: posix_memalign has incorrect behaviour if size == 0 X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Kostik Belousov List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Sep 2009 14:10:07 -0000 The following reply was made to PR standards/138307; it has been noted by GNATS. From: Kostik Belousov To: =?koi8-r?Q?Rafa=EBl_Carr=E9?= Cc: bug-followup@freebsd.org Subject: Re: standards/138307: posix_memalign has incorrect behaviour if size == 0 Date: Thu, 3 Sep 2009 16:44:38 +0300 The following patch should help. diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 270d641..b56b003 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -5320,6 +5320,15 @@ posix_memalign(void **memptr, size_t alignment, size_t size) goto RETURN; } + if (size == 0) { + if (opt_sysv == false) + size = 1; + else { + result = NULL; + ret = 0; + goto RETURN; + } + } result = ipalloc(alignment, size); }