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':
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to