This is causing UBSan to flag an error in my code, which is (IMO legitimately) passing NULL to memcmp() when length argument is zero.
UBSan is correct, even if the size is zero the pointers must still have valid values.
Can you please refer me to the standard section for this? I thought NULL *is* valid pointer for never being dereferenced.
The standard uses the phrase “object pointed to”. C does not have zero-sized objects, so pointers to objects are always not NULL. I believe this is a defect in the standard and something that negatively impacts C++ interoperability, among other things, but unfortunately, this is a minority view.
7.24.1#2 "Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4."
Thank you both.