annotate gcc/testsuite/gcc.dg/pr79214.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* PR preprocessor/79214 - -Wno-system-header defeats strncat buffer overflow
kono
parents:
diff changeset
2 warnings
kono
parents:
diff changeset
3 { dg-do compile }
kono
parents:
diff changeset
4 { dg-options "-O2" } */
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 #include "pr79214.h"
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 typedef __SIZE_TYPE__ size_t;
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 char d[3];
kono
parents:
diff changeset
11 char s[4];
kono
parents:
diff changeset
12
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
13 static size_t range (void)
111
kono
parents:
diff changeset
14 {
kono
parents:
diff changeset
15 extern size_t size ();
kono
parents:
diff changeset
16 size_t n = size ();
kono
parents:
diff changeset
17 if (n <= sizeof d)
kono
parents:
diff changeset
18 return sizeof d + 1;
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 return n;
kono
parents:
diff changeset
21 }
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 void test_bzero (void)
kono
parents:
diff changeset
24 {
kono
parents:
diff changeset
25 bzero (d, range ()); /* { dg-warning ".__builtin_(bzero|memset). writing 4 or more bytes into a region of size 3 overflows the destination" } */
kono
parents:
diff changeset
26 }
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 void test_memcpy (void)
kono
parents:
diff changeset
29 {
kono
parents:
diff changeset
30 memcpy (d, s, range ()); /* { dg-warning ".__builtin_memcpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */
kono
parents:
diff changeset
31 }
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 void test_memmove (void)
kono
parents:
diff changeset
34 {
kono
parents:
diff changeset
35 memmove (d, d + 1, range ()); /* { dg-warning ".__builtin_memmove. writing 4 or more bytes into a region of size 3 overflows the destination" } */
kono
parents:
diff changeset
36 }
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 void test_mempcpy (void)
kono
parents:
diff changeset
39 {
kono
parents:
diff changeset
40 mempcpy (d, s, range ()); /* { dg-warning ".__builtin_mempcpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */
kono
parents:
diff changeset
41 }
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 void test_memset (int n)
kono
parents:
diff changeset
44 {
kono
parents:
diff changeset
45 memset (d, n, range ()); /* { dg-warning ".__builtin_memset. writing 4 or more bytes into a region of size 3 overflows the destination" } */
kono
parents:
diff changeset
46 }
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 void test_strcat (int i)
kono
parents:
diff changeset
49 {
kono
parents:
diff changeset
50 const char *s = i < 0 ? "123" : "4567";
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 strcat (d, s); /* { dg-warning ".__builtin_strcat. writing between 4 and 5 bytes into a region of size 3 overflows the destination" } */
kono
parents:
diff changeset
53 }
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 char* test_stpcpy (int i)
kono
parents:
diff changeset
56 {
kono
parents:
diff changeset
57 const char *s = i < 0 ? "123" : "4567";
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 return stpcpy (d, s); /* { dg-warning ".__builtin_stpcpy. writing between 4 and 5 bytes into a region of size 3 overflows the destination" } */
kono
parents:
diff changeset
60 }
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 char* test_stpncpy (int i)
kono
parents:
diff changeset
63 {
kono
parents:
diff changeset
64 const char *s = i < 0 ? "123" : "4567";
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 return stpncpy (d, s, range ()); /* { dg-warning ".__builtin_stpncpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */
kono
parents:
diff changeset
67 }
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 char* test_strcpy (int i)
kono
parents:
diff changeset
70 {
kono
parents:
diff changeset
71 const char *s = i < 0 ? "123" : "4567";
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 return strcpy (d, s); /* { dg-warning ".__builtin_strcpy. writing between 4 and 5 bytes into a region of size 3 overflows the destination" } */
kono
parents:
diff changeset
74 }
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 char* test_strncpy (int i)
kono
parents:
diff changeset
77 {
kono
parents:
diff changeset
78 const char *s = i < 0 ? "123" : "4567";
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 return strncpy (d, s, range ()); /* { dg-warning ".__builtin_strncpy. writing 4 or more bytes into a region of size 3 overflows the destination" } */
kono
parents:
diff changeset
81 }
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 char* test_strncat (int i)
kono
parents:
diff changeset
84 {
kono
parents:
diff changeset
85 const char *s = i < 0 ? "123" : "4567";
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 return strncat (d, s, range ()); /* { dg-warning ".__builtin_strncat. specified bound between 4 and \[0-9\]+" } */
kono
parents:
diff changeset
88 }