From owner-svn-src-head@FreeBSD.ORG Sat Feb 28 06:06:58 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 17357106566B; Sat, 28 Feb 2009 06:06:58 +0000 (UTC) (envelope-from das@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 059648FC14; Sat, 28 Feb 2009 06:06:58 +0000 (UTC) (envelope-from das@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n1S66vkI097138; Sat, 28 Feb 2009 06:06:57 GMT (envelope-from das@svn.freebsd.org) Received: (from das@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n1S66vcw097136; Sat, 28 Feb 2009 06:06:57 GMT (envelope-from das@svn.freebsd.org) Message-Id: <200902280606.n1S66vcw097136@svn.freebsd.org> From: David Schultz Date: Sat, 28 Feb 2009 06:06:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r189138 - head/lib/libc/stdio X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Feb 2009 06:06:58 -0000 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':