about summary refs log tree commit diff
path: root/stdio-common
diff options
context:
space:
mode:
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/vfprintf.c13
-rw-r--r--stdio-common/vfscanf.c10
2 files changed, 13 insertions, 10 deletions
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index bcff97118d..08333035d8 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -1992,7 +1992,7 @@ group_number (CHAR_T *w, CHAR_T *rear_ptr, const char *grouping,
     /* No grouping should be done.  */
     return w;
 
-  len = *grouping;
+  len = *grouping++;
 
   /* Copy existing string so that nothing gets overwritten.  */
   src = (CHAR_T *) alloca ((rear_ptr - w) * sizeof (CHAR_T));
@@ -2017,11 +2017,7 @@ group_number (CHAR_T *w, CHAR_T *rear_ptr, const char *grouping,
 	  while (cnt > 0);
 #endif
 
-	  len = *grouping++;
-	  if (*grouping == '\0')
-	    /* The previous grouping repeats ad infinitum.  */
-	    --grouping;
-	  else if (*grouping == CHAR_MAX
+	  if (*grouping == CHAR_MAX
 #if CHAR_MIN < 0
 		   || *grouping < 0
 #endif
@@ -2034,6 +2030,11 @@ group_number (CHAR_T *w, CHAR_T *rear_ptr, const char *grouping,
 	      while (s > src);
 	      break;
 	    }
+	  else if (*grouping != '\0')
+	    /* The previous grouping repeats ad infinitum.  */
+	    len = *grouping++;
+	  else
+	    len = grouping[-1];
 	}
     }
   return w;
diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
index 4f6a531b0c..75e187b765 100644
--- a/stdio-common/vfscanf.c
+++ b/stdio-common/vfscanf.c
@@ -1776,7 +1776,8 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 		      ADDW (c);
 		      got_dot = 1;
 		    }
-		  else if (thousands != L'\0' && ! got_dot && c == thousands)
+		  else if ((flags & GROUP) != 0 && thousands != L'\0'
+			   && ! got_dot && c == thousands)
 		    ADDW (c);
 		  else
 		    {
@@ -1820,12 +1821,13 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 			 we can compare against it.  */
 		      const char *cmp2p = thousands;
 
-		      if (thousands != NULL && ! got_dot)
+		      if ((flags & GROUP) != 0 && thousands != NULL
+			  && ! got_dot)
 			{
-			  while (cmp2p < cmpp
+			  while (cmp2p - thousands < cmpp - decimal
 				 && *cmp2p == decimal[cmp2p - thousands])
 			    ++cmp2p;
-			  if (cmp2p == cmpp)
+			  if (cmp2p - thousands == cmpp - decimal)
 			    {
 			      while ((unsigned char) *cmp2p == c && avail > 0)
 				if (*++cmp2p == '\0')