replace integer cast with conversion (#5160)

This commit is contained in:
tersec 2023-07-04 14:29:26 +00:00 committed by GitHub
parent ad3b2fb5ed
commit 6730e16439
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -1,3 +1,10 @@
# beacon_chain
# Copyright (c) 2021-2023 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.push raises: [].}
import
@ -148,9 +155,8 @@ proc readHeader(f: IoHandle): Result[Header, string] =
typ: Type
discard typ.copyFrom(buf)
# Cast safe because we had only 4 bytes of length data
let
len = cast[int64](uint32.fromBytesLE(buf.toOpenArray(2, 5)))
# Conversion safe because we had only 4 bytes of length data
let len = (uint32.fromBytesLE(buf.toOpenArray(2, 5))).int64
# No point reading these..
if len > int.high(): return err("header length exceeds int.high")