aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wformat-overflow1.c
blob: cf9766fae144afc2ca32e7661e879ef66572dafa (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
/*
    { dg-do compile }
    { dg-options "-Wformat-overflow -std=c2x" }
*/

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

void test_warn () {

    int n = __INT_MAX__;
    char dst [5] = {0};
    sprintf (dst, "%b", n);  /* { dg-warning "-Wformat-overflow" } */

    sprintf (dst, "%#b", n); /* { dg-warning "-Wformat-overflow" } */

}

void test_no_warn () {

    char dst [5] = {0};
    int n = 8;
    sprintf (dst, "%b", n);

    char another_dst [34] = {0};
    n = __INT_MAX__;
    sprintf (another_dst, "%#b", n);

}