diff options
author | Mike Pall <mike> | 2022-01-13 15:38:56 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2022-01-13 15:38:56 +0100 |
commit | 103c29e634d822e0affd7d3ae16a7d8a80c038d3 (patch) | |
tree | 1402116387eb1c33c2ef7a6080e0632f4a9e3697 /src | |
parent | a01602a826c4187432f404f6a5a112f75fe914ff (diff) | |
download | luajit-103c29e634d822e0affd7d3ae16a7d8a80c038d3.tar.gz luajit-103c29e634d822e0affd7d3ae16a7d8a80c038d3.tar.bz2 luajit-103c29e634d822e0affd7d3ae16a7d8a80c038d3.zip |
Fix tonumber("-0") in dual-number mode.
Reported by Sergey Kaplun.
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_strscan.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/lj_strscan.c b/src/lj_strscan.c index ccf74860..d18fab8c 100644 --- a/src/lj_strscan.c +++ b/src/lj_strscan.c | |||
@@ -121,7 +121,8 @@ static StrScanFmt strscan_hex(const uint8_t *p, TValue *o, | |||
121 | /* Format-specific handling. */ | 121 | /* Format-specific handling. */ |
122 | switch (fmt) { | 122 | switch (fmt) { |
123 | case STRSCAN_INT: | 123 | case STRSCAN_INT: |
124 | if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { | 124 | if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg && |
125 | !(x == 0 && neg)) { | ||
125 | o->i = neg ? -(int32_t)x : (int32_t)x; | 126 | o->i = neg ? -(int32_t)x : (int32_t)x; |
126 | return STRSCAN_INT; /* Fast path for 32 bit integers. */ | 127 | return STRSCAN_INT; /* Fast path for 32 bit integers. */ |
127 | } | 128 | } |
@@ -448,6 +449,9 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) | |||
448 | if ((opt & STRSCAN_OPT_TONUM)) { | 449 | if ((opt & STRSCAN_OPT_TONUM)) { |
449 | o->n = neg ? -(double)x : (double)x; | 450 | o->n = neg ? -(double)x : (double)x; |
450 | return STRSCAN_NUM; | 451 | return STRSCAN_NUM; |
452 | } else if (x == 0 && neg) { | ||
453 | o->n = -0.0; | ||
454 | return STRSCAN_NUM; | ||
451 | } else { | 455 | } else { |
452 | o->i = neg ? -(int32_t)x : (int32_t)x; | 456 | o->i = neg ? -(int32_t)x : (int32_t)x; |
453 | return STRSCAN_INT; | 457 | return STRSCAN_INT; |
@@ -463,7 +467,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) | |||
463 | fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig); | 467 | fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig); |
464 | 468 | ||
465 | /* Try to convert number to integer, if requested. */ | 469 | /* Try to convert number to integer, if requested. */ |
466 | if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) { | 470 | if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT) && !tvismzero(o)) { |
467 | double n = o->n; | 471 | double n = o->n; |
468 | int32_t i = lj_num2int(n); | 472 | int32_t i = lj_num2int(n); |
469 | if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; } | 473 | if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; } |