Skip to contentSkip to conversation

tests/test-mmap.c: Check mmap() return value before using it

PATCH Applied Peter Maydell 2 participants 2 messages Apr 14, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/test-mmap.c: Check mmap() return value before using it

Correct the position of a "stop if MAP_FAILED" check in the mmap() tests, so that if mmap() does fail we print a failure message rather than segfaulting inside memcpy().

---
 tests/test-mmap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tests/test-mmap.c +1 -1
index fcb365f..c578e25 100644
@@ -164,6 +164,7 @@ void check_aligned_anonymous_unfixed_colliding_mmaps(void)
 		nlen = pagesize * 8;
 		p3 = mmap(NULL, nlen, PROT_READ, 
 			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+		fail_unless (p3 != MAP_FAILED);
 
 		/* Check if the mmaped areas collide.  */
 		if (p3 < p2 
@@ -174,7 +175,6 @@ void check_aligned_anonymous_unfixed_colliding_mmaps(void)
 
 		/* Make sure we get pages aligned with the pagesize. The
 		   target expects this.  */
-		fail_unless (p3 != MAP_FAILED);
 		p = (uintptr_t) p3;
 		fail_unless ((p & pagemask) == 0);
 		munmap (p2, pagesize);
Signature · 1 line
1.7.1
#1 lore raw
Quoted 5 lines · Peter Maydell

Correct the position of a "stop if MAP_FAILED" check in the mmap() tests, so that if mmap() does fail we print a failure message rather than segfaulting inside memcpy().

I've applied this, thanks.

Quoted 28 lines
---
 tests/test-mmap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tests/test-mmap.c +1 -1
index fcb365f..c578e25 100644
@@ -164,6 +164,7 @@ void check_aligned_anonymous_unfixed_colliding_mmaps(void)
 		nlen = pagesize * 8;
 		p3 = mmap(NULL, nlen, PROT_READ, 
 			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+		fail_unless (p3 != MAP_FAILED);
 
 		/* Check if the mmaped areas collide.  */
 		if (p3 < p2 
@@ -174,7 +175,6 @@ void check_aligned_anonymous_unfixed_colliding_mmaps(void)
 
 		/* Make sure we get pages aligned with the pagesize. The
 		   target expects this.  */
-		fail_unless (p3 != MAP_FAILED);
 		p = (uintptr_t) p3;
 		fail_unless ((p & pagemask) == 0);
 		munmap (p2, pagesize);
Signature · 1 line
1.7.1