Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/torture/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 -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 // suppressing buffer overflow warnings. | 5 // suppressing buffer overflow warnings. |
6 // { dg-skip-if "" { *-*-* } { "*" } { "-O0" "-O2" } } | 6 // { dg-skip-if "" { *-*-* } { "*" } { "-O0" "-O2" } } |
7 // { dg-skip-if "" { *-*-* } { "-flto" } { "" } } | 7 // { dg-skip-if "" { *-*-* } { "-flto" } { "" } } |
8 // { dg-require-effective-target alloca } | |
8 | 9 |
9 extern "C" { | 10 extern "C" { |
10 | 11 |
11 typedef __SIZE_TYPE__ size_t; | 12 typedef __SIZE_TYPE__ size_t; |
12 extern void *memset (void *, int, size_t); | 13 extern void *memset (void *, int, size_t); |
701 | 702 |
702 strncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } | 703 strncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } |
703 strncat (w, s2, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } | 704 strncat (w, s2, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } |
704 stpncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } | 705 stpncpy (w, s1, sizeof (w)); // { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } |
705 | 706 |
706 // These are correct, no warning. | |
707 const char s3[] = "foobarbaz"; | 707 const char s3[] = "foobarbaz"; |
708 const char s4[] = "abcde12345678"; | 708 const char s4[] = "abcde12345678"; |
709 strncpy (x, s3, sizeof (s3)); | 709 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" } |
710 strncat (x, s4, sizeof (s4)); | 710 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" } |
711 stpncpy (x, s3, sizeof (s3)); | 711 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" } |
712 | |
713 // These are safe, no warning. | |
712 y[1] = strndup (s3, sizeof (s3)); | 714 y[1] = strndup (s3, sizeof (s3)); |
713 z += strncmp (s3, s4, sizeof (s3)); | 715 z += strncmp (s3, s4, sizeof (s3)); |
714 z += strncmp (s3, s4, sizeof (s4)); | 716 z += strncmp (s3, s4, sizeof (s4)); |
715 z += strncasecmp (s3, s4, sizeof (s3)); | 717 z += strncasecmp (s3, s4, sizeof (s3)); |
716 z += strncasecmp (s3, s4, sizeof (s4)); | 718 z += strncasecmp (s3, s4, sizeof (s4)); |