Skip to contentSkip to conversation

tests/tcg/i386/test-flags: Check mmap() return value

PATCH New longlong yan 1 participant 1 message Jun 30

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/tcg/i386/test-flags: Check mmap() return value

test-flags.c calls mmap() to allocate a page but does not check whether it succeeded. If the allocation fails, the following *mprotect()* and *asm* block dereference the invalid pointer and produce a confusing failure.

Add an assertion to fail early with a clear message.

Fixes e7bbb7cb71b3 ("target/i386: introduce flags writeback mechanism")
---
 tests/tcg/i386/test-flags.c | 1 +
 1 file changed, 1 insertion(+)
tests/tcg/i386/test-flags.c +1 -0
index c379e29627..4ecf7053e2 100644
@@ -21,6 +21,7 @@ int main()
 
     /* fault in the page then protect it */
     addr = mmap (NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
+    assert(addr != MAP_FAILED);
     *addr = 0x1234;
     mprotect(addr, 4096, PROT_READ);
 
Signature · 1 line
2.43.0