diff options
author | Martin Sebor <msebor@redhat.com> | 2017-08-10 17:40:11 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2017-08-10 11:40:11 -0600 |
commit | 0a8923facae32e5cb1886f885fb5eb64d4614b73 (patch) | |
tree | 3afaf3d6aadaa7921da6fe96079ae94f771e04cf | |
parent | 8e941ae950ddce1745b4d6819a7131908dd7de24 (diff) | |
download | gcc-0a8923facae32e5cb1886f885fb5eb64d4614b73.zip gcc-0a8923facae32e5cb1886f885fb5eb64d4614b73.tar.gz gcc-0a8923facae32e5cb1886f885fb5eb64d4614b73.tar.bz2 |
PR c++/81586 - valgrind error in output_buffer_append_r with -Wall
gcc/ChangeLog:
PR c++/81586
* pretty-print.c (pp_format): Correct the handling of %s precision.
From-SVN: r251029
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/pretty-print.c | 12 |
2 files changed, 16 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 95d07f6..c49cb4a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-08-10 Martin Sebor <msebor@redhat.com> + + PR c++/81586 + * pretty-print.c (pp_format): Correct the handling of %s precision. + 2017-08-10 H.J. Lu <hongjiu.lu@intel.com> PR target/81736 diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c index 570dec7..556462f 100644 --- a/gcc/pretty-print.c +++ b/gcc/pretty-print.c @@ -667,7 +667,17 @@ pp_format (pretty_printer *pp, text_info *text) } s = va_arg (*text->args_ptr, const char *); - pp_append_text (pp, s, s + n); + + /* Negative precision is treated as if it were omitted. */ + if (n < 0) + n = INT_MAX; + + /* Append the lesser of precision and strlen (s) characters. */ + size_t len = strlen (s); + if ((unsigned) n < len) + len = n; + + pp_append_text (pp, s, s + len); } break; |