From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mimir.eigenstate.org ([206.124.132.107]) by ewsd; Thu May 14 20:52:00 EDT 2020 Received: from abbatoir.fios-router.home (pool-162-83-132-245.nycmny.fios.verizon.net [162.83.132.245]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 8f01a80b (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO); Thu, 14 May 2020 17:51:49 -0700 (PDT) Message-ID: <80954AE3C6C5B7FA9CEE3F96050E744A@eigenstate.org> To: qwx@sciops.net, 9front@9front.org Subject: Re: [9front] libstdio fscanf regression Date: Thu, 14 May 2020 17:51:47 -0700 From: ori@eigenstate.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: session standard NoSQL manager > 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 #include #include 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++;