bin/181153: sscanf doesn't skip whitespace properly

Garrett Cooper yaneurabeya at gmail.com
Fri Aug 9 02:10:02 UTC 2013


The following reply was made to PR kern/181153; it has been noted by GNATS.

From: Garrett Cooper <yaneurabeya at gmail.com>
To: Andrey Chernov <ache at freebsd.org>
Cc: "FreeBSD-gnats-submit at FreeBSD.org" <freebsd-gnats-submit at freebsd.org>
Subject: Re: bin/181153: sscanf doesn't skip whitespace properly
Date: Thu, 8 Aug 2013 19:03:10 -0700

 On Thu, Aug 8, 2013 at 6:24 PM, Andrey Chernov <ache at freebsd.org> wrote:
 > On 09.08.2013 4:23, Garrett Cooper wrote:
 >> ATF_TC_BODY(sscanf_whitespace, tc)
 >> {
 >>         const char str[] = "\f\n\r\t\v%z";
 >>         char c;
 >>
 >>         /* set of "white space" symbols from isspace(3) */
 >>         c = 0;
 >>         (void)sscanf(str, "%%%c", &c);
 >>         ATF_REQUIRE(c == 'z');
 >> }
 >
 > I doubt this exampe should skip whitespace. POSIX says:
 > "A directive that is an ordinary character shall be executed as follows:
 > the next byte shall be read from the input and compared with the byte
 > that comprises the directive; if the comparison shows that they are not
 > equivalent, the directive shall fail, and the differing and subsequent
 > bytes shall remain unread."
 > %% is the ordinary % character and no isspace(3) skipping mentioned in
 > this explanation.
 
 What about this line [*]?
 
 "
 A directive composed of one or more white-space characters is executed
 by reading input until no more valid input can be read, or up to the
 first byte which is not a white-space character which remains unread.
 "
 
 I think this is what the NetBSD test developer was shooting for originally.
 
 FWIW I did print out the value previously and it was (char)0, or '\0'.
 
 Thanks!
 
 * http://pubs.opengroup.org/onlinepubs/7908799/xsh/fscanf.html


More information about the freebsd-bugs mailing list