On 15/04/2025 2:00 pm, Jan Beulich wrote:
> On 15.04.2025 14:49, Teddy Astie wrote:
>> UBSAN complains when trying memcpy with a NULL pointer even if it's going to
>> copy zero bytes (which are the only cases where a NULL pointer is used).
> If this really was a problem, I think we'd need to go through and find all
> instances. However, ...
>
>> Fix this by only doing the memcpy if the pointer is non-NULL.
>>
>> (XEN) 
>> ================================================================================
>> (XEN) UBSAN: Undefined behaviour in arch/x86/mm/shadow/hvm.c:168:5
>> (XEN) null pointer passed as argument 1, declared with nonnull attribute
> ... it can only be the compiler who has added the nonnull attribute; we
> use it only in very few (other) places.
>
> Personally I find it absurd to forbid NULL here when the size is zero. Yet
> I agree that the spec can be interpreted this way.

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf

This is being proposed for fixing in C2Y, because lots of people think
it's absurd.

However, until we can raise our -std, I think we're stuck with the
current behaviour.

GCC-15 introduces the nonnull_if_nonzero attribute specifically for
memcpy() etc, but I don't see how we could make use of it in this case.

~Andrew

Reply via email to