Menu

#90 bad floating-point constant exponents should cause a warning

open-works-for-me
nobody
None
1
2004-02-15
2003-05-16
Anonymous
No

Apparently flconvert() in float.c uses atoi() to
convert the portion of a floating-point constant that
follows the 'E' or 'e' character into a number that
represents the exponent. Since atoi() will silently
stop whenever it encounters characters other than
leading whitespaces or decimal digits, bad exponents
don't cause NASM to emit a warning.

For example:

dd 1.0E12
dd 1.0E12a3

dq 1.0E12
dq 1.0E12a3

dt 1.0E12
dt 1.0E12a3

Silently ignoring everything starting with the 'a' is
not a good thing. Instead NASM should warn.

I ran accross this while looking at allowing
underscores inside integer and floating-point
constants. See the thread in the expert forum for more
details.

Discussion

  • Nobody/Anonymous

    Logged In: NO

    The following change seems to fix the problem.

    old code:

    if (*string) {
    string++; /* eat the E */
    tenpwr += atoi(string);
    }

    new code:

    if (*string) {
    int i = 0;
    int neg = FALSE;

    string++; /* eat the E */
    if (*string == '+') {
    string++;
    } else if (*string == '-') {
    neg = TRUE;
    string++;
    }
    while (*string) {
    if (*string >= '0' && *string <= '9') {
    i = (i * 10) + (*string - '0');
    } else {
    error (ERR_NONFATAL,
    "floating-point constant: `%c' is invalid
    character",
    *string);
    /*
    * For compatibility with earlier versions that
    * used atoi(), we use break instead of return.
    */
    break;
    }
    string++;
    }
    if ( neg ) {
    i = 0 - i;
    }
    tenpwr += i;
    }

     
  • Nobody/Anonymous

    Logged In: NO

    In light of SourceForge bug #740021, the newly proposed
    exponent parsing code should be enhanced as follows:

    if (*string >= '0' && *string <= '9') {
    i = (i * 10) + (*string - '0');
    + if ( i > 5000 ) {
    + break;
    + }
    } else {

    Two birds with one stone! :)

     
  • nasm64developer

    nasm64developer - 2004-02-15
    • priority: 5 --> 1
    • status: open --> open-works-for-me
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.