regtest: fix compiler warnings with clang 16
[valgrind.git] / memcheck / tests / badjump2.c
blobae858e7733e904fdee8d5c93e52dced0dd1033ab
1 #include <assert.h>
2 #include <setjmp.h>
3 #include <signal.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
8 // Regression test for bug 91162: if a client had a SEGV signal handler,
9 // and jumped to a bogus address, Valgrind would abort. With the fix,
10 // the following test runs to completion correctly.
12 static jmp_buf myjmpbuf;
14 static
15 void SIGSEGV_handler(int signum)
17 longjmp(myjmpbuf, 1);
20 int main(void)
22 struct sigaction sigsegv_new, sigsegv_saved;
23 int res;
25 /* Install own SIGSEGV handler */
26 memset(&sigsegv_new, 0, sizeof(sigsegv_new));
27 sigsegv_new.sa_handler = SIGSEGV_handler;
28 sigsegv_new.sa_flags = 0;
29 #if !defined(__APPLE__) && !defined(__sun) && !defined(__FreeBSD__)
30 sigsegv_new.sa_restorer = NULL;
31 #endif
32 res = sigemptyset( &sigsegv_new.sa_mask );
33 assert(res == 0);
35 res = sigaction( SIGSEGV, &sigsegv_new, &sigsegv_saved );
36 assert(res == 0);
38 if (setjmp(myjmpbuf) == 0) {
39 // Jump to zero; will cause seg fault
40 #if defined(__powerpc64__) && (_CALL_ELF != 2)
41 unsigned long int fn[3];
42 fn[0] = 0;
43 fn[1] = 0;
44 fn[2] = 0;
45 #else
46 void (*fn)(void) = 0;
47 #endif
48 ((void(*)(void)) fn) ();
49 fprintf(stderr, "Got here??\n");
50 } else {
51 fprintf(stderr, "Signal caught, as expected\n");
54 return 0;