Detect UInt/ULong parsing overflow after digit addition instead of before

#KT-26161
This commit is contained in:
Ilya Gorbunov
2018-08-21 22:45:17 +03:00
parent d99f97ad96
commit f5df53b7a7
@@ -207,9 +207,9 @@ public fun String.toUIntOrNull(radix: Int): UInt? {
result *= uradix
if (result > limit - digit.toUInt()) return null
val beforeAdding = result
result += digit.toUInt()
if (result < beforeAdding) return null // overflow has happened
}
return result
@@ -260,9 +260,9 @@ public fun String.toULongOrNull(radix: Int): ULong? {
result *= uradix
if (result > limit - digit.toUInt()) return null
val beforeAdding = result
result += digit.toUInt()
if (result < beforeAdding) return null // overflow has happened
}
return result