uint arithmetic for pointers (#22159)

pointers are not signed and arithmetic may correctly cross int.max
threshold

this PR only fixes 2 occurances - there are plenty however in the std
lib

(cherry picked from commit cb40f11e6c)
This commit is contained in:
Jacek Sieka
2023-06-27 08:20:02 +02:00
committed by narimiran
parent 5e4648232b
commit b0cee7c0c5
2 changed files with 2 additions and 2 deletions

View File

@@ -992,7 +992,7 @@ template instantiateForRegion(allocator: untyped) {.dirty.} =
proc realloc0Impl(p: pointer, oldSize, newSize: Natural): pointer =
result = realloc(allocator, p, newSize)
if newSize > oldSize:
zeroMem(cast[pointer](cast[int](result) + oldSize), newSize - oldSize)
zeroMem(cast[pointer](cast[uint](result) + uint(oldSize)), newSize - oldSize)
when false:
proc countFreeMem(): int =

View File

@@ -22,7 +22,7 @@ proc reallocImpl(p: pointer, newSize: Natural): pointer =
proc realloc0Impl(p: pointer, oldsize, newSize: Natural): pointer =
result = realloc(p, newSize.csize_t)
if newSize > oldSize:
zeroMem(cast[pointer](cast[int](result) + oldSize), newSize - oldSize)
zeroMem(cast[pointer](cast[uint](result) + uint(oldSize)), newSize - oldSize)
proc deallocImpl(p: pointer) =
c_free(p)