]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
test-segfault: Fix build error caused by a null pointer dereference warning
authorRalf Habacker <ralf.habacker@freenet.de>
Tue, 8 Mar 2022 08:02:51 +0000 (09:02 +0100)
committerSimon McVittie <smcv@collabora.com>
Thu, 21 Apr 2022 12:54:23 +0000 (13:54 +0100)
Only do the deliberate crash via undefined behaviour (which the compiler
is quite right to warn us about!) if raise() isn't available.

The pointer needs to be volatile otherwise the compiler is free to remove
the store.

Part-of: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/275
Reviewed-by: Simon McVittie <smcv@collabora.com>
test/test-segfault.c

index 5c559ccb9a0e4ec027fd32526141d8d0b24aa103..ef905c58d198d925b49ae3ebd578ae577408c545 100644 (file)
 int
 main (int argc, char **argv)
 {
-  char *p;  
-
   _dbus_disable_crash_handling ();
 
 #ifdef HAVE_RAISE
   raise (SIGSEGV);
+#else
+  {
+    volatile char *p = NULL;
+    *p = 'a';
+  }
 #endif
-  p = NULL;
-  *p = 'a';
-  
+
   return 0;
 }