[4/6] tests: Use volatile pointer for NULL dereference

Submitted by Daniel Stone on Aug. 29, 2018, 6:17 a.m.

Details

Message ID 20180829061715.27776-5-daniels@collabora.com
State Accepted
Commit 9575d1c772378df73cd421997b70d4a880575911
Headers show
Series "Minor test/scanner fixes" ( rev: 1 ) in Wayland (DEPRECATED)

Commit Message

Daniel Stone Aug. 29, 2018, 6:17 a.m.
Clang warns that it can silently discard a non-volatile write to a NULL
pointer (perhaps it constitutes undefined behaviour?), and recommends
changing it to volatile.

This patch slavishly complies with the demand of the unfeeling machine.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 tests/sanity-test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/tests/sanity-test.c b/tests/sanity-test.c
index 66ca16fb..2495a115 100644
--- a/tests/sanity-test.c
+++ b/tests/sanity-test.c
@@ -70,8 +70,10 @@  FAIL_TEST(fail_kill)
 
 FAIL_TEST(fail_segv)
 {
+	char * volatile *null = 0;
+
 	test_disable_coredumps();
-	* (char **) 0 = "Goodbye, world";
+	*null = "Goodbye, world";
 }
 
 FAIL_TEST(sanity_assert)

Comments

On Tuesday, 28 August 2018 23:17:13 PDT Daniel Stone wrote:
> Clang warns that it can silently discard a non-volatile write to a NULL
> pointer (perhaps it constitutes undefined behaviour?), and recommends

It is.

> changing it to volatile.

That doesn't help. It's still UB and can be discarded because you're not 
allowed to provoke UB. If you need to write to a whose value is identical to 
NULL, write assembly.

How about a raise(SIGSEGV) instead?