On 03/03/2026 2:18 pm, Jan Beulich wrote: > On 27.02.2026 11:58, Edwin Török wrote: >> Fixes this `-fsanitize=undefined` error: >> ``` >> test_x86_emulator.c:614:12: runtime error: null pointer passed as argument >> 1, which is declared to never be null >> /usr/include/string.h:44:28: note: nonnull attribute specified here >> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior >> test_x86_emulator.c:614:12 >> ``` >> >> Although this is more of a grey area: I don't see anything in the >> standard that'd forbid calling `memset` with NULL and 0, > There actually is. In the C99 spec clause 2 refers to section 7.1.4, where > null > pointer arguments are excluded. Imo for memcpy() etc exceptions should be made > for the case where the count is also zero, but sadly nothing like that is > there.
C23 does finally make NULL with a zero length be well defined behaviour for memcpy() and friends, but it's going to be a long time before we can rely on this properly. GCC 15 gains __attribute__((nonzero_if_null)) too. ~Andrew
