summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJacek Sieka <arnetheduck@gmail.com>2023-06-27 08:20:02 +0200
committerGitHub <noreply@github.com>2023-06-27 08:20:02 +0200
commitcb40f11e6c0a8f8df8b429f239483c408c7cc668 (patch)
tree40e002134526fd3fabe0c190bca13ff829aeeb9f
parent4b761295e7ab31412903c02b8fb98f580bf005ca (diff)
downloadNim-cb40f11e6c0a8f8df8b429f239483c408c7cc668.tar.gz
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
-rw-r--r--lib/system/alloc.nim2
-rw-r--r--lib/system/mm/malloc.nim2
2 files changed, 2 insertions, 2 deletions
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index ac1741ceb..edb094f33 100644
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -1139,7 +1139,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 =
diff --git a/lib/system/mm/malloc.nim b/lib/system/mm/malloc.nim
index d41dce705..b24b6f1e0 100644
--- a/lib/system/mm/malloc.nim
+++ b/lib/system/mm/malloc.nim
@@ -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)