9front - general discussion about 9front
 help / color / mirror / Atom feed
* [PATCH] fix APE sscanf [ specifier
@ 2020-05-07  7:49 telephil9
  2020-05-07 16:24 ` telephil9
  0 siblings, 1 reply; 5+ messages in thread
From: telephil9 @ 2020-05-07  7:49 UTC (permalink / raw)
  To: 9front; +Cc: telephil9

Hi,

APE sscanf return value is wrong when using a [ specifier and there is no match.
The following code highlights the issue (full example: http://okturing.com/src/8478/body)
	char s[2];
	sscanf("H", " %1[Zz] ", s); // SHOULD NOT RETURN 1

This patch fixes the issue:
---

diff -r 8006152d13d2 sys/src/ape/lib/ap/stdio/vfscanf.c
--- a/sys/src/ape/lib/ap/stdio/vfscanf.c	Tue Apr 28 20:51:19 2020 -0700
+++ b/sys/src/ape/lib/ap/stdio/vfscanf.c	Thu May 07 09:44:39 2020 +0200
@@ -396,13 +396,14 @@
 			if(nn==0) return 0;
 			else goto Done;
 		}
-		if(!match(c, pat))
-			break;
+		if(!match(c, pat)){
+			nungetc(c, f);
+			return 0;
+		}
 		if(store)
 			*s++=c;
 		nn++;
 	}
-	nungetc(c, f);
 Done:
 	if(store) *s='\0';
 	return 1;

---

Regards,
Philippe


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-09 22:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07  7:49 [PATCH] fix APE sscanf [ specifier telephil9
2020-05-07 16:24 ` telephil9
2020-05-08 15:11   ` [9front] " ori
2020-05-09  6:40     ` telephil9
2020-05-09 22:13       ` ori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).