about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-05-21 18:32:36 +0200
committerbptato <nincsnevem662@gmail.com>2024-05-21 18:34:54 +0200
commitda0ef4a8afb0b1a44e4e37bdda0dfa2210f141e4 (patch)
treefc3b8c0f088a8dc540bad2625695263c176f3d4e /src/utils/twtstr.nim
parentf24152ee279e3e2d58da614cf9d1cb11f7e2b3f1 (diff)
downloadchawan-da0ef4a8afb0b1a44e4e37bdda0dfa2210f141e4.tar.gz
twtstr: fix overflow check
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 3cbcfcd3..8171010a 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -230,7 +230,7 @@ func parseIntImpl[T: SomeSignedInt](s: string; allowed: set[char]; radix: T):
     if s[i] notin allowed:
       return none(T) # invalid
     let c = T(hexValue(s[i]))
-    if unlikely(T.high div radix - c < integer):
+    if unlikely((T.high - c) div radix < integer):
       return none(T) # overflow
     integer *= radix
     integer += c
@@ -265,7 +265,7 @@ func parseUIntImpl[T: SomeUnsignedInt](s: string; allowSign: static bool;
     if s[i] notin allowed:
       return none(T) # invalid
     let c = T(hexValue(s[i]))
-    if unlikely(T.high div radix - c < integer):
+    if unlikely((T.high - c) div radix < integer):
       return none(T) # overflow
     integer *= radix
     integer += c