Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Feb 2009 06:06:57 +0000 (UTC)
From:      David Schultz <das@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r189138 - head/lib/libc/stdio
Message-ID:  <200902280606.n1S66vcw097136@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: das
Date: Sat Feb 28 06:06:57 2009
New Revision: 189138
URL: http://svn.freebsd.org/changeset/base/189138

Log:
  Replace a dozen lines of code with a call to strnlen() / wcsnlen().

Modified:
  head/lib/libc/stdio/vfprintf.c
  head/lib/libc/stdio/vfwprintf.c

Modified: head/lib/libc/stdio/vfprintf.c
==============================================================================
--- head/lib/libc/stdio/vfprintf.c	Sat Feb 28 06:05:37 2009	(r189137)
+++ head/lib/libc/stdio/vfprintf.c	Sat Feb 28 06:06:57 2009	(r189138)
@@ -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':

Modified: head/lib/libc/stdio/vfwprintf.c
==============================================================================
--- head/lib/libc/stdio/vfwprintf.c	Sat Feb 28 06:05:37 2009	(r189137)
+++ head/lib/libc/stdio/vfwprintf.c	Sat Feb 28 06:06:57 2009	(r189138)
@@ -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':



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200902280606.n1S66vcw097136>