aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-cppbuiltin.c
diff options
context:
space:
mode:
authorqinzhao <qinzhao@138bc75d-0d04-0410-961f-82ee72b054a4>2017-12-14 17:37:20 +0000
committerqinzhao <qinzhao@138bc75d-0d04-0410-961f-82ee72b054a4>2017-12-14 17:37:20 +0000
commitb8bf7c13bf1dfe2f30729f6b7af9c3e9f0bdd2cf (patch)
tree707f59bba7756a18a71f663acf1e92c0218c53c4 /gcc/c-family/c-cppbuiltin.c
parente4b0fa233333db4e986ef959eba1fd38a67e8670 (diff)
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@255654 138bc75d-0d04-0410-961f-82ee72b054a4
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 2ac9616b72f..9e33aed9b8b 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