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.
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;
}
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! :)