delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2004/03/09/14:24:30

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
From: <ams AT ludd DOT ltu DOT se>
Message-Id: <200403091922.i29JMCqL016181@speedy.ludd.ltu.se>
Subject: Broken sscanf test case
To: DJGPP-WORKERS <djgpp-workers AT delorie DOT com>
Date: Tue, 9 Mar 2004 20:22:12 +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

Hello.

I've noticed that the test case in libc/ansi/stdio/sscanf3.c is
broken. When we wrote it we forgot that the standard says "returns the
value of the macro EOF if an input failure _occurs_ _before_ _any_
_conversion_" (my underlining).

It looks like we simply forgot the underlined words.

Thus this (pasted) patch is how I understand how it should be:

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       9 Mar 2004 19:11:47 -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" },


Note that I consider suppressed assignments as (successful)
conversions.

If this is right, we instantly have errors in our sscanf() of
course. I discovered this problem when "sscanf( "5,5,5", 
"%d,%d,%d %c", &i1, &i2, &i3, &a_char )" returned -1 instead of my
expectation, 3.


Right,

						MartinS

- Raw text -


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