about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-07-25 14:47:53 +0000
committerRoland McGrath <roland@gnu.org>1995-07-25 14:47:53 +0000
commit874f1b9bd817c0fa7e9fb231ec2e377c819d73a4 (patch)
tree28683317a46c9e0bea67039e80401fb82ab24e85
parent51813e8065f8b03c09ceca85eaada73645096d26 (diff)
downloadglibc-874f1b9bd817c0fa7e9fb231ec2e377c819d73a4.tar.gz
glibc-874f1b9bd817c0fa7e9fb231ec2e377c819d73a4.tar.xz
glibc-874f1b9bd817c0fa7e9fb231ec2e377c819d73a4.zip
Tue Jul 25 09:14:53 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
	* stdio/vfprintf.c (vfprintf): For %s with precision spec, use
 	memchr instead of strlen to limit search for NUL by precision.
-rw-r--r--ChangeLog5
-rw-r--r--stdio/vfprintf.c23
2 files changed, 22 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 5e22580c13..c329a30a64 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Jul 25 09:14:53 1995  Roland McGrath  <roland@churchy.gnu.ai.mit.edu>
+
+	* stdio/vfprintf.c (vfprintf): For %s with precision spec, use
+ 	memchr instead of strlen to limit search for NUL by precision.
+
 Mon Jul 24 03:13:16 1995  Roland McGrath  <roland@churchy.gnu.ai.mit.edu>
 
 	* sysdeps/posix/pathconf.c: New file.
diff --git a/stdio/vfprintf.c b/stdio/vfprintf.c
index 056ea32bee..1246229a63 100644
--- a/stdio/vfprintf.c
+++ b/stdio/vfprintf.c
@@ -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)