Debian Codegraph @

gcc/testsuite/gcc.dg/Wstringop-overread-4.c

raw
1 /* Verify -Wstringop-overread with a source pointer pointing either
2 before the beginning or past the end of an object.
3 { dg-do compile }
4 { dg-options "-O -Wall" } */
5
6 typedef __SIZE_TYPE__ size_t;
7
8 size_t strlen (const char *);
9
10
11 extern char a[1];
12
13 volatile size_t n;
14
15 void len_si_1_max (int i)
16 {
17 if (i < 1) i = 1;
18 n = strlen (a + i); // { dg-warning "reading 1 or more bytes from a region of size 0" }
19 n = strlen (a + i + 1); // { dg-warning "reading 1 or more bytes from a region of size 0" }
20 }
21
22 void len_ui_1_max (unsigned i)
23 {
24 if (i < 1) i = 1;
25 n = strlen (a + i); // { dg-warning "reading 1 or more bytes from a region of size 0" }
26 n = strlen (a + i + 1); // { dg-warning "reading 1 or more bytes from a region of size 0" "" { xfail ilp32 } }
27 }
28
29 void len_sl_1_max (long i)
30 {
31 if (i < 1) i = 1;
32 n = strlen (a + i); // { dg-warning "reading 1 or more bytes from a region of size 0" }
33 n = strlen (a + i + 1); // { dg-warning "reading 1 or more bytes from a region of size 0" }
34 }
35
36 void len_ul_1_max (unsigned long i)
37 {
38 if (i < 1) i = 1;
39 n = strlen (a + i); // { dg-warning "reading 1 or more bytes from a region of size 0" }
40 n = strlen (a + i + 1); // { dg-warning "reading 1 or more bytes from a region of size 0" "" { xfail *-*-* } }
41 }
42
43
44 void len_si_min_m1 (int i)
45 {
46 if (i > -1) i = -1;
47 n = strlen (a + i - 1); // { dg-warning "reading 1 or more bytes from a region of size 0" "" { xfail lp64 } }
48 n = strlen (a + i); // { dg-warning "reading 1 or more bytes from a region of size 0" "" { xfail *-*-* } }
49 n = strlen (a + i + 2);
50 }
51
52 void len_sl_min_m1 (long i)
53 {
54 if (i > -1) i = -1;
55 n = strlen (a + i - 1); // { dg-warning "reading 1 or more bytes from a region of size 0" }
56 n = strlen (a + i); // { dg-warning "reading 1 or more bytes from a region of size 0" "" { xfail *-*-* } }
57 n = strlen (a + i + 2);
58 }