mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fix malloc_usable_size for NULL input
@ 2016-01-31 16:31 Szabolcs Nagy
  0 siblings, 0 replies; only message in thread
From: Szabolcs Nagy @ 2016-01-31 16:31 UTC (permalink / raw)
  To: musl

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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-01-31 16:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-31 16:31 [PATCH] fix malloc_usable_size for NULL input Szabolcs Nagy

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).