From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9247 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] fix malloc_usable_size for NULL input Date: Sun, 31 Jan 2016 17:31:03 +0100 Message-ID: <20160131163102.GX9621@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1454257882 5248 80.91.229.3 (31 Jan 2016 16:31:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 31 Jan 2016 16:31:22 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-9260-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jan 31 17:31:22 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1aPuuH-0005ie-T1 for gllmg-musl@m.gmane.org; Sun, 31 Jan 2016 17:31:22 +0100 Original-Received: (qmail 5460 invoked by uid 550); 31 Jan 2016 16:31:19 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 5421 invoked from network); 31 Jan 2016 16:31:14 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Xref: news.gmane.org gmane.linux.lib.musl.general:9247 Archived-At: the linux man page specifies malloc_usable_size(0) to return 0 and this is the semantics other implementations follow (jemalloc). reported by Alexander Monakov. --- src/malloc/malloc_usable_size.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/malloc/malloc_usable_size.c b/src/malloc/malloc_usable_size.c index 8cccd9d..6743ea7 100644 --- a/src/malloc/malloc_usable_size.c +++ b/src/malloc/malloc_usable_size.c @@ -13,5 +13,5 @@ struct chunk { size_t malloc_usable_size(void *p) { - return CHUNK_SIZE(MEM_TO_CHUNK(p)) - OVERHEAD; + return p ? CHUNK_SIZE(MEM_TO_CHUNK(p)) - OVERHEAD : 0; } -- 2.7.0