avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] [bugs #10420] sscanf(), If there is a decimal number


From: Joerg Wunsch
Subject: Re: [avr-libc-dev] [bugs #10420] sscanf(), If there is a decimal number followed by the character '_' in the buffer, you can't get the the number.
Date: Sat, 18 Sep 2004 23:33:01 +0200
User-agent: Mutt/1.5.6i

As Theodore A. Roth wrote:

>     378                     if (j > 9)
>     379                         j -= 'a' - '0' - 10;
>     380                     if (j < 0 || j >= base) {

I think I see the logical flaw in this now, too.  I tried to minimize
the code required for this check, but obviously opened a window for
false positives by that.

> I have attached a patch that seems to fix the problem for me. Tested on
> a mega128, using both "<1/dr_2_600" and "<1/dr_2\\600" for buf and the
> respective fmt strings.

Patch looks OK to me except of some whitespace inconsistencies.  You've
been using spaces here, and tabs there to indent the code.

> One other thing. line 379 is hideous. The distribution of the
> subtraction via the '-=' operator makes this code very difficult to read
> and understand what it is doing exactly. This is a case where parens
> should be used:
> 
>   j -= ('a' + '0' + 10);
> 
> is so much more explicit and makes the code easier to understand.

Yeah, blame me on this one. ;-)

-- 
J"org Wunsch                                           Unix support engineer
Wir stellen aus! Auf der SYSTEMS 2004  vom 18.-22. Oktober in München
Halle B 3, Stand 320-206 (Partner-Stand von Sun Microsystems)
Halle B 2, Stand 605 "Die Musterfirma"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]