diff --git a/stew/byteutils.nim b/stew/byteutils.nim index 9018c8b..56b45c0 100644 --- a/stew/byteutils.nim +++ b/stew/byteutils.nim @@ -1,5 +1,5 @@ # byteutils -# Copyright (c) 2018 Status Research & Development GmbH +# Copyright (c) 2018-2022 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0). @@ -29,7 +29,7 @@ proc readHexChar*(c: char): byte of 'a'..'f': result = byte(ord(c) - ord('a') + 10) of 'A'..'F': result = byte(ord(c) - ord('A') + 10) else: - raise newException(ValueError, $c & " is not a hexademical character") + raise newException(ValueError, $c & " is not a hexadecimal character") template skip0xPrefix(hexStr: string): int = ## Returns the index of the first meaningful char in `hexStr` by skipping diff --git a/stew/ptrops.nim b/stew/ptrops.nim index 5956556..2a0159d 100644 --- a/stew/ptrops.nim +++ b/stew/ptrops.nim @@ -34,14 +34,8 @@ template offset*[T](p: ptr T, count: int): ptr T = # Actual behavior is wrapping, but this may be revised in the future to enable # better optimizations. - - # We turn off checking here - too large counts is UB - {.push checks: off.} - let - bytes = count * sizeof(T) - res = cast[ptr T](offset(cast[pointer](p), bytes)) - {.pop.} - res + let bytes = count * sizeof(T) + cast[ptr T](offset(cast[pointer](p), bytes)) template distance*(a, b: pointer): int = ## Number of bytes between a and b - undefined behavior when difference @@ -53,7 +47,4 @@ template distance*(a, b: pointer): int = template distance*[T](a, b: ptr T): int = # Number of elements between a and b - undefined behavior when difference # exceeds what can be represented in an int - {.push checks: off.} - let res = distance(cast[pointer](a), cast[pointer](b)) div sizeof(T) - {.pop.} - res + distance(cast[pointer](a), cast[pointer](b)) div sizeof(T)