|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] tools/tests/x86_emulator: avoid passing NULL to memcpy
commit bdd49cc2f61510797a47ad81486be653633ab3ee
Author: Edwin Török <edwin.torok@xxxxxxxxxx>
AuthorDate: Wed Mar 4 08:26:11 2026 +0100
Commit: Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Mar 4 08:26:11 2026 +0100
tools/tests/x86_emulator: avoid passing NULL to memcpy
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 `memcpy` with NULL and 0, 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 <edwin.torok@xxxxxxxxxx>
Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
---
tools/tests/x86_emulator/test_x86_emulator.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/tests/x86_emulator/test_x86_emulator.c
b/tools/tests/x86_emulator/test_x86_emulator.c
index f30568b7f1..20929b80c6 100644
--- a/tools/tests/x86_emulator/test_x86_emulator.c
+++ b/tools/tests/x86_emulator/test_x86_emulator.c
@@ -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 )
+ memcpy(p_data, (void *)offset, bytes);
return X86EMUL_OKAY;
}
--
generated by git-patchbot for /home/xen/git/xen.git#staging
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |