1 /* { dg-do compile } */ 2 /* { dg-options "-O2 -Warray-bounds" } */ 3 /* { dg-skip-if "exceeds eBPF stack limit" { bpf-*-* } } */ 4 /* based on PR 31227 */ 5 6 typedef __SIZE_TYPE__ size_t; 7 8 extern size_t strlen (const char *); 9 10 struct iovec 11 { 12 void *iov_base; 13 size_t iov_len; 14 }; 15 16 struct S 17 { 18 const char *abday[7]; 19 const char *day[7]; 20 const char *abmon[12]; 21 const char *mon[12]; 22 const char *am_pm[2]; 23 }; 24 25 extern void foo (size_t, struct iovec *); 26 27 void bar(struct S * time)28bar (struct S *time) 29 { 30 struct iovec iov[43]; 31 size_t cnt; 32 iov[0].iov_base = (void *) "abc"; 33 iov[0].iov_len = 3; 34 35 iov[1].iov_base = (void *) "def"; 36 iov[1].iov_len = 3; 37 38 for (cnt = 0; cnt < 7; ++cnt) 39 { 40 iov[2 + cnt].iov_base = (void *) (time->abday[cnt] ?: ""); 41 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; 42 } 43 44 for (; cnt < 14; ++cnt) 45 { 46 iov[2 + cnt].iov_base = (void *) (time->day[cnt - 7] ?: ""); 47 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; 48 } 49 50 for (; cnt < 26; ++cnt) 51 { 52 iov[2 + cnt].iov_base = (void *) (time->abmon[cnt - 14] ?: ""); 53 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; 54 } 55 56 for (; cnt < 38; ++cnt) 57 { 58 iov[2 + cnt].iov_base = (void *) (time->mon[cnt - 26] ?: ""); 59 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; 60 } 61 62 for (; cnt < 40; ++cnt) 63 { 64 iov[2 + cnt].iov_base = (void *) (time->am_pm[cnt - 38] ?: ""); 65 iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1; 66 } 67 68 foo (2 + cnt, iov); 69 } 70 71 struct malloc_chunk { 72 long prev_size; 73 long size; 74 struct malloc_chunk* fd; 75 struct malloc_chunk* bk; 76 }; 77 typedef struct malloc_chunk* mchunkptr; 78 struct malloc_state { 79 mchunkptr top; 80 mchunkptr last_remainder; 81 mchunkptr bins[128 * 2 - 2]; 82 }; 83 #define bin_at(m, i) \ 84 (mchunkptr) (((char *) &((m)->bins[((i) - 1) * 2])) \ 85 - __builtin_offsetof (struct malloc_chunk, fd)) 86 malloc_init_state(struct malloc_state * av)87void malloc_init_state(struct malloc_state *av) 88 { 89 int i; 90 mchunkptr bin; 91 92 for (i = 1; i < 128; ++i) { 93 bin = bin_at(av,i); 94 bin->fd = bin->bk = bin; 95 } 96 } 97 98 typedef unsigned short WCHAR; 99 typedef WCHAR *LPWSTR; 100 g(LPWSTR dest,int len)101static void g(LPWSTR dest, int len) { 102 dest[len-1] = 0; 103 } 104 f()105void f() { 106 WCHAR szPathW[260]; 107 108 g(szPathW, 260); 109 } 110