]> git.ipfire.org Git - thirdparty/gcc.git/commit
Patch for middle-end/PR79538
authorQing Zhao <qing.zhao@oracle.com>
Thu, 14 Dec 2017 17:37:20 +0000 (17:37 +0000)
committerQing Zhao <qinzhao@gcc.gnu.org>
Thu, 14 Dec 2017 17:37:20 +0000 (17:37 +0000)
commit2004617a8c2e67005230ebfcbdd1e4216b411bf1
tree707f59bba7756a18a71f663acf1e92c0218c53c4
parent65fe74706ffbd4d51bf31add434843b1991b2b39
Patch for middle-end/PR79538
missing -Wformat-overflow with %s and non-member array arguments

-Wformat-overflow uses the routine "get_range_strlen" to decide the
maximum string length, however, currently "get_range_strlen" misses
the handling of non-member arrays.

Adding the handling of non-member array resolves the issue.
Adding test case pr79538.c into gcc.dg.

During gcc bootstrap, 2 source files (c-family/c-cppbuiltin.c,
fortran/class.c) were detected new warnings by -Wformat-overflow
due to the new handling of non-member array in "get_range_strlen".
in order to avoid these new warnings and continue with bootstrap,
updating these 2 files to avoid the warnings.

in c-family/c-cppbuiltin.c, the warning is following:

../../latest_gcc_2/gcc/c-family/c-cppbuiltin.c:1627:15: note:
‘sprintf’ output 2 or more bytes (assuming 257) into a destination
of size 256
       sprintf (buf1, "%s=%s", macro, buf2);
       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
in the above, buf1 and buf2 are declared as:
char buf1[256], buf2[256];

i.e, buf1 and buf2 have same size. adjusting the size of buf1 and
buf2 resolves the warning.

fortran/class.c has the similar issue as above. Instead of adjusting
size of the buffers, replacing sprintf with xasprintf is a better
solution for these cases.

From-SVN: r255654
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-cppbuiltin.c
gcc/fortran/ChangeLog
gcc/fortran/class.c
gcc/gimple-fold.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr79538.c [new file with mode: 0644]