bugAVR C Runtime Library - Bugs: bug #19079, sscanf %s eats 1 char too much

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #19079: sscanf %s eats 1 char too much

Submitter:  None
Submitted:  Sun 18 Feb 2007 03:13:51 PM UTC
   
 
Category:  Library Severity:  4 - Important
Priority:  9 - Immediate Item Group:  libc code
Status:  Fixed Assigned to:  dmix
Percent Complete:  100% Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  None
Fixed Release:  None

Sat 23 Feb 2008 10:31:57 AM UTC, comment #5: 

Fixed in CVS 1_6 branch also.

Dmitry Xmelkov <dmix>
Group administrator
Mon 18 Feb 2008 10:20:27 AM UTC, comment #4: 

Fixed in CVS HEAD.

Dmitry Xmelkov <dmix>
Group administrator
Thu 20 Dec 2007 05:22:12 PM UTC, comment #3: 

Frederic,

Will you be committing the fix for this bug?

Thanks,
Eric Weddington

Eric Weddington <arcanum>
Group administrator
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)

Frédéric Nadeau <fnadeau>
Mon 22 Oct 2007 12:21:49 AM UTC, comment #1: 

Bug #21382 is marked as a duplicate of this bug.

Eric Weddington <arcanum>
Group administrator
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

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #14213:  19079_patch.txt added by fnadeau (1KiB - text/plain - Patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dmix (Posted a comment)
  • -email is unavailable- added by fnadeau (Updated the item)
  • -email is unavailable- added by joerg_wunsch (Updated the item)
  • -email is unavailable- added by arcanum (Updated the item)
  •  

    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2008-03-08 arcanum Assigned tofnadeau dmix
        Open/ClosedOpen Closed
    2008-02-23 dmix StatusReady For Test Fixed
        Percent Complete50% 100%
    2008-02-18 dmix StatusNone Ready For Test
        Percent Complete0% 50%
    2007-10-29 arcanum Assigned toNone fnadeau
    2007-10-26 fnadeau Attached File- Added 19079_patch.txt, #14213
    2007-10-22 joerg_wunsch PrivacyPrivate Public
    2007-10-22 arcanum Severity3 - Normal 4 - Important
    2007-03-25 arcanum Priority5 - Normal 9 - Immediate

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code