diff options
author | flywind <xzsflywind@gmail.com> | 2021-08-16 21:14:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-16 15:14:35 +0200 |
commit | 901c5ded527bb06c52bfc1fd38c9a5fadee0f49a (patch) | |
tree | 30cad98f100bb175dc2e497380ff986e53f84985 /lib | |
parent | 1acba63cb725a0eee8f8b02f585057e030ce6295 (diff) | |
download | Nim-901c5ded527bb06c52bfc1fd38c9a5fadee0f49a.tar.gz |
fix #18702(fix `parseutils.parseFloat`) (#18703) [backport:1.0]
* fix #18702 * Apply suggestions from code review
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system/strmantle.nim | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim index 81ac5c751..f55168c01 100644 --- a/lib/system/strmantle.nim +++ b/lib/system/strmantle.nim @@ -211,15 +211,16 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, var ti = 0 let maxlen = t.high - "e+000".len # reserve enough space for exponent - result = i - start + let endPos = i + result = endPos - start i = start # re-parse without error checking, any error should be handled by the code above. - if i < s.len and s[i] == '.': i.inc - while i < s.len and s[i] in {'0'..'9','+','-'}: + if i < endPos and s[i] == '.': i.inc + while i < endPos and s[i] in {'0'..'9','+','-'}: if ti < maxlen: t[ti] = s[i]; inc(ti) inc(i) - while i < s.len and s[i] in {'.', '_'}: # skip underscore and decimal point + while i < endPos and s[i] in {'.', '_'}: # skip underscore and decimal point inc(i) # insert exponent |