On Dez 06 2019, Martin Sebor wrote:

> diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-27.c 
> b/gcc/testsuite/gcc.dg/Wstringop-overflow-27.c
> new file mode 100644
> index 00000000000..249ce2b6ad5
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-27.c

> +void test_strcpy_warn (const char *s)
> +{
> +  {
> +    const char a[] = "123";
> +    /* Verify that using signed int for the strlen result works (i.e.,
> +       that the conversion from signed int to size_t doesn't prevent
> +       the detection.  */
> +    int n = strlen (a);
> +    char *t = (char*)calloc (n, 1);     // { dg-message "at offset 0 to an 
> object with size 3 allocated by 'calloc' here" "calloc note" { xfail *-*-* } }
> +                                        // { dg-message "at offset 0 to an 
> object with size at most 3 allocated by 'calloc' here" "calloc note" { target 
> *-*-* } .-1 }

Please make the test name unique.

> +    strcpy (t, a);                      // { dg-warning "writing 4 bytes 
> into a region of size (between 0 and )?3 " }
> +
> +    sink (t);
> +  }
> +
> +  {
> +    const char a[] = "1234";
> +    size_t n = strlen (a);
> +    char *t = (char*)malloc (n);        // { dg-message "at offset 0 to an 
> object with size 4 allocated by 'malloc' here" "malloc note" { xfail *-*-* } }
> +                                        // { dg-message "at offset 0 to an 
> object with size at most 4 allocated by 'malloc' here" "malloc note" { target 
> *-*-* } .-1 }

Likewise.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

Reply via email to