From f3e470c3e4caee7b947fd49f26a5add170ea6265 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sun, 12 Nov 2023 00:22:50 +0000 Subject: [PATCH] realloc: ASSUME non-NULL source pointer for memcpy NULL has size zero, which rounds up to zero, and so would have been handled. --- src/snmalloc/override/libc.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/snmalloc/override/libc.h b/src/snmalloc/override/libc.h index 05a82ec..a7fd211 100644 --- a/src/snmalloc/override/libc.h +++ b/src/snmalloc/override/libc.h @@ -74,7 +74,10 @@ namespace snmalloc::libc // Guard memcpy as GCC is assuming not nullptr for ptr after the memcpy // otherwise. if (SNMALLOC_UNLIKELY(sz != 0)) + { + SNMALLOC_ASSUME(ptr != nullptr); ::memcpy(p, ptr, sz); + } a.dealloc(ptr); } else if (SNMALLOC_LIKELY(size == 0)) @@ -174,4 +177,4 @@ namespace snmalloc::libc *memptr = p; return 0; } -} // namespace snmalloc::libc \ No newline at end of file +} // namespace snmalloc::libc