diff options
Diffstat (limited to 'src/lj_strscan.c')
-rw-r--r-- | src/lj_strscan.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/lj_strscan.c b/src/lj_strscan.c index 1d1c1c74..4ca848ec 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. */ |
@@ -348,18 +348,18 @@ static StrScanFmt strscan_bin(const uint8_t *p, TValue *o, | |||
348 | switch (fmt) { | 348 | switch (fmt) { |
349 | case STRSCAN_INT: | 349 | case STRSCAN_INT: |
350 | if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { | 350 | if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { |
351 | o->i = neg ? -(int32_t)x : (int32_t)x; | 351 | o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; |
352 | return STRSCAN_INT; /* Fast path for 32 bit integers. */ | 352 | return STRSCAN_INT; /* Fast path for 32 bit integers. */ |
353 | } | 353 | } |
354 | if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; } | 354 | if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; } |
355 | /* fallthrough */ | 355 | /* fallthrough */ |
356 | case STRSCAN_U32: | 356 | case STRSCAN_U32: |
357 | if (dig > 32) return STRSCAN_ERROR; | 357 | if (dig > 32) return STRSCAN_ERROR; |
358 | o->i = neg ? -(int32_t)x : (int32_t)x; | 358 | o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; |
359 | return STRSCAN_U32; | 359 | return STRSCAN_U32; |
360 | case STRSCAN_I64: | 360 | case STRSCAN_I64: |
361 | case STRSCAN_U64: | 361 | case STRSCAN_U64: |
362 | o->u64 = neg ? (uint64_t)-(int64_t)x : x; | 362 | o->u64 = neg ? ~x+1u : x; |
363 | return fmt; | 363 | return fmt; |
364 | default: | 364 | default: |
365 | break; | 365 | break; |
@@ -468,7 +468,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, | |||
468 | if (xx >= STRSCAN_MAXEXP) return STRSCAN_ERROR; | 468 | if (xx >= STRSCAN_MAXEXP) return STRSCAN_ERROR; |
469 | p++; | 469 | p++; |
470 | } | 470 | } |
471 | ex += negx ? -(int32_t)xx : (int32_t)xx; | 471 | ex += negx ? (int32_t)(~xx+1u) : (int32_t)xx; |
472 | } | 472 | } |
473 | 473 | ||
474 | /* Parse suffix. */ | 474 | /* Parse suffix. */ |
@@ -507,7 +507,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, | |||
507 | o->n = -0.0; | 507 | o->n = -0.0; |
508 | return STRSCAN_NUM; | 508 | return STRSCAN_NUM; |
509 | } else { | 509 | } else { |
510 | o->i = neg ? -(int32_t)x : (int32_t)x; | 510 | o->i = neg ? (int32_t)(~x+1u) : (int32_t)x; |
511 | return STRSCAN_INT; | 511 | return STRSCAN_INT; |
512 | } | 512 | } |
513 | } | 513 | } |