URL:
<http://savannah.nongnu.org/bugs/?19079>
Summary: sscanf %s eats 1 char too much
Project: AVR C Runtime Library
Submitted by: None
Submitted on: Sunday 02/18/2007 at 15:13 UTC
Category: Library
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: libc code
Status: None
Privacy: Private
Percent Complete: 0%
Assigned to: None
Originator Email: [EMAIL PROTECTED]
Open/Closed: Open
Discussion Lock: Any
_______________________________________________________
Details:
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:
[EMAIL PROTECTED]:~/work/avrlibc/avr-libc-1.4.5/libc/stdio$ diff vfscanf.c
vfscanf.c.org
290,291d289
<
< ungetc(i,stream); /* we eat too much
*/
[EMAIL PROTECTED]:~/work/avrlibc/avr-libc-1.4.5/libc/stdio$
Regards,
Jerzy
_______________________________________________________
Reply to this item at:
<http://savannah.nongnu.org/bugs/?19079>
_______________________________________________
Message sent via/by Savannah
http://savannah.nongnu.org/
_______________________________________________
AVR-libc-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-libc-dev