(vfprintf): For %s with precision spec, use memchr instead of strlen to
authorroland <roland>
Tue, 25 Jul 1995 13:14:35 +0000 (13:14 +0000)
committerroland <roland>
Tue, 25 Jul 1995 13:14:35 +0000 (13:14 +0000)
limit search for NUL by precision.

stdio/vfprintf.c

index 056ea32..1246229 100644 (file)
@@ -531,13 +531,24 @@ vfprintf (s, format, ap)
                      len = 0;
                    }
                }
-              else
-                len = strlen (str);
+              else if (specs[cnt].info.prec != -1)
+               {
+                 const char *end = memchr (str, '\0', specs[cnt].info.prec);
+                 if (end)
+                   len = end - str;
+                 else
+                   len = strlen (str);
+               }
+             else
+               {
+                 len = strlen (str);
+
+                 if (specs[cnt].info.prec != -1
+                     && (size_t) specs[cnt].info.prec < len)
+                   /* Limit the length to the precision.  */
+                   len = specs[cnt].info.prec;
+               }
 
-              if (specs[cnt].info.prec != -1
-                 && (size_t) specs[cnt].info.prec < len)
-               /* Limit the length to the precision.  */
-                len = specs[cnt].info.prec;
               specs[cnt].info.width -= len;
 
               if (!specs[cnt].info.left)