From ba92c53624689272a650b176c8a27e47dd495a2d Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Thu, 2 Feb 2023 09:30:14 +0100 Subject: [PATCH] Fix potential overflow error on toPC (#1458) One might want to rework that toPC code to avoid this oddities. Consider this a quick fix. --- nimbus/utils/prettify.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nimbus/utils/prettify.nim b/nimbus/utils/prettify.nim index 57be4e8d2..48c16f967 100644 --- a/nimbus/utils/prettify.nim +++ b/nimbus/utils/prettify.nim @@ -62,8 +62,13 @@ proc toPC*( let sign = if num < 0: "-" else: "" preTruncated = (num.abs * multiplier) + roundUp + if int.high.float <= preTruncated: return "NaN" + # `intToStr` will do `abs` which throws overflow exception when value of low() + if preTruncated.int <= int.low(): + return "NaN" + result = sign & preTruncated.int.intToStr(minDigits) & "%" when 0 < digitsAfterDot: result.insert(".", result.len - minDigits)