aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-4.c
blob: 4b40336127e990d97a9c685ef1e25b2ae52063a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* { dg-do compile } */
/* { dg-options "-Wformat -Wformat-length=1 -fdiagnostics-show-caret -ftrack-macro-expansion=0" } */

extern int sprintf (char*, const char*, ...);

char dst [8];

void test (void)
{
  sprintf (dst + 7, "%-s", "1");
  /* { dg-warning "writing a terminating nul past the end of the destination" "" { target *-*-* } 10 }
     { dg-message "format output 2 bytes into a destination of size 1" "" { target *-*-* } 10 }
     { dg-begin-multiline-output "" }
   sprintf (dst + 7, "%-s", "1");
                      ~~^~
     { dg-end-multiline-output "" }
     { dg-begin-multiline-output "" }
   sprintf (dst + 7, "%-s", "1");
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   { dg-end-multiline-output "" } */

  sprintf (dst + 7, "%-s", "abcd");
  /* { dg-warning ".%-s. directive writing 4 bytes into a region of size 1" "" { target *-*-* } 22 }
     { dg-message "format output 5 bytes into a destination of size 1" "" { target *-*-* } 22 }
     { dg-begin-multiline-output "" }
   sprintf (dst + 7, "%-s", "abcd");
                      ^~~   ~~~~~~
     { dg-end-multiline-output "" }
     { dg-begin-multiline-output "" }
   sprintf (dst + 7, "%-s", "abcd");
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    { dg-end-multiline-output "" } */
}