Bug #1600

CParser::IsNumber can return wrong result

Added by cbpporter cbpporter almost 3 years ago. Updated almost 3 years ago.

Status:ApprovedStart date:01/03/2017
Priority:LowDue date:
Assignee:-% Done:

0%

Category:CoreSpent time:-
Target version:-

Description

CParser::IsNumber takes a base parameter, so I interpreted the function as being designed as "is the contents of the stream in the parser a number using base XXX?".

If this assertion is true, IsNumber(8) on a stream with the contents "9 ..." will return true, which should be false.

Fix:

bool CParser::IsNumber(int base) const
{
    if(IsDigit(*term)) {
        int q = *term - '0';
        return q >= 0 && q < base;
    }
    else {
        int q = ToUpper(*term) - 'A';
        return q >= 0 && q < base - 10;
    }
}

The fix is a bit slower, but I doubt this will have real life impact.

History

#1 Updated by cbpporter cbpporter almost 3 years ago

  • Category set to Core

#2 Updated by Miroslav Fidler almost 3 years ago

  • Status changed from New to Approved

Also available in: Atom PDF