Subject: scanf bug (Re: lib/4838)
To: None <current-users@NetBSD.ORG>
From: Ian Dall <Ian.Dall@dsto.defence.gov.au>
List: current-users
Date: 02/25/1998 11:02:36
--Fr+6gul6Ok
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
A while ago I reported a bug #4838.
How do you "follow up" a bug report?
Anyway, I noticed the following in comp.std.c and I checked in current
and we do have the bug which Chris has fixed. I have not tested (yet)
if it fixes the problem #4838, but it seems likely.
Ian
--Fr+6gul6Ok
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Path: fang.dsto.defence.gov.au!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!feed2.news.erols.com!erols!feeder.qis.net!news.umbc.edu!cs.umd.edu!elf.bsdi.com!not-for-mail
Newsgroups: comp.std.c
Organization: none of the above
Lines: 40
Message-ID: <6csjoc$ijn@elf.bsdi.com>
References: <34eed9be.0@newshost.pcug.org.au> <34F13CCD.2132C14C@soton.sc.philips.com> <vyzen0usflu.fsf@issan.informatik.uni-dortmund.de> <34F19292.33506964@soton.sc.philips.com>
NNTP-Posting-Host: elf.bsdi.com
Xref: fang.dsto.defence.gov.au comp.std.c:19123
From: torek@elf.bsdi.com (Chris Torek)
Subject: Re: sscanf("3","%d%n",&d,&n): should 'n' be set?
Date: 23 Feb 1998 11:47:24 -0800
In article <34F19292.33506964@soton.sc.philips.com>
Stephen Baynes <stephen.baynes@soton.sc.philips.com> wrote:
>The implication of that is that [%n] can't fail, otherwise one would need
>it to count it under the return value. Going back to the original question,
>that means that %n should not fail even if it is matching against the end
>of input.
Yes. Moreover, it means that "%d %n" should *also* set "n". I
misunderstood this a bit when implementing the 4.4BSD stdio, and
made format-whitespace-directive processing too eager. For anyone
using that stdio, here is a patch to the vfscanf code.
*** svfscanf.c 1996/06/03 15:24:22 2.1
--- svfscanf.c 1998/01/21 16:36:27 2.2
***************
*** 129,139 ****
return (nassigned);
if (isspace(c)) {
! for (;;) {
! if (fp->_r <= 0 && __srefill(fp))
! return (nassigned);
! if (!isspace(*fp->_p))
! break;
nread++, fp->_r--, fp->_p++;
- }
continue;
}
--- 129,135 ----
return (nassigned);
if (isspace(c)) {
! while ((fp->_r > 0 || __srefill(fp) == 0) &&
! isspace(*fp->_p))
nread++, fp->_r--, fp->_p++;
continue;
}
--
In-Real-Life: Chris Torek, Berkeley Software Design Inc
El Cerrito, CA Domain: torek@bsdi.com +1 510 234 3167
Antispam notice: unsolicited commercial email will be handled at my
consulting rate; pyramid-scheme mail will be forwarded to the FTC.
--Fr+6gul6Ok--