malloc/Makefile: Split and sort tests
[glibc.git] / sysdeps / pthread / tst-cleanup2.c
blobfd305a8b52f687ad9af7eda45169c8a7d61721a1
1 /* Copyright (C) 2003-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <setjmp.h>
19 #include <signal.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <sys/types.h>
24 static sigjmp_buf jmpbuf;
26 static void
27 sig_handler (int signo)
29 siglongjmp (jmpbuf, 1);
32 static int
33 do_test (void)
35 char *p = NULL;
36 /* gcc can overwrite the success written value by scheduling instructions
37 around sprintf. It is allowed to do this since according to C99 the first
38 argument of sprintf is a character array and NULL is not a valid character
39 array. Mark the return value as volatile so that it gets reloaded on
40 return. */
41 volatile int ret = 0;
43 if (signal (SIGSEGV, &sig_handler) == SIG_ERR)
45 perror ("installing SIGSEGV handler");
46 return 1;
49 puts ("Attempting to sprintf to null ptr");
50 if (setjmp (jmpbuf))
52 puts ("Exiting main...");
53 return ret;
56 sprintf (p, "This should segv\n");
58 return 1;
61 #define TEST_FUNCTION do_test ()
62 #include "../test-skeleton.c"