diff options
-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; |