diff options
author | 2016-08-27 16:10:40 +0000 | |
---|---|---|
committer | 2016-08-27 16:10:40 +0000 | |
commit | b3e86db50598b6bdbfee08b867c2e335e2ead080 (patch) | |
tree | 7fbeb0705dfc9fc6068838df6b7df498dfa60f68 /lib/libc/stdio/vfprintf.c | |
parent | Enable ALPN regress now that it passes. (diff) | |
download | wireguard-openbsd-b3e86db50598b6bdbfee08b867c2e335e2ead080.tar.xz wireguard-openbsd-b3e86db50598b6bdbfee08b867c2e335e2ead080.zip |
When a precision is specified for a string format use strnlen()
to determine the length instead of doing it manually. OK schwarze@
Diffstat (limited to 'lib/libc/stdio/vfprintf.c')
-rw-r--r-- | lib/libc/stdio/vfprintf.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 1b497515500..49fa61af607 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfprintf.c,v 1.75 2016/08/17 22:15:08 tedu Exp $ */ +/* $OpenBSD: vfprintf.c,v 1.76 2016/08/27 16:10:40 millert Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -486,6 +486,8 @@ __vfprintf(FILE *fp, const char *fmt0, __va_list ap) * Scan the format for conversions (`%' character). */ for (;;) { + size_t len; + cp = fmt; while ((n = mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) { fmt += n; @@ -886,22 +888,10 @@ fp_common: cp = "(null)"; } - if (prec >= 0) { - /* - * can't use strlen; can only look for the - * NUL in the first `prec' characters, and - * strlen() will go further. - */ - char *p = memchr(cp, 0, prec); - - size = p ? (p - cp) : prec; - } else { - size_t len; - - if ((len = strlen(cp)) > INT_MAX) - goto overflow; - size = (int)len; - } + len = prec >= 0 ? strnlen(cp, prec) : strlen(cp); + if (len > INT_MAX) + goto overflow; + size = (int)len; sign = '\0'; break; case 'U': |