aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-cppbuiltin.c
diff options
context:
space:
mode:
authorQing Zhao <qing.zhao@oracle.com>2017-12-14 17:37:20 +0000
committerQing Zhao <qinzhao@gcc.gnu.org>2017-12-14 17:37:20 +0000
commit2004617a8c2e67005230ebfcbdd1e4216b411bf1 (patch)
tree707f59bba7756a18a71f663acf1e92c0218c53c4 /gcc/c-family/c-cppbuiltin.c
parent65fe74706ffbd4d51bf31add434843b1991b2b39 (diff)
downloadgcc-2004617a8c2e67005230ebfcbdd1e4216b411bf1.zip
gcc-2004617a8c2e67005230ebfcbdd1e4216b411bf1.tar.gz
gcc-2004617a8c2e67005230ebfcbdd1e4216b411bf1.tar.bz2
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
Diffstat (limited to 'gcc/c-family/c-cppbuiltin.c')
-rw-r--r--gcc/c-family/c-cppbuiltin.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 2ac9616..9e33aed 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1613,7 +1613,7 @@ builtin_define_with_hex_fp_value (const char *macro,
const char *fp_cast)
{
REAL_VALUE_TYPE real;
- char dec_str[64], buf1[256], buf2[256];
+ char dec_str[64], buf[256], buf1[128], buf2[64];
/* This is very expensive, so if possible expand them lazily. */
if (lazy_hex_fp_value_count < 12
@@ -1656,11 +1656,11 @@ builtin_define_with_hex_fp_value (const char *macro,
/* Assemble the macro in the following fashion
macro = fp_cast [dec_str fp_suffix] */
- sprintf (buf1, "%s%s", dec_str, fp_suffix);
- sprintf (buf2, fp_cast, buf1);
- sprintf (buf1, "%s=%s", macro, buf2);
+ sprintf (buf2, "%s%s", dec_str, fp_suffix);
+ sprintf (buf1, fp_cast, buf2);
+ sprintf (buf, "%s=%s", macro, buf1);
- cpp_define (parse_in, buf1);
+ cpp_define (parse_in, buf);
}
/* Return a string constant for the suffix for a value of type TYPE