[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: |
Dave Denholm |
Subject: |
Re: [gnugo-devel] cygwin sscanf problem in gtp.c |
Date: |
26 Oct 2001 15:23:47 +0100 |
Trevor Morris <address@hidden> writes:
> Here's a test file that shows how gtp.c fails.
> In short, the " %s %n" construct isn't working as expected. In the
> last sscanf, 1 is returned, but n is not set. This causes very
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.
(Or maybe this is implementation dependent ?)
dd
> bad behavior in gtp.c (line 97, etc.) [specifically p += n].
> Is this specific to cygwin, or do other platforms have this problem
> too?
>
> const char *db = "dragon_data black\n";
> const char *d1 = "dragon_data\n";
>
> char command[1024];
> int n=-1,r;
>
> dump(const char *s, char*command) {
> printf("%d %d '%s' '%s'\n", r, n, command, s);
> n = -1 ;
> }
>
>
> main() {
> r = sscanf(d1, " %s%n", command, &n);
> dump(d1, command);
> r = sscanf(db, " %s%n", command, &n);
> dump(db, command);
> r = sscanf(d1, " %s%n", command, &n);
> dump(d1, command);
>
> r = sscanf(d1, " %s %n", command, &n);
> dump(d1, command);
> r = sscanf(db, " %s %n", command, &n);
> dump(db, command);
> r = sscanf(d1, " %s %n", command, &n);
> dump(d1, command);
> }
>
> cygwin (gcc) output:
> 1 11 'dragon_data' 'dragon_data
> '
> 1 11 'dragon_data' 'dragon_data black
> '
> 1 11 'dragon_data' 'dragon_data
> '
> 1 -1 'dragon_data' 'dragon_data
> '
> 1 12 'dragon_data' 'dragon_data black
> '
> 1 -1 'dragon_data' 'dragon_data
> '
>
>
> VC output:
> 1 11 'dragon_data' 'dragon_data
> '
> 1 11 'dragon_data' 'dragon_data black
> '
> 1 11 'dragon_data' 'dragon_data
> '
> 1 12 'dragon_data' 'dragon_data
> '
> 1 12 'dragon_data' 'dragon_data black
> '
> 1 12 'dragon_data' 'dragon_data
> '
>
>
>
>
> _______________________________________________
> gnugo-devel mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/gnugo-devel
dd
--
address@hidden http://www.insignia.com