www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/03/05:56:36

Date: Wed, 3 Apr 1996 14:43:44 +0400 (MSD)
From: "Alexander V. Lukyanov" <lav AT video DOT yars DOT free DOT net>
Message-Id: <199604031043.OAA28739@video.yars.free.net>
To: djgpp AT delorie DOT com
Subject: doscan patch

Here is the patch which intended to fix two problems with scanf family
recently reported. Those are: 
1. scanf returns 0 instead of -1 in some cases when it reaches eof before any
   matching failure or conversion.
2. scanf ignores matching failures.

--- doscan.c~	Wed Jan 24 04:31:46 1996
+++ doscan.c	Mon Apr  1 15:19:38 1996
@@ -56,6 +56,8 @@
   fileended = 0;
   for (;;) switch (ch = *fmt++) {
   case '\0': 
+    if (fileended && nmatch==0)
+       return(-1);
     return (nmatch);
   case '%':
     if ((ch = *fmt++) == '%')
@@ -101,12 +103,17 @@
     if (ch == '\0')
       return(-1);
     if (_innum(ptr, ch, len, size, iop, scan_getc, scan_ungetc,
-	       &fileended) && ptr)
-      nmatch++;
-/* breaks %n */
-/*    if (fileended) {
-      return(nmatch? nmatch: -1);
-    } */
+	       &fileended))
+    {
+      if (ptr)
+        nmatch++;
+    }
+    else
+    {
+      if (fileended && nmatch==0)
+        return(-1);
+      return(nmatch);
+    }
     break;
   case ' ':
   case '\n':

- Raw text -


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