From d18533cc294552c39f69781e5a9b04b8882b6364 Mon Sep 17 00:00:00 2001 From: Pablo de Oliveira Date: Mon, 17 Mar 2014 19:13:22 +0100 Subject: [PATCH] Fix userprog tests for clang Recent clang version, detect attemps to dereference or call NULL, and eliminate the code. ../../tests/userprog/bad-read.c:11:9: warning: indirection of non-volatile null pointer will be deleted, not trap [-Wnull-dereference] *(int *) NULL); ^~~~~~~~~~~~~ This patchs adds the volatile modifier as necessary. It allows to use clang to compile the tests. --- src/tests/userprog/bad-jump.c | 5 ++++- src/tests/userprog/bad-read.c | 2 +- src/tests/userprog/bad-write.c | 2 +- src/tests/userprog/no-vm/multi-oom.c | 6 +++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/tests/userprog/bad-jump.c b/src/tests/userprog/bad-jump.c index 51b7c9f..a915c39 100644 --- a/src/tests/userprog/bad-jump.c +++ b/src/tests/userprog/bad-jump.c @@ -4,10 +4,13 @@ #include "tests/lib.h" #include "tests/main.h" +typedef int (* volatile functionptr)(void); + void test_main (void) { + functionptr fp = NULL; msg ("Congratulations - you have successfully called NULL: %d", - ((int (*)(void))NULL)()); + fp()); fail ("should have exited with -1"); } diff --git a/src/tests/userprog/bad-read.c b/src/tests/userprog/bad-read.c index 904c278..d821a9a 100644 --- a/src/tests/userprog/bad-read.c +++ b/src/tests/userprog/bad-read.c @@ -8,6 +8,6 @@ void test_main (void) { msg ("Congratulations - you have successfully dereferenced NULL: %d", - *(int *)NULL); + *(volatile int *) NULL); fail ("should have exited with -1"); } diff --git a/src/tests/userprog/bad-write.c b/src/tests/userprog/bad-write.c index 000c26b..9082c9b 100644 --- a/src/tests/userprog/bad-write.c +++ b/src/tests/userprog/bad-write.c @@ -7,6 +7,6 @@ void test_main (void) { - *(int *)NULL = 42; + *(volatile int *)NULL = 42; fail ("should have exited with -1"); } diff --git a/src/tests/userprog/no-vm/multi-oom.c b/src/tests/userprog/no-vm/multi-oom.c index 6a4472d..cd2c939 100644 --- a/src/tests/userprog/no-vm/multi-oom.c +++ b/src/tests/userprog/no-vm/multi-oom.c @@ -67,15 +67,15 @@ consume_some_resources_and_die (int seed) { consume_some_resources (); random_init (seed); - int *PHYS_BASE = (int *)0xC0000000; + volatile int *PHYS_BASE = (volatile int *)0xC0000000; switch (random_ulong () % 5) { case 0: - *(int *) NULL = 42; + *(volatile int *) NULL = 42; case 1: - return *(int *) NULL; + return *(volatile int *) NULL; case 2: return *PHYS_BASE; -- 2.30.2