Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gcc.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 /* { dg-require-effective-target alloca } */ |
8 | 8 |
702 | 702 |
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 strncpy (w, s1, 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 strncat (w, s2, 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 stpncpy (w, s1, sizeof (w)); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */ |
706 | 706 |
707 /* These are correct, no warning. */ | 707 /* These are pointless when the destination is large enough, and |
708 cause overflow otherwise. If the copies are guaranteed to be | |
709 safe the calls might as well be replaced by strcat(), strcpy(), | |
710 or memcpy(). */ | |
708 const char s3[] = "foobarbaz"; | 711 const char s3[] = "foobarbaz"; |
709 const char s4[] = "abcde12345678"; | 712 const char s4[] = "abcde12345678"; |
710 strncpy (x, s3, sizeof (s3)); | 713 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?" } */ |
711 strncat (x, s4, sizeof (s4)); | 714 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?" } */ |
712 stpncpy (x, s3, sizeof (s3)); | 715 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?" } */ |
716 | |
717 /* These are correct, no warning. */ | |
713 y[1] = strndup (s3, sizeof (s3)); | 718 y[1] = strndup (s3, sizeof (s3)); |
714 z += strncmp (s3, s4, sizeof (s3)); | 719 z += strncmp (s3, s4, sizeof (s3)); |
715 z += strncmp (s3, s4, sizeof (s4)); | 720 z += strncmp (s3, s4, sizeof (s4)); |
716 z += strncasecmp (s3, s4, sizeof (s3)); | 721 z += strncasecmp (s3, s4, sizeof (s3)); |
717 z += strncasecmp (s3, s4, sizeof (s4)); | 722 z += strncasecmp (s3, s4, sizeof (s4)); |