[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 4/4] tools/tests/x86_emulator: avoid passing NULL to memcpy
- To: Jan Beulich <jbeulich@xxxxxxxx>, Edwin Török <edwin.torok@xxxxxxxxxx>
- From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
- Date: Tue, 3 Mar 2026 15:24:33 +0000
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lKmfsrSHU2A47P2t7ur29OSgAcpnzWZ/Dz6hdWCxs3U=; b=lMXqvIOXHGLuMoIHOoyOGi3DoBnQw5+epFyuZ6Mnh4mKoKtG3OymYi5Vn1trT4kqfRdO7oiMFX1Ehf7J3G4kG6sVibJghC6QPtLjnZS2R2SJJVo+s5rJWSmtVYMNtnPj/gT1WyR3YQXVMzMScZYwHHAunp7MXK8bG0a4hD6tKZbq9+GjUsgsBGeOfT7G9JxK+Drv7gRuXmd+ALH/k1vop61HlZZUAF6sl4cOJ+PaQQKuGLKAbyovUzrPykmpJeom3cfQYjTfARWEPogy7siyVX9hIbVSdU5AtU/pO9juU4aGqxF2EOeUsSAbz4+9sh8jT1F+hHHWZOmsdXUt/B61Sg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QZp+5LTLn345tPyV0VqRmi1Xc9zCGhZ8BpqGsOESK9ns4ui18Fl1FGVF9G1XXXzRFxoa+4epxESO6fJDyZVOjY3u76edkoNq8GcFaC8Z1w/UHdZBQ/WWMSATd9ixeJVxw2ErTsW0j9Xu7sPm+LmXjwIIK8/JK0UnG+Z9AE0WTYwaB/smEfzmz76HzIDltMSoVp0v+cgzGIpZ0tpRLjU34iqnuFmj6Uov6+QShSDtioIY9R4E1CTuXsqXdrxeGTt94F70eCwMApRmSKjfhoQOUgAUlt39XNHQmZ+LSYcoDEbkjDkmf/EiFdsHEOAZowio47m0pfNBEWO10LjNZCBFTg==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
- Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- Delivery-date: Tue, 03 Mar 2026 15:24:49 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
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
|