diff options
Diffstat (limited to 'stdio')
-rw-r--r-- | stdio/vfprintf.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/stdio/vfprintf.c b/stdio/vfprintf.c index 056ea32bee..1246229a63 100644 --- a/stdio/vfprintf.c +++ b/stdio/vfprintf.c @@ -531,13 +531,24 @@ vfprintf (s, format, ap) len = 0; } } - else - len = strlen (str); + else if (specs[cnt].info.prec != -1) + { + const char *end = memchr (str, '\0', specs[cnt].info.prec); + if (end) + len = end - str; + else + len = strlen (str); + } + else + { + len = strlen (str); + + if (specs[cnt].info.prec != -1 + && (size_t) specs[cnt].info.prec < len) + /* Limit the length to the precision. */ + len = specs[cnt].info.prec; + } - if (specs[cnt].info.prec != -1 - && (size_t) specs[cnt].info.prec < len) - /* Limit the length to the precision. */ - len = specs[cnt].info.prec; specs[cnt].info.width -= len; if (!specs[cnt].info.left) |