summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorOscar NihlgÄrd <oscarnihlgard@gmail.com>2019-01-18 19:15:29 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-01-18 19:15:29 +0100
commit86a91c1a4a38a669e9ed5409975936f64ad3e532 (patch)
tree4a9e92558b298fbf2309fac72002c2ddbf3d3879 /lib
parent3cc39c2eb90fa391c3da732525db0cdb52d7f958 (diff)
downloadNim-86a91c1a4a38a669e9ed5409975936f64ad3e532.tar.gz
Fix parseutils.parseBiggestInt regression (#10348)
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/parseutils.nim15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/pure/parseutils.nim b/lib/pure/parseutils.nim
index c2d52ebcc..ba09347a2 100644
--- a/lib/pure/parseutils.nim
+++ b/lib/pure/parseutils.nim
@@ -350,6 +350,10 @@ proc captureBetween*(s: string, first: char, second = '\0', start = 0): string =
 proc integerOutOfRangeError() {.noinline.} =
   raise newException(ValueError, "Parsed integer outside of valid range")
 
+# See #6752
+when defined(js):
+  {.push overflowChecks: off.}
+
 proc rawParseInt(s: string, b: var BiggestInt, start = 0): int =
   var
     sign: BiggestInt = -1
@@ -363,18 +367,21 @@ proc rawParseInt(s: string, b: var BiggestInt, start = 0): int =
     b = 0
     while i < s.len and s[i] in {'0'..'9'}:
       let c = ord(s[i]) - ord('0')
-      if b >= (low(int) + c) div 10:
+      if b >= (low(BiggestInt) + c) div 10:
         b = b * 10 - c
       else:
         integerOutOfRangeError()
       inc(i)
       while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
-    if sign == -1 and b == low(int):
+    if sign == -1 and b == low(BiggestInt):
       integerOutOfRangeError()
     else:
       b = b * sign
       result = i - start
 
+when defined(js):
+  {.pop.} # overflowChecks: off
+
 proc parseBiggestInt*(s: string, number: var BiggestInt, start = 0): int {.
   rtl, extern: "npuParseBiggestInt", noSideEffect, raises: [ValueError].} =
   ## Parses an integer starting at `start` and stores the value into `number`.
@@ -632,4 +639,8 @@ when isMainModule:
   doAssert(parseSaturatedNatural("1_000_000", value) == 9)
   doAssert value == 1_000_000
 
+  var i64Value: int64
+  discard parseBiggestInt("9223372036854775807", i64Value)
+  doAssert i64Value == 9223372036854775807
+
 {.pop.}