9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: qwx@sciops.net, 9front@9front.org
Subject: Re: [9front] libstdio fscanf regression
Date: Thu, 14 May 2020 17:51:47 -0700	[thread overview]
Message-ID: <80954AE3C6C5B7FA9CEE3F96050E744A@eigenstate.org> (raw)
In-Reply-To: <C2203AEDA91A3A95DDC2F8A8755C03FE@wopr.sciops.net>

> Hello,
> 
> Commit 7551 (fix '%[]' specifiers and '%n' (thanks phil9)) seems to have
> broken libstdio's *scanf (ape version untested).
> 
> Test case is games/doom's configuration file loading, which uses fscanf:
> /sys/src/games/doom/m_misc.c:314
> 
> ...
> 
> 	    if (fscanf (f, "%79s %[^\n]\n", def, strparm) == 2)
> 
> ...

Thanks for the report -- I think this is what we want. At least,
it works for your test case, and it tracks with what I'd expect
the semantics to be. I haven't pored over the spec yet.

Test code:

#include <u.h>
#include <libc.h>
#include <stdio.h>

void
main(int argc, char **argv)
{
	char def[80], strparm[128];

	print("%d\n", scanf("%79s %[^\n]\n", def, strparm));
	exits(nil);
}

Patch:

diff -r 35459627f401 sys/src/ape/lib/ap/stdio/vfscanf.c
--- a/sys/src/ape/lib/ap/stdio/vfscanf.c	Wed May 13 18:50:01 2020 -0700
+++ b/sys/src/ape/lib/ap/stdio/vfscanf.c	Thu May 14 17:48:32 2020 -0700
@@ -416,7 +416,7 @@
 		}
 		if(!match(c, pat)){
 			nungetc(c, f);
-			return 0;
+			return nn > 0;
 		}
 		if(store)
 			*s++=c;
diff -r 35459627f401 sys/src/libstdio/vfscanf.c
--- a/sys/src/libstdio/vfscanf.c	Wed May 13 18:50:01 2020 -0700
+++ b/sys/src/libstdio/vfscanf.c	Thu May 14 17:48:32 2020 -0700
@@ -339,6 +339,7 @@
 	int c, nn;
 	register char *s;
 	register const char *pat;
+
 	pat=++fmtp;
 	if(*fmtp=='^') fmtp++;
 	if(*fmtp!='\0') fmtp++;
@@ -354,7 +355,7 @@
 		}
 		if(!match(c, pat)){
 			nungetc(c, f);
-			return 0;
+			return nn > 0;
 		}
 		if(store) *s++=c;
 		nn++;



  reply	other threads:[~2020-05-15  0:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15  0:20 qwx
2020-05-15  0:51 ` ori [this message]
2020-05-15  1:37   ` [9front] " qwx
2020-05-15  1:42     ` ori
2020-05-15  2:06       ` qwx

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=80954AE3C6C5B7FA9CEE3F96050E744A@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    --cc=qwx@sciops.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).