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

 
 

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

Submitted by:  None
Submitted on:  Sun 18 Feb 2007 03:13:51 PM UTC  
 
Category: LibrarySeverity: 4 - Important
Priority: 9 - ImmediateItem Group: libc code
Status: FixedPercent Complete: 100%
Assigned to: Dmitry Xmelkov <dmix>Originator Email: -unavailable-
Open/Closed: ClosedRelease: None
Fixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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

Fixed in CVS 1_6 branch also.

Dmitry Xmelkov <dmix>
Project AdministratorIn charge of this item.
Mon 18 Feb 2008 10:20:27 AM UTC, comment #4:

Fixed in CVS HEAD.

Dmitry Xmelkov <dmix>
Project AdministratorIn charge of this item.
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>
Project 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>
Project 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.)

Attach File(s):
   
   
Comment:
   

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
  • -unavailable- added by dmix (Posted a comment)
  • -unavailable- added by fnadeau (Updated the item)
  • -unavailable- added by joerg_wunsch (Updated the item)
  • -unavailable- added by arcanum (Updated the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 11 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 08 Mar 2008 02:19:24 PM UTCarcanumAssigned tofnadeau=>dmix
      Open/ClosedOpen=>Closed
    Sat 23 Feb 2008 10:31:57 AM UTCdmixStatusReady For Test=>Fixed
      Percent Complete50%=>100%
    Mon 18 Feb 2008 10:20:27 AM UTCdmixStatusNone=>Ready For Test
      Percent Complete0%=>50%
    Mon 29 Oct 2007 03:16:04 AM UTCarcanumAssigned toNone=>fnadeau
    Fri 26 Oct 2007 12:06:25 AM UTCfnadeauAttached File-=>Added 19079_patch.txt, #14213
    Mon 22 Oct 2007 10:35:02 AM UTCjoerg_wunschPrivacyPrivate=>Public
    Mon 22 Oct 2007 12:21:49 AM UTCarcanumSeverity3 - Normal=>4 - Important
    Sun 25 Mar 2007 01:00:02 AM UTCarcanumPriority5 - Normal=>9 - Immediate

    Back to the top


    Powered by Savane 3.1-cleanup1