Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4B28EEC144C for ; Tue, 3 Mar 2026 14:19:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1244829.1544192 (Exim 4.92) (envelope-from ) id 1vxQaI-0001XY-93; Tue, 03 Mar 2026 14:18:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1244829.1544192; Tue, 03 Mar 2026 14:18:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vxQaI-0001XR-6C; Tue, 03 Mar 2026 14:18:50 +0000 Received: by outflank-mailman (input) for mailman id 1244829; Tue, 03 Mar 2026 14:18:49 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vxQaH-0001XL-HR for xen-devel@lists.xenproject.org; Tue, 03 Mar 2026 14:18:49 +0000 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [2a00:1450:4864:20::431]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e47a8fc0-170b-11f1-9ccf-f158ae23cfc8; Tue, 03 Mar 2026 15:18:47 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-439b8a3f2bcso1707883f8f.3 for ; Tue, 03 Mar 2026 06:18:47 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439ba2a58dasm11432271f8f.27.2026.03.03.06.18.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Mar 2026 06:18:46 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e47a8fc0-170b-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1772547526; x=1773152326; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=HuTfQgsOPgXncwtzFb0ToG36NX3pcQJjsDUuwPvdBSs=; b=FDD8nsUFt75xmCdQxlEkGUS/HYkaDSwlzSsKETGNQZ+IJvXMm7IAnc9B43/VgMipMU 1FGJ49WMKMcgY/t56mr8hwoBG/9cm69UJI+AME7IT5wEImcELdLLyhmwtU+De3OR66Ag GQKf7Z2Gnme5IoZkKuMy74+Ame+wn2UV3FrRQ4B7L/U6iUI3IeM7C82ozkhg9ZqJtXIf iO3JzrPC8/ec/5MZ9VFTGOdjHblfAEEhJivcWM86WHAohBmu1DXA3ooH54W0hV0dQmAY yhD9paGP1LiN6Bo2Oq9HFcysEnx1jlDMP0J2KmY883M6CiSb5ZU0JbnVC8aU9P4LlXI4 FpRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772547526; x=1773152326; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HuTfQgsOPgXncwtzFb0ToG36NX3pcQJjsDUuwPvdBSs=; b=MjuN7tvz6zMP6fIhtolyDvLma2LXZxKnpOlD9qdOH3tebuJ+oJ5qYW2Ovrqo0m15+7 RxV3M+gT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Received: by 2002:a5d:5885:0:b0:435:9cd5:bb2a with SMTP id ffacd0b85a97d-4399de032c0mr28955619f8f.24.1772547526439; Tue, 03 Mar 2026 06:18:46 -0800 (PST) Message-ID: Date: Tue, 3 Mar 2026 15:18:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 4/4] tools/tests/x86_emulator: avoid passing NULL to memcpy To: =?UTF-8?B?RWR3aW4gVMO2csO2aw==?= Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Anthony PERARD , xen-devel@lists.xenproject.org References: <340f6a9fc4fdd4216f41e4bbdb1234069322d1c8.1772189234.git.edwin.torok@citrix.com> Content-Language: en-US From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <340f6a9fc4fdd4216f41e4bbdb1234069322d1c8.1772189234.git.edwin.torok@citrix.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Nit: Why do you talk of memset() though when memcpy() is what you alter? > but `glibc` > does specify it as non-null, which allows the compiler to make > optimizations assuming it never is NULL, so this is undefined behaviour > only on glibc. > Best to avoid the potential undefined behaviour though. > > Signed-off-by: Edwin Török Acked-by: Jan Beulich with both nits (above and below) addressed. I can again take care of that when committing. (Same remark applies here as to the usefulness of compiling ... > --- a/tools/tests/x86_emulator/test_x86_emulator.c > +++ b/tools/tests/x86_emulator/test_x86_emulator.c ... this file with sanitizer options active.) > @@ -611,7 +611,8 @@ static int fetch( > if ( verbose ) > printf("** %s(CS:%p,, %u,)\n", __func__, (void *)offset, bytes); > > - memcpy(p_data, (void *)offset, bytes); > + if (bytes) Nit: Style. A well formed if() is even visible in context. Jan > + memcpy(p_data, (void *)offset, bytes); > return X86EMUL_OKAY; > } >