Subject: scanf bug (Re: lib/4838)
To: None <current-users@NetBSD.ORG>
From: Ian Dall <>
List: current-users
Date: 02/25/1998 11:02:36
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.


Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit

Newsgroups: comp.std.c
Organization: none of the above
Lines: 40
Message-ID: <6csjoc$>
References: <> <> <> <>
Xref: comp.std.c:19123
From: (Chris Torek)
Subject: Re: sscanf("3","%d%n",&d,&n): should 'n' be set?
Date: 23 Feb 1998 11:47:24 -0800

In article <>
Stephen Baynes <> 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++;
- 			}
--- 129,135 ----
  			return (nassigned);
  		if (isspace(c)) {
! 			while ((fp->_r > 0 || __srefill(fp) == 0) &&
! 			    isspace(*fp->_p))
  				nread++, fp->_r--, fp->_p++;
In-Real-Life: Chris Torek, Berkeley Software Design Inc
El Cerrito, CA	Domain:	+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.