From efda68d8972cec4cd342864acdc2364d6498fbc3 Mon Sep 17 00:00:00 2001 From: xhon-pelushi Date: Wed, 30 Sep 2026 17:03:17 -0400 Subject: [PATCH] benchfn: don't memset a NULL dst buffer of size 0 Some fullbench scenarios (convertSequences, get1BlockSummary) do not need a destination buffer, so their preparation leaves dst == NULL and dstCapacity == 0. BMK_benchFunction() then called memset(NULL, 0xE5, 0). Passing a null pointer to memset() is undefined behavior even when the length is 0, and UBSan reports it through glibc's nonnull annotation: programs/benchfn.c:116:13: runtime error: null pointer passed as argument 1, which is declared to never be null Skip the warm-up memset when the destination capacity is 0. Fixes #4776 --- programs/benchfn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/programs/benchfn.c b/programs/benchfn.c index 3e042cf38f8..f31993c0a43 100644 --- a/programs/benchfn.c +++ b/programs/benchfn.c @@ -113,7 +113,8 @@ BMK_runOutcome_t BMK_benchFunction(BMK_benchParams_t p, /* init */ { size_t i; for(i = 0; i < p.blockCount; i++) { - memset(p.dstBuffers[i], 0xE5, p.dstCapacities[i]); /* warm up and erase result buffer */ + if (p.dstCapacities[i] > 0) /* dstBuffers[i] may be NULL when dstCapacities[i] == 0 */ + memset(p.dstBuffers[i], 0xE5, p.dstCapacities[i]); /* warm up and erase result buffer */ } } /* benchmark */