From 0b8ef5a98dc10bb279eb65a8e7b11db2a2ddb3ae Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 1 Aug 2020 07:27:17 +0100 Subject: [PATCH] daemon/debug.c: Use __builtin_trap to cause segfault. I couldn't get GCC 10.1 to ignore this warning any longer, possibly because I am using LTO. In any case dereferencing a pointer is undefined behaviour, so let's use GCC's __builtin_trap() function instead (also supported by clang). debug.c: In function 'debug_segv': debug.c:1002:8: error: null pointer dereference [-Werror=null-dereference] 1002 | *ptr = 1; | ^ --- daemon/debug.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/daemon/debug.c b/daemon/debug.c index 9bd046698..61eb93712 100644 --- a/daemon/debug.c +++ b/daemon/debug.c @@ -984,22 +984,8 @@ do_internal_rhbz914931 (int count) return 0; } -#pragma GCC diagnostic push -#if defined(__GNUC__) && GUESTFS_GCC_VERSION >= 60000 /* gcc >= 6 */ -#pragma GCC diagnostic ignored "-Wnull-dereference" -#endif - static void deliberately_cause_a_segfault (void) { - /* http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html - * "Dereferencing a NULL Pointer: contrary to popular belief, - * dereferencing a null pointer in C is undefined. It is not defined - * to trap [...]" - */ - volatile int *ptr = NULL; - /* coverity[var_deref_op] */ - *ptr = 1; + __builtin_trap (); } - -#pragma GCC diagnostic pop