[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gnugo-devel] cygwin sscanf problem in gtp.c
From: |
Gunnar Farneback |
Subject: |
Re: [gnugo-devel] cygwin sscanf problem in gtp.c |
Date: |
Fri, 26 Oct 2001 17:02:18 +0200 |
User-agent: |
EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/20.7 (sparc-sun-solaris2.7) (with unibyte mode) |
Dave wrote:
> Is the before %n intentional - it's saying match a string as %s,
> then if it can match some whitespace, put the number of characers
> consumed into %n. Since scanf stops as soon as the match fails,
> it could satisfy the %s, but then if it fails to match the whitespace
> it will return 1 without filling in the %n.
The Linux man page for sscanf is very clear and says:
White space (such as blanks, tabs, or newlines) in the format string
match any amount of white space, including none, in the input.
The Solaris man page is less clear but very similar to the text I
believe is in the standard. Relevant passages include
The format is a character string, beginning and ending in
its initial shift state, if any, composed of zero or more
directives. Each directive is composed of one of the follow-
ing:
o one or more white-space characters (space, tab, new-
line, vertical-tab or form-feed characters);
o an ordinary character (neither % nor a white-space
character); or
o a conversion specification.
[...]
The scanf() functions execute each directive of the format
in turn. If a directive fails, as detailed below, the func-
tion returns. Failures are described as input failures (due
to the unavailability of input bytes) or matching failures
(due to inappropriate input).
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.
We can notice
1. There is no provision for failure when the directive is a white
space. (In contrast to the other cases, which I excluded above.)
2. The newline at the end of the string *is* a white space and should
be matched.
My conclusion is that this is a bug in cygwin.
/Gunnar