summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2009-02-28 06:06:57 +0000
committerdas <das@FreeBSD.org>2009-02-28 06:06:57 +0000
commite5de8b5d17e9fc17c5f215cb5052acfa2a94f96b (patch)
tree7523c9dd08e5896a325226e1c1c23b88ff90a00d /lib/libc/stdio
parentebb4763b7fa6c54ee27fcd944e1d83d892f43906 (diff)
downloadFreeBSD-src-e5de8b5d17e9fc17c5f215cb5052acfa2a94f96b.zip
FreeBSD-src-e5de8b5d17e9fc17c5f215cb5052acfa2a94f96b.tar.gz
Replace a dozen lines of code with a call to strnlen() / wcsnlen().
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r--lib/libc/stdio/vfprintf.c17
-rw-r--r--lib/libc/stdio/vfwprintf.c18
2 files changed, 2 insertions, 33 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index 21e8f82..7e5d7fe 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -822,22 +822,7 @@ fp_common:
}
} else if ((cp = GETARG(char *)) == NULL)
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, (size_t)prec);
-
- if (p != NULL) {
- size = p - cp;
- if (size > prec)
- size = prec;
- } else
- size = prec;
- } else
- size = strlen(cp);
+ size = (prec >= 0) ? strnlen(cp, prec) : strlen(cp);
sign = '\0';
break;
case 'U':
diff --git a/lib/libc/stdio/vfwprintf.c b/lib/libc/stdio/vfwprintf.c
index 2aa4972..f3768de 100644
--- a/lib/libc/stdio/vfwprintf.c
+++ b/lib/libc/stdio/vfwprintf.c
@@ -890,23 +890,7 @@ fp_common:
cp = convbuf;
}
}
-
- if (prec >= 0) {
- /*
- * can't use wcslen; can only look for the
- * NUL in the first `prec' characters, and
- * wcslen() will go further.
- */
- wchar_t *p = wmemchr(cp, 0, (size_t)prec);
-
- if (p != NULL) {
- size = p - cp;
- if (size > prec)
- size = prec;
- } else
- size = prec;
- } else
- size = wcslen(cp);
+ size = (prec >= 0) ? wcsnlen(cp, prec) : wcslen(cp);
sign = '\0';
break;
case 'U':
OpenPOWER on IntegriCloud