comparison gcc/testsuite/gcc.dg/builtin-stringop-chk-4.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
100 memcpy (buf + 5, s, UR (1, 2)); /* { dg-warning "writing between 1 and 2 bytes into a region of size 0 overflows the destination" } */ 100 memcpy (buf + 5, s, UR (1, 2)); /* { dg-warning "writing between 1 and 2 bytes into a region of size 0 overflows the destination" } */
101 101
102 memcpy (buf + size_max, s, UR (1, 2)); /* { dg-warning "writing between 1 and 2 bytes into a region of size 0 overflows the destination" "excessive pointer offset" { xfail *-*-* } } */ 102 memcpy (buf + size_max, s, UR (1, 2)); /* { dg-warning "writing between 1 and 2 bytes into a region of size 0 overflows the destination" "excessive pointer offset" { xfail *-*-* } } */
103 103
104 memcpy (buf, s, UR (ssize_max, size_max)); /* { dg-warning "writing \[0-9\]+ or more bytes into a region of size 5 overflows the destination" } */ 104 memcpy (buf, s, UR (ssize_max, size_max)); /* { dg-warning "writing \[0-9\]+ or more bytes into a region of size 5 overflows the destination" } */
105 memcpy (buf, s, UR (ssize_max + 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 105 memcpy (buf, s, UR (ssize_max + 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
106 memcpy (buf, s, UR (size_max - 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 106 memcpy (buf, s, UR (size_max - 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
107 107
108 /* Exercise memcpy into a destination of unknown size with excessive 108 /* Exercise memcpy into a destination of unknown size with excessive
109 number of bytes. */ 109 number of bytes. */
110 memcpy (d, s, UR (ssize_max, size_max)); 110 memcpy (d, s, UR (ssize_max, size_max));
111 memcpy (d, s, UR (ssize_max + 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 111 memcpy (d, s, UR (ssize_max + 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
112 112
113 memcpy (buf, s, SR (-1, 1)); 113 memcpy (buf, s, SR (-1, 1));
114 memcpy (buf, s, SR (-3, 2)); 114 memcpy (buf, s, SR (-3, 2));
115 memcpy (buf, s, SR (-5, 3)); 115 memcpy (buf, s, SR (-5, 3));
116 memcpy (buf, s, SR (-7, 4)); 116 memcpy (buf, s, SR (-7, 4));
122 memcpy (d, s, SR (-5, 3)); 122 memcpy (d, s, SR (-5, 3));
123 memcpy (d, s, SR (-7, 4)); 123 memcpy (d, s, SR (-7, 4));
124 memcpy (d, s, SR (-9, 5)); 124 memcpy (d, s, SR (-9, 5));
125 memcpy (d, s, SR (-11, 6)); 125 memcpy (d, s, SR (-11, 6));
126 126
127 memcpy (buf, s, SR (-2, -1)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 127 memcpy (buf, s, SR (-2, -1)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
128 memcpy (d, s, SR (-2, -1)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 128 memcpy (d, s, SR (-2, -1)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
129 129
130 /* Even though the following calls are bounded by the range of N's 130 /* Even though the following calls are bounded by the range of N's
131 type they must not cause a warning for obvious reasons. */ 131 type they must not cause a warning for obvious reasons. */
132 memcpy (buf, s, schar_val); 132 memcpy (buf, s, schar_val);
133 memcpy (buf, s, sshrt_val); 133 memcpy (buf, s, sshrt_val);
185 mempcpy (buf, s, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */ 185 mempcpy (buf, s, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */
186 186
187 mempcpy (buf, s, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */ 187 mempcpy (buf, s, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */
188 188
189 mempcpy (buf, s, UR (ssize_max, size_max)); /* { dg-warning "writing \[0-9\]+ or more bytes into a region of size 5 overflows the destination" } */ 189 mempcpy (buf, s, UR (ssize_max, size_max)); /* { dg-warning "writing \[0-9\]+ or more bytes into a region of size 5 overflows the destination" } */
190 mempcpy (buf, s, UR (ssize_max + 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 190 mempcpy (buf, s, UR (ssize_max + 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
191 mempcpy (buf, s, UR (size_max - 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 191 mempcpy (buf, s, UR (size_max - 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
192 192
193 /* Exercise mempcpy into a destination of unknown size with excessive 193 /* Exercise mempcpy into a destination of unknown size with excessive
194 number of bytes. */ 194 number of bytes. */
195 mempcpy (d, s, UR (ssize_max, size_max)); 195 mempcpy (d, s, UR (ssize_max, size_max));
196 mempcpy (d, s, UR (ssize_max + 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 196 mempcpy (d, s, UR (ssize_max + 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
197 } 197 }
198 198
199 /* Test memset with a number of bytes bounded by a known range. */ 199 /* Test memset with a number of bytes bounded by a known range. */
200 200
201 void test_memset_range (void *d) 201 void test_memset_range (void *d)
211 memset (buf, 0, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */ 211 memset (buf, 0, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */
212 212
213 memset (buf, 0, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */ 213 memset (buf, 0, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */
214 214
215 memset (buf, 0, UR (ssize_max, size_max)); /* { dg-warning "writing \[0-9\]+ or more bytes into a region of size 5 overflows the destination" } */ 215 memset (buf, 0, UR (ssize_max, size_max)); /* { dg-warning "writing \[0-9\]+ or more bytes into a region of size 5 overflows the destination" } */
216 memset (buf, 0, UR (ssize_max + 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 216 memset (buf, 0, UR (ssize_max + 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
217 memset (buf, 0, UR (size_max - 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 217 memset (buf, 0, UR (size_max - 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
218 218
219 /* Exercise memset into a destination of unknown size with excessive 219 /* Exercise memset into a destination of unknown size with excessive
220 number of bytes. */ 220 number of bytes. */
221 memset (d, 0, UR (ssize_max, size_max)); 221 memset (d, 0, UR (ssize_max, size_max));
222 memset (d, 0, UR (ssize_max + 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 222 memset (d, 0, UR (ssize_max + 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
223 } 223 }
224 224
225 /* Test bzero with a number of bytes bounded by a known range. */ 225 /* Test bzero with a number of bytes bounded by a known range. */
226 226
227 void test_bzero_range (void *d) 227 void test_bzero_range (void *d)
237 bzero (buf, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */ 237 bzero (buf, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */
238 238
239 bzero (buf, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */ 239 bzero (buf, UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 overflows the destination" } */
240 240
241 bzero (buf, UR (ssize_max, size_max)); /* { dg-warning "writing \[0-9\]+ or more bytes into a region of size 5 overflows the destination" } */ 241 bzero (buf, UR (ssize_max, size_max)); /* { dg-warning "writing \[0-9\]+ or more bytes into a region of size 5 overflows the destination" } */
242 bzero (buf, UR (ssize_max + 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 242 bzero (buf, UR (ssize_max + 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
243 bzero (buf, UR (size_max - 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 243 bzero (buf, UR (size_max - 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
244 244
245 /* Exercise bzero into a destination of unknown size with excessive 245 /* Exercise bzero into a destination of unknown size with excessive
246 number of bytes. */ 246 number of bytes. */
247 bzero (d, UR (ssize_max, size_max)); 247 bzero (d, UR (ssize_max, size_max));
248 bzero (d, UR (ssize_max + 1, size_max)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 248 bzero (d, UR (ssize_max + 1, size_max)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
249 } 249 }
250 250
251 /* Test strcat with an argument referencing a non-constant string of 251 /* Test strcat with an argument referencing a non-constant string of
252 lengths in a known range. */ 252 lengths in a known range. */
253 253
341 strncat (buf, S (0), 3); 341 strncat (buf, S (0), 3);
342 strncat (buf, S (0), 4); 342 strncat (buf, S (0), 4);
343 343
344 strncat (buf + 5, S (0), 0); 344 strncat (buf + 5, S (0), 0);
345 345
346 strncat (buf + 5, S (0), 1); /* { dg-warning "specified bound 1 exceeds destination size 0" } */ 346 strncat (buf + 5, S (0), 1); /* { dg-warning "specified \(bound|size\) 1 exceeds destination size 0" } */
347 strncat (buf + 5, S (1), 1); /* { dg-warning "specified bound 1 exceeds destination size 0" } */ 347 strncat (buf + 5, S (1), 1); /* { dg-warning "specified \(bound|size\) 1 exceeds destination size 0" } */
348 348
349 /* Strncat always appends a terminating null after copying the N 349 /* Strncat always appends a terminating null after copying the N
350 characters so the following triggers a warning pointing out 350 characters so the following triggers a warning pointing out
351 that specifying sizeof(buf) as the upper bound may cause 351 that specifying sizeof(buf) as the upper bound may cause
352 the nul to overflow the destination. */ 352 the nul to overflow the destination. */
353 strncat (buf, S (0), 5); /* { dg-warning "specified bound 5 equals destination size" } */ 353 strncat (buf, S (0), 5); /* { dg-warning "specified \(bound|size\) 5 equals destination size" } */
354 strncat (buf, S (0), 6); /* { dg-warning "specified bound 6 exceeds destination size 5" } */ 354 strncat (buf, S (0), 6); /* { dg-warning "specified \(bound|size\) 6 exceeds destination size 5" } */
355 355
356 strncat (buf, S (1), 0); 356 strncat (buf, S (1), 0);
357 strncat (buf, S (1), 1); 357 strncat (buf, S (1), 1);
358 strncat (buf, S (1), 2); 358 strncat (buf, S (1), 2);
359 strncat (buf, S (1), 3); 359 strncat (buf, S (1), 3);
360 strncat (buf, S (1), 4); 360 strncat (buf, S (1), 4);
361 strncat (buf, S (1), 5); /* { dg-warning "specified bound 5 equals destination size" } */ 361 strncat (buf, S (1), 5); /* { dg-warning "specified \(bound|size\) 5 equals destination size" } */
362 strncat (buf, S (1), 6); /* { dg-warning "specified bound 6 exceeds destination size 5" } */ 362 strncat (buf, S (1), 6); /* { dg-warning "specified \(bound|size\) 6 exceeds destination size 5" } */
363 strncat (buf, S (2), 6); /* { dg-warning "specified bound 6 exceeds destination size 5" } */ 363 strncat (buf, S (2), 6); /* { dg-warning "specified \(bound|size\) 6 exceeds destination size 5" } */
364 364
365 /* The following could just as well say "writing 6 bytes into a region 365 /* The following could just as well say "writing 6 bytes into a region
366 of size 5. Either would be correct and probably equally as clear 366 of size 5. Either would be correct and probably equally as clear
367 in this case. But when the length of the source string is not known 367 in this case. But when the length of the source string is not known
368 at all then the bound warning seems clearer. */ 368 at all then the bound warning seems clearer. */
369 strncat (buf, S (5), 6); /* { dg-warning "specified bound 6 exceeds destination size 5" } */ 369 strncat (buf, S (5), 6); /* { dg-warning "specified \(bound|size\) 6 exceeds destination size 5" } */
370 strncat (buf, S (7), 6); /* { dg-warning "specified bound 6 exceeds destination size 5" } */ 370 strncat (buf, S (7), 6); /* { dg-warning "specified \(bound|size\) 6 exceeds destination size 5" } */
371 371
372 { 372 {
373 /* The implementation of the warning isn't smart enough to determine 373 /* The implementation of the warning isn't smart enough to determine
374 the length of the string in the buffer so it assumes it's empty 374 the length of the string in the buffer so it assumes it's empty
375 and issues the warning basically for the same cases as strncpy. */ 375 and issues the warning basically for the same cases as strncpy. */
390 390
391 strncat_chk (buf, S (0), 1); 391 strncat_chk (buf, S (0), 1);
392 strncat_chk (buf, S (0), 2); 392 strncat_chk (buf, S (0), 2);
393 strncat_chk (buf, S (0), 3); 393 strncat_chk (buf, S (0), 3);
394 strncat_chk (buf, S (0), 4); 394 strncat_chk (buf, S (0), 4);
395 strncat_chk (buf, S (0), 5); /* { dg-warning "specified bound 5 equals destination size" } */ 395 strncat_chk (buf, S (0), 5); /* { dg-warning "specified \(bound|size\) 5 equals destination size" } */
396 396
397 strncat_chk (buf, S (5), 1); 397 strncat_chk (buf, S (5), 1);
398 strncat_chk (buf, S (5), 2); 398 strncat_chk (buf, S (5), 2);
399 strncat_chk (buf, S (5), 3); 399 strncat_chk (buf, S (5), 3);
400 strncat_chk (buf, S (5), 4); 400 strncat_chk (buf, S (5), 4);
401 strncat_chk (buf, S (5), 5); /* { dg-warning "specified bound 5 equals destination size" } */ 401 strncat_chk (buf, S (5), 5); /* { dg-warning "specified \(bound|size\) 5 equals destination size" } */
402 402
403 strncat_chk (buf, S (5), 10); /* { dg-warning "specified bound \[0-9\]+ exceeds destination size 5" } */ 403 strncat_chk (buf, S (5), 10); /* { dg-warning "specified \(bound|size\) \[0-9\]+ exceeds destination size 5" } */
404 404
405 strncat_chk (d, S (5), size_max); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size " } */ 405 strncat_chk (d, S (5), size_max); /* { dg-warning "specified \(bound|size\) \[0-9\]+ exceeds maximum object size " } */
406 } 406 }
407 407
408 /* Test strncpy with a non-constant source string of length in a known 408 /* Test strncpy with a non-constant source string of length in a known
409 range and a constant number of bytes. */ 409 range and a constant number of bytes. */
410 410
424 strncpy (buf, S (7), 5); 424 strncpy (buf, S (7), 5);
425 strncpy (buf, S (8), 6); /* { dg-warning "writing 6 bytes into a region of size 5 " } */ 425 strncpy (buf, S (8), 6); /* { dg-warning "writing 6 bytes into a region of size 5 " } */
426 426
427 strncpy (buf, S (1), ssize_max - 1); /* { dg-warning "writing \[0-9\]+ bytes into a region of size 5" } */ 427 strncpy (buf, S (1), ssize_max - 1); /* { dg-warning "writing \[0-9\]+ bytes into a region of size 5" } */
428 strncpy (buf, S (2), ssize_max); /* { dg-warning "writing \[0-9\]+ bytes into a region of size 5" } */ 428 strncpy (buf, S (2), ssize_max); /* { dg-warning "writing \[0-9\]+ bytes into a region of size 5" } */
429 strncpy (buf, S (3), ssize_max + 1); /* { dg-warning "specified size \[0-9\]+ exceeds maximum object size" } */ 429 strncpy (buf, S (3), ssize_max + 1); /* { dg-warning "specified \(bound|size\) \[0-9\]+ exceeds maximum object size" } */
430 strncpy (buf, S (4), size_max); /* { dg-warning "specified size \[0-9\]+ exceeds maximum object size" } */ 430 strncpy (buf, S (4), size_max); /* { dg-warning "specified \(bound|size\) \[0-9\]+ exceeds maximum object size" } */
431 431
432 /* Exercise strncpy into a destination of unknown size with a valid 432 /* Exercise strncpy into a destination of unknown size with a valid
433 and invalid constant number of bytes. */ 433 and invalid constant number of bytes. */
434 strncpy (d, S (1), ssize_max - 1); 434 strncpy (d, S (1), ssize_max - 1);
435 strncpy (d, S (2), ssize_max); 435 strncpy (d, S (2), ssize_max);
436 strncpy (d, S (3), ssize_max + 1); /* { dg-warning "specified size \[0-9\]+ exceeds maximum object size" } */ 436 strncpy (d, S (3), ssize_max + 1); /* { dg-warning "specified \(bound|size\) \[0-9\]+ exceeds maximum object size" } */
437 strncpy (d, S (4), size_max); /* { dg-warning "specified size \[0-9\]+ exceeds maximum object size" } */ 437 strncpy (d, S (4), size_max); /* { dg-warning "specified \(bound|size\) \[0-9\]+ exceeds maximum object size" } */
438 } 438 }
439 439
440 /* Test strncpy with a non-constant source string of length in a known 440 /* Test strncpy with a non-constant source string of length in a known
441 range and a non-constant number of bytes also in a known range. */ 441 range and a non-constant number of bytes also in a known range. */
442 442
470 470
471 strncpy (buf, S (0), UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 " } */ 471 strncpy (buf, S (0), UR (6, 7)); /* { dg-warning "writing between 6 and 7 bytes into a region of size 5 " } */
472 strncpy (buf, S (1), UR (7, 8)); /* { dg-warning "writing between 7 and 8 bytes into a region of size 5 " } */ 472 strncpy (buf, S (1), UR (7, 8)); /* { dg-warning "writing between 7 and 8 bytes into a region of size 5 " } */
473 strncpy (buf, S (2), UR (ssize_max, ssize_max + 1)); /* { dg-warning "writing \[0-9\]+ or more bytes into a region of size 5 " } */ 473 strncpy (buf, S (2), UR (ssize_max, ssize_max + 1)); /* { dg-warning "writing \[0-9\]+ or more bytes into a region of size 5 " } */
474 474
475 strncpy (buf, S (2), UR (ssize_max + 1, ssize_max + 2)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 475 strncpy (buf, S (2), UR (ssize_max + 1, ssize_max + 2)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
476 476
477 strncpy (buf + 5, S (0), UR (0, 1)); 477 strncpy (buf + 5, S (0), UR (0, 1));
478 strncpy (buf + 5, S (1), UR (0, 1)); 478 strncpy (buf + 5, S (1), UR (0, 1));
479 strncpy (buf + 5, S (0), UR (1, 2)); /* { dg-warning "writing between 1 and 2 bytes into a region of size 0 " } */ 479 strncpy (buf + 5, S (0), UR (1, 2)); /* { dg-warning "writing between 1 and 2 bytes into a region of size 0 " } */
480 strncpy (buf + 5, S (1), UR (1, 2)); /* { dg-warning "writing between 1 and 2 bytes into a region of size 0 " } */ 480 strncpy (buf + 5, S (1), UR (1, 2)); /* { dg-warning "writing between 1 and 2 bytes into a region of size 0 " } */
498 strncpy (dst, S (1), UR (6, 7)); 498 strncpy (dst, S (1), UR (6, 7));
499 strncpy (dst, S (2), UR (7, 8)); 499 strncpy (dst, S (2), UR (7, 8));
500 500
501 strncpy (dst, S (3), UR (ssize_max, ssize_max + 1)); 501 strncpy (dst, S (3), UR (ssize_max, ssize_max + 1));
502 502
503 strncpy (dst, S (4), UR (ssize_max + 1, ssize_max + 2)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */ 503 strncpy (dst, S (4), UR (ssize_max + 1, ssize_max + 2)); /* { dg-warning "specified \(bound|size\) between \[0-9\]+ and \[0-9\]+ exceeds maximum object size" } */
504 } 504 }