Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Test -Wsizeof-pointer-memaccess warnings. */ | 1 /* Test -Wsizeof-pointer-memaccess warnings. */ |
2 /* { dg-do compile } */ | 2 /* { dg-do compile } */ |
3 /* { dg-options "-Wall -O2 -Wno-sizeof-array-argument -ftrack-macro-expansion=0" } */ | 3 /* { dg-options "-Wall -O2 -Wno-array-bounds -Wno-sizeof-array-argument -Wno-stringop-truncation -ftrack-macro-expansion=0" } */ |
4 /* { dg-options "-Wall -O2 -Wno-sizeof-array-argument -Wno-c++-compat -ftrack-macro-expansion=0" {target c} } */ | 4 /* { dg-options "-Wall -O2 -Wno-array-bounds -Wno-sizeof-array-argument -Wno-stringop-truncation -Wno-c++-compat -ftrack-macro-expansion=0" {target c} } */ |
5 /* { dg-require-effective-target alloca } */ | 5 /* { dg-require-effective-target alloca } */ |
6 | 6 |
7 #define bos(ptr) __builtin_object_size (ptr, 1) | 7 #define bos(ptr) __builtin_object_size (ptr, 1) |
8 #define bos0(ptr) __builtin_object_size (ptr, 0) | 8 #define bos0(ptr) __builtin_object_size (ptr, 0) |
9 | 9 |
471 | 471 |
472 strncpy (w, s1, sizeof (w)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */ | 472 strncpy (w, s1, sizeof (w)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */ |
473 strncat (w, s2, sizeof (w)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */ | 473 strncat (w, s2, sizeof (w)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */ |
474 stpncpy (w, s1, sizeof (w)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */ | 474 stpncpy (w, s1, sizeof (w)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */ |
475 | 475 |
476 /* These are correct, no warning. */ | 476 /* These are pointless when the destination is large enough, and |
477 cause overflow otherwise. If the copies are guaranteed to be | |
478 safe the calls might as well be replaced by strcat(), strcpy(), | |
479 or memcpy(). */ | |
477 const char s3[] = "foobarbaz"; | 480 const char s3[] = "foobarbaz"; |
478 const char s4[] = "abcde12345678"; | 481 const char s4[] = "abcde12345678"; |
479 strncpy (x, s3, sizeof (s3)); | 482 strncpy (x, s3, sizeof (s3)); /* { dg-warning "call is the same expression as the source; did you mean to use the size of the destination?" } */ |
480 strncat (x, s4, sizeof (s4)); | 483 strncat (x, s4, sizeof (s4)); /* { dg-warning "call is the same expression as the source; did you mean to use the size of the destination?" } */ |
481 stpncpy (x, s3, sizeof (s3)); | 484 stpncpy (x, s3, sizeof (s3)); /* { dg-warning "call is the same expression as the source; did you mean to use the size of the destination?" } */ |
482 } | 485 } |
483 | 486 |
484 /* { dg-prune-output "\[\n\r\]*writing\[\n\r\]*" } */ | 487 /* { dg-prune-output "\[\n\r\]*writing\[\n\r\]*" } */ |
485 /* { dg-prune-output "\[\n\r\]*reading\[\n\r\]*" } */ | 488 /* { dg-prune-output "\[\n\r\]*reading\[\n\r\]*" } */ |