mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 23:54:19 +00:00
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:
@@ -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 =
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user