delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2004/03/20/13:13:37

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
From: <ams AT ludd DOT ltu DOT se>
Message-Id: <200403201813.i2KID7Rn022566@speedy.ludd.ltu.se>
Subject: Re: Broken sscanf test case
In-Reply-To: <200403111020.LAA16907@lws256.emw.erisoft.se> "from Martin Stromberg
at Mar 11, 2004 11:20:57 am"
To: djgpp-workers AT delorie DOT com
Date: Sat, 20 Mar 2004 19:13:07 +0100 (CET)
X-Mailer: ELM [version 2.4ME+ PL78 (25)]
MIME-Version: 1.0
X-MailScanner: Found to be clean
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Hello.

First note that comp.std.c seems to agree with me:
<http://groups.google.se/groups?hl=sv&lr=&ie=UTF-8&threadm=4057500f%240%2496976%24cc7c7865%40news.luth.se&rnum=1&prev=/groups%3Fq%3Dsscanf%2Bsuppressed%2Bassignments%26hl%3Dsv%26lr%3D%26ie%3DUTF-8%26selm%3D4057500f%25240%252496976%2524cc7c7865%2540news.luth.se%26rnum%3D1>.


Here the patch:
Index: djgpp/src/libc/ansi/stdio/doscan.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doscan.c,v
retrieving revision 1.15
diff -p -u -r1.15 doscan.c
--- djgpp/src/libc/ansi/stdio/doscan.c	23 Nov 2003 21:14:48 -0000	1.15
+++ djgpp/src/libc/ansi/stdio/doscan.c	20 Mar 2004 17:48:30 -0000
@@ -59,11 +59,13 @@ _doscan_low(FILE *iop, int (*scan_getc)(
   register int ch;
   int nmatch, len, ch1;
   int *ptr, fileended, size;
+  int suppressed;
 
   decimal = localeconv()->decimal_point[0];
   nchars = 0;
   nmatch = 0;
   fileended = 0;
+  suppressed = 0;
   for (;;) switch (ch = *fmt++) {
   case '\0': 
     return (nmatch);
@@ -73,8 +75,9 @@ _doscan_low(FILE *iop, int (*scan_getc)(
     ptr = 0;
     if (ch != '*')
       ptr = va_arg(argp, int *);
-    else
+    else {
       ch = *fmt++;
+    }
     len = 0;
     size = REGULAR;
     while (isdigit(ch & 0xff)) {
@@ -168,11 +171,13 @@ _doscan_low(FILE *iop, int (*scan_getc)(
     {
       if (ptr)
 	nmatch++;
+      else
+	suppressed = 1;
     }
     else
     {
-      if (fileended)
-        return(EOF);
+      if (fileended && !nmatch && !suppressed)
+	return(EOF);
       return(nmatch);
     }
     break;
@@ -198,7 +203,7 @@ _doscan_low(FILE *iop, int (*scan_getc)(
     if (ch1 != EOF) nchars++;
     if (ch1 != ch) {
       if (ch1==EOF)
-	return(nmatch? nmatch: EOF);
+	return(nmatch||suppressed? nmatch: EOF);
       scan_ungetc(ch1, iop);
       nchars--;
       return(nmatch);
Index: djgpp/tests/libc/ansi/stdio/sscanf3.c
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/stdio/sscanf3.c,v
retrieving revision 1.1
diff -p -u -r1.1 sscanf3.c
--- djgpp/tests/libc/ansi/stdio/sscanf3.c	23 Nov 2003 21:14:48 -0000	1.1
+++ djgpp/tests/libc/ansi/stdio/sscanf3.c	20 Mar 2004 17:48:32 -0000
@@ -18,28 +18,28 @@ sscanf_testcase_t sscanf_testcases[] = {
   /* No assignment */
   { "",    "%*[0123456789]%*c",             EOF, "",  "" },
   { "X",   "%*[0123456789]%*c",             0,   "",  "" },
-  { "1",   "%*[0123456789]%*c",             EOF, "",  "" },
+  { "1",   "%*[0123456789]%*c",             0,   "",  "" },
   { "1X2", "%*[0123456789]%*[0123456789]",  0,   "",  "" },
   { "1,2", "%*[0123456789],%*[0123456789]", 0,   "",  "" },
 
   /* Assign first */
   { "",    "%[0123456789]%*c",              EOF, "",  "" },
   { "X",   "%[0123456789]%*c",              0,   "",  "" },
-  { "1",   "%[0123456789]%*c",              EOF, "1", "" },
+  { "1",   "%[0123456789]%*c",              1,   "1", "" },
   { "1X2", "%[0123456789]%*[0123456789]",   1,   "1", "" },
   { "1,2", "%[0123456789],%*[0123456789]",  1,   "1", "" },
 
   /* Assign second */
   { "",    "%*[0123456789]%c",              EOF, "",  "" },
   { "X",   "%*[0123456789]%c",              0,   "",  "" },
-  { "1",   "%*[0123456789]%c",              EOF, "",  "" },
+  { "1",   "%*[0123456789]%c",              0,   "",  "" },
   { "1X2", "%*[0123456789]%[0123456789]",   0,   "",  "" },
   { "1,2", "%*[0123456789],%[0123456789]",  1,   "2", "" },
 
   /* Assign both */
   { "",    "%[0123456789]%c",               EOF, "",  "" },
   { "X",   "%[0123456789]%c",               0,   "",  "" },
-  { "1",   "%[0123456789]%c",               EOF, "1", "" },
+  { "1",   "%[0123456789]%c",               1,   "1", "" },
   { "1X2", "%[0123456789]%[0123456789]",    1,   "1", "" },
   { "1,2", "%[0123456789],%[0123456789]",   2,   "1", "2" },
 

Right,

						MartinS

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019