Skip analyzer strndup test on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overread-5.c
blobb75002b4295f63064348bed99253d57ad312060f
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 -Wno-array-bounds" } */
6 typedef __SIZE_TYPE__ size_t;
8 size_t strlen (const char *);
10 void sink (void*, ...);
12 void off_sz_or_1 (size_t i)
14 i |= 1;
16 /* Verify the offset in the notes only mentions the meaningful lower
17 bound and not a range with the excessive (and meaningless) upper
18 bound like [2, 9223372036854775807]. */
19 extern char a[1];
20 // { dg-message "at offset 1 into source object 'a'" "note" { target *-*-* } .-1 }
21 // { dg-message "at offset 2 " "note" { target *-*-* } .-2 }
23 char *p1 = a + i;
24 char *p2 = p1 + 1;
25 char *p3 = p1 - 1;
27 size_t n = 0;
28 n += strlen (p1); // { dg-warning "reading 1 or more bytes from a region of size 0" }
29 n += strlen (p2); // { dg-warning "reading 1 or more bytes from a region of size 0" }
30 n += strlen (p3);
32 sink (p1, p2, p3, n);
36 void off_sz_or_2 (size_t i)
38 i |= 2;
40 extern char b[2];
41 // { dg-message "at offset 2 " "note" { target *-*-* } .-1 }
42 // { dg-message "at offset 3 " "note" { target *-*-* } .-2 }
44 char *p1 = b + i;
45 char *p2 = p1 + 1;
46 char *p3 = p1 - 1;
48 size_t n = 0;
49 n += strlen (p1); // { dg-warning "reading 1 or more bytes from a region of size 0" }
50 n += strlen (p2); // { dg-warning "reading 1 or more bytes from a region of size 0" }
51 n += strlen (p3);
53 sink (p1, p2, p3, n);
57 void off_sz_or_4 (size_t i)
59 i |= 4;
61 extern char c[3];
62 // { dg-message "at offset 4 " "note" { target *-*-* } .-1 }
63 // { dg-message "at offset 5 " "note" { target *-*-* } .-2 }
64 // { dg-message "at offset 3 " "note" { target *-*-* } .-3 }
66 char *p1 = c + i;
67 char *p2 = p1 + 1;
68 char *p3 = p1 - 1;
70 size_t n = 0;
71 n += strlen (p1); // { dg-warning "reading 1 or more bytes from a region of size 0" }
72 n += strlen (p2); // { dg-warning "reading 1 or more bytes from a region of size 0" }
73 n += strlen (p3); // { dg-warning "reading 1 or more bytes from a region of size 0" }
75 sink (p1, p2, p3, n);