1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/* Test to exercise attribute "nonstring".
{ dg-do compile }
{ dg-options "-O2 -Wattributes -Wstringop-truncation -ftrack-macro-expansion=0" } */
#define ATTR(list) __attribute__ (list)
#define NONSTR ATTR ((nonstring))
#define strncpy(d, s, n) (__builtin_strncpy ((d), (s), (n)), sink (d))
void sink (void*);
/* Global string with an known bound. */
extern char gns3[][3] NONSTR;
/* Global non-string pointers. */
extern NONSTR char (*pns_1)[1];
extern char (* NONSTR pns_2)[2];
extern char (*pns_3)[3] NONSTR;
struct MemArrays
{
NONSTR char ma3[2][3];
char NONSTR ma4[3][4];
char ma5[4][5] NONSTR;
};
void test_array (const char *s, unsigned n)
{
const char s7[] = "1234567";
strncpy (gns3[2], "", 0);
strncpy (gns3[2], "a", 1);
strncpy (gns3[2], "a", 2);
strncpy (gns3[2], "a", 3);
strncpy (gns3[2], "ab", 3);
strncpy (gns3[2], "abc", 3);
}
void test_pointer (const char *s, unsigned n)
{
const char s7[] = "1234567";
strncpy (*pns_1, "a", 1);
strncpy (*pns_2, "ab", 2);
strncpy (*pns_3, "abc", 3);
strncpy (*pns_3, s7, 3);
strncpy (*pns_1, s, 1);
strncpy (*pns_2, s, 1);
strncpy (*pns_3, s, 1);
strncpy (*pns_1, s, n);
strncpy (*pns_2, s, n);
strncpy (*pns_3, s, n);
}
void test_member_array (struct MemArrays *p, const char *s, unsigned n)
{
const char s7[] = "1234567";
strncpy (p->ma3[1], "", 0);
strncpy (p->ma3[1], "a", 1);
strncpy (p->ma4[2], "ab", 2);
strncpy (p->ma5[3], "abc", 3);
strncpy (p->ma3[1], s, 1);
strncpy (p->ma4[2], s, 1);
strncpy (p->ma5[3], s, 1);
strncpy (p->ma3[1], s7, n);
strncpy (p->ma4[2], s7, n);
strncpy (p->ma5[3], s7, n);
}
|