From 253a4623e4883e59507724911d4619d2399597ed Mon Sep 17 00:00:00 2001 From: Vindaar Date: Wed, 3 Oct 2018 20:00:12 +0200 Subject: [PATCH] circumvent RangeError, which will be wrongly caught Converting an integer via `T(number)` to some integer will cause a range error, if it doesn't fit. Maybe it didn't in the past, which is why the code worked before? Some other error was thrown? With this code anyway it crashed, because it threw an internal error. --- yaml/serialization.nim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/yaml/serialization.nim b/yaml/serialization.nim index e4468a5..2b0e820 100644 --- a/yaml/serialization.nim +++ b/yaml/serialization.nim @@ -199,7 +199,13 @@ proc constructObject*[T: int8|int16|int32|int64]( elif item.scalarContent[0] == '0' and item.scalarContent.len > 1 and item.scalarContent[1] in {'o', 'O'}: result = parseOctal[T](s, item.scalarContent) else: - result = T(parseBiggestInt(item.scalarContent)) + let nInt = parseBiggestInt(item.scalarContent) + if nInt <= T.high: + # make sure we don't produce a range error + result = T(nInt) + else: + # if outside of range, what to do?! + raise newException(YamlConstructionError, "AAA") proc constructObject*(s: var YamlStream, c: ConstructionContext, result: var int)