mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-11-21 03:14:19 +08:00
Don't confuse suffixed hexadecimal with floating-point
1e30 is a floating-point constant, but 1e30h is not. The scanner won't know that until it sees the "h", so make sure we keep enough state to be able to distinguish "1e30" (a possible hex constant) from "1.e30", "1e+30" or "1.0" (unabiguously floating-point.)
This commit is contained in:
parent
f5f3d70d6d
commit
37d88e4125
23
stdscan.c
23
stdscan.c
@ -118,6 +118,8 @@ int stdscan(void *private_data, struct tokenval *tv)
|
||||
bool rn_error;
|
||||
bool is_hex = false;
|
||||
bool is_float = false;
|
||||
bool has_e = false;
|
||||
bool has_h = false;
|
||||
char c;
|
||||
|
||||
r = stdscan_bufptr++;
|
||||
@ -128,8 +130,17 @@ int stdscan(void *private_data, struct tokenval *tv)
|
||||
for (;;) {
|
||||
c = *stdscan_bufptr++;
|
||||
|
||||
if ((!is_hex && (c == 'e' || c == 'E')) ||
|
||||
(c == 'P' || c == 'p')) {
|
||||
if (!is_hex && (c == 'e' || c == 'E')) {
|
||||
has_e = true;
|
||||
if (*stdscan_bufptr == '+' || *stdscan_bufptr == '-') {
|
||||
/* e can only be followed by +/- if it is either a
|
||||
prefixed hex number or a floating-point number */
|
||||
is_float = true;
|
||||
stdscan_bufptr++;
|
||||
}
|
||||
} else if (c == 'H' || c == 'h') {
|
||||
has_h = true;
|
||||
} else if (c == 'P' || c == 'p') {
|
||||
is_float = true;
|
||||
if (*stdscan_bufptr == '+' || *stdscan_bufptr == '-')
|
||||
stdscan_bufptr++;
|
||||
@ -142,6 +153,11 @@ int stdscan(void *private_data, struct tokenval *tv)
|
||||
}
|
||||
stdscan_bufptr--; /* Point to first character beyond number */
|
||||
|
||||
if (has_e && !has_h) {
|
||||
/* 1e13 is floating-point, but 1e13h is not */
|
||||
is_float = true;
|
||||
}
|
||||
|
||||
if (is_float) {
|
||||
tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r);
|
||||
return tv->t_type = TOKEN_FLOAT;
|
||||
@ -154,7 +170,8 @@ int stdscan(void *private_data, struct tokenval *tv)
|
||||
tv->t_charptr = NULL;
|
||||
return tv->t_type = TOKEN_NUM;
|
||||
}
|
||||
} else if (*stdscan_bufptr == '\'' || *stdscan_bufptr == '"') { /* a char constant */
|
||||
} else if (*stdscan_bufptr == '\'' || *stdscan_bufptr == '"') {
|
||||
/* a char constant */
|
||||
char quote = *stdscan_bufptr++, *r;
|
||||
bool rn_warn;
|
||||
r = tv->t_charptr = stdscan_bufptr;
|
||||
|
@ -1,6 +1,10 @@
|
||||
dd 0x1234_5678
|
||||
dd 305_419_896 ; Same number as above it
|
||||
dd 0x1e16 ; NOT a floating-point number!
|
||||
dd 1e16h ; NOT a floating-point number!
|
||||
dd 1e16_h ; NOT a floating-point number!
|
||||
dd $1e16 ; NOT a floating-point number!
|
||||
dd $1e16 ; NOT a floating-point number!
|
||||
dd 1e16 ; THIS is a floating-point number!
|
||||
dd 1e+16
|
||||
dd 1.e+16
|
||||
|
Loading…
Reference in New Issue
Block a user