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;
      |        ^
This commit is contained in:
Richard W.M. Jones
2020-08-01 07:27:17 +01:00
parent 599f2f7bd9
commit 0b8ef5a98d

View File

@@ -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