diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2018-07-23 13:20:38 +0000 |
---|---|---|
committer | Bernd Edlinger <edlinger@gcc.gnu.org> | 2018-07-23 13:20:38 +0000 |
commit | a353fec45af2c09f8e3c849ac8f00e7342600019 (patch) | |
tree | c06abcb5c0a4358ca0013b0cd13287b6275b0d3b | |
parent | 723f415edcc9d560beb82983d28ea0607d3c5286 (diff) | |
download | gcc-a353fec45af2c09f8e3c849ac8f00e7342600019.zip gcc-a353fec45af2c09f8e3c849ac8f00e7342600019.tar.gz gcc-a353fec45af2c09f8e3c849ac8f00e7342600019.tar.bz2 |
gimple-fold.c (gimple_fold_builtin_printf): Don't create a not NUL terminated STRING_CST object.
2018-07-23 Bernd Edlinger <bernd.edlinger@hotmail.de>
* gimple-fold.c (gimple_fold_builtin_printf): Don't create a not NUL
terminated STRING_CST object.
From-SVN: r262932
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/gimple-fold.c | 16 |
2 files changed, 8 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 13cc870..2cbe833 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2018-07-23 Bernd Edlinger <bernd.edlinger@hotmail.de> + * gimple-fold.c (gimple_fold_builtin_printf): Don't create a not NUL + terminated STRING_CST object. + +2018-07-23 Bernd Edlinger <bernd.edlinger@hotmail.de> + hsa-dump.c (dump_hsa_symbol): Avoid out of scope access to buf. 2018-07-23 Segher Boessenkool <segher@kernel.crashing.org> diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 027ca4d..c3fa570 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -3433,23 +3433,13 @@ gimple_fold_builtin_printf (gimple_stmt_iterator *gsi, tree fmt, && (int) len > 0) { char *newstr; - tree offset_node, string_cst; /* Create a NUL-terminated string that's one char shorter than the original, stripping off the trailing '\n'. */ - newarg = build_string_literal (len, str); - string_cst = string_constant (newarg, &offset_node); - gcc_checking_assert (string_cst - && (TREE_STRING_LENGTH (string_cst) - == (int) len) - && integer_zerop (offset_node) - && (unsigned char) - TREE_STRING_POINTER (string_cst)[len - 1] - == target_newline); - /* build_string_literal creates a new STRING_CST, - modify it in place to avoid double copying. */ - newstr = CONST_CAST (char *, TREE_STRING_POINTER (string_cst)); + newstr = xstrdup (str); newstr[len - 1] = '\0'; + newarg = build_string_literal (len, newstr); + free (newstr); if (fn_puts) { gcall *repl = gimple_build_call (fn_puts, 1, newarg); |