diff options
Diffstat (limited to '')
-rw-r--r-- | src/lj_strscan.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/lj_strscan.c b/src/lj_strscan.c index 914cfb7a..9e8023b5 100644 --- a/src/lj_strscan.c +++ b/src/lj_strscan.c | |||
@@ -124,19 +124,19 @@ static StrScanFmt strscan_hex(const uint8_t *p, TValue *o, | |||
124 | case STRSCAN_INT: | 124 | case STRSCAN_INT: |
125 | if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg && | 125 | if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg && |
126 | !(x == 0 && neg)) { | 126 | !(x == 0 && neg)) { |
127 | o->i = neg ? -(int32_t)x : (int32_t)x; | 127 | o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; |
128 | return STRSCAN_INT; /* Fast path for 32 bit integers. */ | 128 | return STRSCAN_INT; /* Fast path for 32 bit integers. */ |
129 | } | 129 | } |
130 | if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; } | 130 | if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; } |
131 | /* fallthrough */ | 131 | /* fallthrough */ |
132 | case STRSCAN_U32: | 132 | case STRSCAN_U32: |
133 | if (dig > 8) return STRSCAN_ERROR; | 133 | if (dig > 8) return STRSCAN_ERROR; |
134 | o->i = neg ? -(int32_t)x : (int32_t)x; | 134 | o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; |
135 | return STRSCAN_U32; | 135 | return STRSCAN_U32; |
136 | case STRSCAN_I64: | 136 | case STRSCAN_I64: |
137 | case STRSCAN_U64: | 137 | case STRSCAN_U64: |
138 | if (dig > 16) return STRSCAN_ERROR; | 138 | if (dig > 16) return STRSCAN_ERROR; |
139 | o->u64 = neg ? (uint64_t)-(int64_t)x : x; | 139 | o->u64 = neg ? ~x+1u : x; |
140 | return fmt; | 140 | return fmt; |
141 | default: | 141 | default: |
142 | break; | 142 | break; |
@@ -168,12 +168,12 @@ static StrScanFmt strscan_oct(const uint8_t *p, TValue *o, | |||
168 | /* fallthrough */ | 168 | /* fallthrough */ |
169 | case STRSCAN_U32: | 169 | case STRSCAN_U32: |
170 | if ((x >> 32)) return STRSCAN_ERROR; | 170 | if ((x >> 32)) return STRSCAN_ERROR; |
171 | o->i = neg ? -(int32_t)x : (int32_t)x; | 171 | o->i = neg ? (int32_t)(~(uint32_t)x+1u) : (int32_t)x; |
172 | break; | 172 | break; |
173 | default: | 173 | default: |
174 | case STRSCAN_I64: | 174 | case STRSCAN_I64: |
175 | case STRSCAN_U64: | 175 | case STRSCAN_U64: |
176 | o->u64 = neg ? (uint64_t)-(int64_t)x : x; | 176 | o->u64 = neg ? ~x+1u : x; |
177 | break; | 177 | break; |
178 | } | 178 | } |
179 | return fmt; | 179 | return fmt; |
@@ -229,18 +229,18 @@ static StrScanFmt strscan_dec(const uint8_t *p, TValue *o, | |||
229 | switch (fmt) { | 229 | switch (fmt) { |
230 | case STRSCAN_INT: | 230 | case STRSCAN_INT: |
231 | if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { | 231 | if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { |
232 | o->i = neg ? -(int32_t)x : (int32_t)x; | 232 | o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; |
233 | return STRSCAN_INT; /* Fast path for 32 bit integers. */ | 233 | return STRSCAN_INT; /* Fast path for 32 bit integers. */ |
234 | } | 234 | } |
235 | if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; } | 235 | if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; } |
236 | /* fallthrough */ | 236 | /* fallthrough */ |
237 | case STRSCAN_U32: | 237 | case STRSCAN_U32: |
238 | if ((x >> 32) != 0) return STRSCAN_ERROR; | 238 | if ((x >> 32) != 0) return STRSCAN_ERROR; |
239 | o->i = neg ? -(int32_t)x : (int32_t)x; | 239 | o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; |
240 | return STRSCAN_U32; | 240 | return STRSCAN_U32; |
241 | case STRSCAN_I64: | 241 | case STRSCAN_I64: |
242 | case STRSCAN_U64: | 242 | case STRSCAN_U64: |
243 | o->u64 = neg ? (uint64_t)-(int64_t)x : x; | 243 | o->u64 = neg ? ~x+1u : x; |
244 | return fmt; | 244 | return fmt; |
245 | default: | 245 | default: |
246 | plainnumber: /* Fast path for plain numbers < 2^63. */ | 246 | plainnumber: /* Fast path for plain numbers < 2^63. */ |
@@ -418,7 +418,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) | |||
418 | if (xx >= STRSCAN_MAXEXP) return STRSCAN_ERROR; | 418 | if (xx >= STRSCAN_MAXEXP) return STRSCAN_ERROR; |
419 | p++; | 419 | p++; |
420 | } | 420 | } |
421 | ex += negx ? -(int32_t)xx : (int32_t)xx; | 421 | ex += negx ? (int32_t)(~xx+1u) : (int32_t)xx; |
422 | } | 422 | } |
423 | 423 | ||
424 | /* Parse suffix. */ | 424 | /* Parse suffix. */ |
@@ -456,7 +456,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) | |||
456 | o->n = -0.0; | 456 | o->n = -0.0; |
457 | return STRSCAN_NUM; | 457 | return STRSCAN_NUM; |
458 | } else { | 458 | } else { |
459 | o->i = neg ? -(int32_t)x : (int32_t)x; | 459 | o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; |
460 | return STRSCAN_INT; | 460 | return STRSCAN_INT; |
461 | } | 461 | } |
462 | } | 462 | } |