From: Martin Sebor Date: Thu, 10 Aug 2017 17:40:11 +0000 (+0000) Subject: PR c++/81586 - valgrind error in output_buffer_append_r with -Wall X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0a8923facae32e5cb1886f885fb5eb64d4614b73;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 95d07f6de14..c49cb4aad01 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-08-10 Martin Sebor + + PR c++/81586 + * pretty-print.c (pp_format): Correct the handling of %s precision. + 2017-08-10 H.J. Lu PR target/81736 diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c index 570dec77dc1..556462fafe7 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;