offset() wraparound

This commit is contained in:
Dustin Brody 2022-03-16 19:40:25 +00:00
parent bb73567168
commit 057cceeb40
No known key found for this signature in database
GPG Key ID: 3D7A11A0156519DC
1 changed files with 2 additions and 2 deletions

View File

@ -34,8 +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.
let bytes = count * sizeof(T)
cast[ptr T](offset(cast[pointer](p), bytes))
let bytes = cast[uint](count) * uint(sizeof(T))
cast[ptr T](offset(cast[pointer](p), cast[int](bytes)))
template distance*(a, b: pointer): int =
## Number of bytes between a and b - undefined behavior when difference