mirror of https://github.com/status-im/NimYAML.git
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.
This commit is contained in:
parent
9a445c18bb
commit
253a4623e4
|
@ -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'}:
|
elif item.scalarContent[0] == '0' and item.scalarContent.len > 1 and item.scalarContent[1] in {'o', 'O'}:
|
||||||
result = parseOctal[T](s, item.scalarContent)
|
result = parseOctal[T](s, item.scalarContent)
|
||||||
else:
|
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,
|
proc constructObject*(s: var YamlStream, c: ConstructionContext,
|
||||||
result: var int)
|
result: var int)
|
||||||
|
|
Loading…
Reference in New Issue