From owner-freebsd-hackers@FreeBSD.ORG Sun Jul 5 17:52:01 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B2FE31065673 for ; Sun, 5 Jul 2009 17:52:01 +0000 (UTC) (envelope-from jasone@FreeBSD.org) Received: from canonware.com (canonware.com [64.183.146.166]) by mx1.freebsd.org (Postfix) with ESMTP id 96B128FC1E for ; Sun, 5 Jul 2009 17:52:01 +0000 (UTC) (envelope-from jasone@FreeBSD.org) Received: from [192.168.168.201] (unknown [192.168.168.201]) by canonware.com (Postfix) with ESMTPA id E209E5081A; Sun, 5 Jul 2009 10:33:38 -0700 (PDT) Message-ID: <4A50E3F2.8080008@FreeBSD.org> Date: Sun, 05 Jul 2009 10:33:38 -0700 From: Jason Evans User-Agent: Thunderbird 2.0.0.22 (X11/20090608) MIME-Version: 1.0 To: Fabian Keil References: <20090705182856.799b6b07@fabiankeil.de> In-Reply-To: <20090705182856.799b6b07@fabiankeil.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: freebsd-hackers@freebsd.org Subject: Re: Zero-length allocation with posix_memalign() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Jul 2009 17:52:01 -0000 Fabian Keil wrote: > Rémi Denis-Courmont, one of the vlc developers, pointed out > that passing a zero size to posix_memalign() should actually > work, though: > > | In principle, while useless, there is no reason why allocating an empty > | picture should not be possible. posix_memalign() does support zero-length > | allocation anyway: > | http://www.opengroup.org/onlinepubs/9699919799/functions/posix_memalign.html > | | 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. Standards: So many to choose from. This behavior for posix_memalign was only defined as of the 2008 standard (see the Issue 7 notes for posix_memalign): https://www.opengroup.org/austin/interps/uploads/40/14543/AI-152.txt Such requirements are unfortunate, because they induce a performance penalty for every call, just so that programs can avoid proper handling of edge cases in the rare situations for which such edge cases are a real possibility. I will add the pessimization to posix_memalign once the 8.0 freeze is over. It will be quite some time before this behavior becomes ubiquitous, so in the meanwhile it's probably a good idea to modify vlc to avoid such allocation requests. Thanks, Jason