aboutsummaryrefslogtreecommitdiff
path: root/gcc/pretty-print.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/pretty-print.c')
-rw-r--r--gcc/pretty-print.c12
1 files changed, 11 insertions, 1 deletions
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;