diff options
Diffstat (limited to 'src/lj_strscan.c')
-rw-r--r-- | src/lj_strscan.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/lj_strscan.c b/src/lj_strscan.c index 948c84a7..433b33a3 100644 --- a/src/lj_strscan.c +++ b/src/lj_strscan.c | |||
@@ -370,9 +370,11 @@ static StrScanFmt strscan_bin(const uint8_t *p, TValue *o, | |||
370 | } | 370 | } |
371 | 371 | ||
372 | /* Scan string containing a number. Returns format. Returns value in o. */ | 372 | /* Scan string containing a number. Returns format. Returns value in o. */ |
373 | StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) | 373 | StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, |
374 | uint32_t opt) | ||
374 | { | 375 | { |
375 | int32_t neg = 0; | 376 | int32_t neg = 0; |
377 | const uint8_t *pe = p + len; | ||
376 | 378 | ||
377 | /* Remove leading space, parse sign and non-numbers. */ | 379 | /* Remove leading space, parse sign and non-numbers. */ |
378 | if (LJ_UNLIKELY(!lj_char_isdigit(*p))) { | 380 | if (LJ_UNLIKELY(!lj_char_isdigit(*p))) { |
@@ -390,7 +392,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) | |||
390 | p += 3; | 392 | p += 3; |
391 | } | 393 | } |
392 | while (lj_char_isspace(*p)) p++; | 394 | while (lj_char_isspace(*p)) p++; |
393 | if (*p) return STRSCAN_ERROR; | 395 | if (*p || p < pe) return STRSCAN_ERROR; |
394 | o->u64 = tmp.u64; | 396 | o->u64 = tmp.u64; |
395 | return STRSCAN_NUM; | 397 | return STRSCAN_NUM; |
396 | } | 398 | } |
@@ -488,6 +490,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) | |||
488 | while (lj_char_isspace(*p)) p++; | 490 | while (lj_char_isspace(*p)) p++; |
489 | if (*p) return STRSCAN_ERROR; | 491 | if (*p) return STRSCAN_ERROR; |
490 | } | 492 | } |
493 | if (p < pe) return STRSCAN_ERROR; | ||
491 | 494 | ||
492 | /* Fast path for decimal 32 bit integers. */ | 495 | /* Fast path for decimal 32 bit integers. */ |
493 | if (fmt == STRSCAN_INT && base == 10 && | 496 | if (fmt == STRSCAN_INT && base == 10 && |
@@ -523,7 +526,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) | |||
523 | 526 | ||
524 | int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o) | 527 | int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o) |
525 | { | 528 | { |
526 | StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o, | 529 | StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), str->len, o, |
527 | STRSCAN_OPT_TONUM); | 530 | STRSCAN_OPT_TONUM); |
528 | lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM); | 531 | lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM); |
529 | return (fmt != STRSCAN_ERROR); | 532 | return (fmt != STRSCAN_ERROR); |
@@ -532,7 +535,7 @@ int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o) | |||
532 | #if LJ_DUALNUM | 535 | #if LJ_DUALNUM |
533 | int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o) | 536 | int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o) |
534 | { | 537 | { |
535 | StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o, | 538 | StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), str->len, o, |
536 | STRSCAN_OPT_TOINT); | 539 | STRSCAN_OPT_TOINT); |
537 | lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM || fmt == STRSCAN_INT); | 540 | lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM || fmt == STRSCAN_INT); |
538 | if (fmt == STRSCAN_INT) setitype(o, LJ_TISNUM); | 541 | if (fmt == STRSCAN_INT) setitype(o, LJ_TISNUM); |