From: Ralf Habacker Date: Tue, 8 Mar 2022 08:02:51 +0000 (+0100) Subject: test-segfault: Fix build error caused by a null pointer dereference warning X-Git-Tag: dbus-1.15.0~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e8423d2991bc6d7f5b4e54c2513a48c39cd23e8;p=thirdparty%2Fdbus.git test-segfault: Fix build error caused by a null pointer dereference warning 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 --- diff --git a/test/test-segfault.c b/test/test-segfault.c index 5c559ccb9..ef905c58d 100644 --- a/test/test-segfault.c +++ b/test/test-segfault.c @@ -10,15 +10,16 @@ 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; }