Fri 26 Oct 2007 12:06:25 AM UTC, comment #2:
I included a patch file.
Here are comment on the patch:
do {
i = getc(stream);
} while (isspace(i));
if (i == EOF)
goto leave;
this was remove. Reason:
Man file state: Matches a sequence of non-white-space characters...
Obviosly that part of code as the exact purpose of removing any leading space(or white-space characters). As a second remark, we dont yet decrement width(hit, bug is sscanf eats 1 char too much)
.
Next modif:
- while (width-- > 0)
+ do
Using a post decrement tation will end up in the following senarion. if Width == 6, we will loop 6 time, this way we will read 6 char from the stream. Didn't we just read 1 earlyer?
next modification: Bring
if ((i = getc(stream)) == EOF)
break;
just after the do
Since we are going to do some test condition on var i, we better have something in it. I guess it was done later on due to the fact that it was red in the part I removed earlyer.
final modif:
while (--width > 0);
To close the do-while, this will ensure a width reading.
I have not done much testing on it, just things that came to my mind. Comment are welcome
Fred
(file #14213)
|
Sun 18 Feb 2007 03:13:51 PM UTC, original submission:
Hello, I think we have a bug here.
example code:
char wsp_N[10];
char wsp_E[11];
int fixva = 0;
int nr_sat = 0;
int x = "$GP,194000.00,5001.4934,N,01954.5390,E,0,02,2.9";
int nrconv = sscanf(x, "$GP,%u.%u,%9s,N,%10s,E,%i,%i,%*s",
wsp_N, wsp_E, &fixva, &nr_sat);
nrconv will be equal 1, wsp_N equals 5001.4934, wsp_E wont be event touched! It is because sscanf eats 1 char too much. This occurs only in situation where pattern %9s will terminate on max string length (9 here), no on whitespace. Then will eat ',' character above, before N from. If we remove ',' from pattern, the second %s will match, and nrconv will be equal 2. And so on.
There is a fix, which works for me:
jxa@amiga:~/work/avrlibc/avr-libc-1.4.5/libc/stdio$ diff vfscanf.c vfscanf.c.org
290,291d289
<
< ungetc(i,stream); /* we eat too much */
jxa@amiga:~/work/avrlibc/avr-libc-1.4.5/libc/stdio$
Regards,
Jerzy
|