Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/torture/Wsizeof-pointer-memaccess1.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 -Wno-sizeof-array-argument -Wno-stringop-overflow" } | 3 // { dg-options "-Wall -Wno-array-bounds -Wno-sizeof-array-argument -Wno-stringop-overflow -Wno-stringop-truncation" } |
4 // Test just twice, once with -O0 non-fortified, once with -O2 fortified. | 4 // Test just twice, once with -O0 non-fortified, once with -O2 fortified. |
5 // { dg-skip-if "" { *-*-* } { "*" } { "-O0" "-O2" } } | 5 // { dg-skip-if "" { *-*-* } { "*" } { "-O0" "-O2" } } |
6 // { dg-skip-if "" { *-*-* } { "-flto" } { "" } } | 6 // { dg-skip-if "" { *-*-* } { "-flto" } { "" } } |
7 // { dg-require-effective-target alloca } | |
7 | 8 |
8 extern "C" { | 9 extern "C" { |
9 | 10 |
10 typedef __SIZE_TYPE__ size_t; | 11 typedef __SIZE_TYPE__ size_t; |
11 extern void *memset (void *, int, size_t); | 12 extern void *memset (void *, int, size_t); |
696 | 697 |
697 strncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } | 698 strncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } |
698 strncat (w, s2, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } | 699 strncat (w, s2, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } |
699 stpncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } | 700 stpncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } |
700 | 701 |
701 // These are correct, no warning. | |
702 const char s3[] = "foobarbaz"; | 702 const char s3[] = "foobarbaz"; |
703 const char s4[] = "abcde12345678"; | 703 const char s4[] = "abcde12345678"; |
704 strncpy (x, s3, sizeof (s3)); | 704 |
705 strncat (x, s4, sizeof (s4)); | 705 // These are pointless when the destination is large enough, and |
706 stpncpy (x, s3, sizeof (s3)); | 706 // cause overflow otherwise. They might as well be replaced by |
707 // strcpy() or memcpy(). | |
708 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?" } | |
709 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?" } | |
710 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?" } | |
711 | |
712 // These are safe, no warning. | |
707 y[1] = strndup (s3, sizeof (s3)); | 713 y[1] = strndup (s3, sizeof (s3)); |
708 z += strncmp (s3, s4, sizeof (s3)); | 714 z += strncmp (s3, s4, sizeof (s3)); |
709 z += strncmp (s3, s4, sizeof (s4)); | 715 z += strncmp (s3, s4, sizeof (s4)); |
710 z += strncasecmp (s3, s4, sizeof (s3)); | 716 z += strncasecmp (s3, s4, sizeof (s3)); |
711 z += strncasecmp (s3, s4, sizeof (s4)); | 717 z += strncasecmp (s3, s4, sizeof (s4)); |