summary refs log tree commit diff stats
path: root/tests/arc
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2024-07-10 23:25:34 +0800
committerGitHub <noreply@github.com>2024-07-10 17:25:34 +0200
commite53a2ed19bf452c2f5db7b691c403a43a26fd5c3 (patch)
treec127483ac8aa25fa8adf7b564bb3adaef51e2cd0 /tests/arc
parent5c5e7a9b6e9ed0c860030f798d4a7096b51b6bda (diff)
downloadNim-e53a2ed19bf452c2f5db7b691c403a43a26fd5c3.tar.gz
fixes #20865; fixes #20987; Missing bounds check in array slicing (#23814)
fixes #20865
fixes #20987
Diffstat (limited to 'tests/arc')
-rw-r--r--tests/arc/topenarray.nim16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/arc/topenarray.nim b/tests/arc/topenarray.nim
index 67c512e4f..ba91666ba 100644
--- a/tests/arc/topenarray.nim
+++ b/tests/arc/topenarray.nim
@@ -68,3 +68,19 @@ block:
   doAssert foo(noBugConst) == expected
   let noBugSeq = @["0", "c", "a"]
   doAssert foo(noBugSeq) == expected
+
+block: # bug #20865
+  var p: pointer
+  var x: array[0, int]
+  # echo toOpenArray(x, 0, 1)[0] # Raises IndexDefect
+  doAssertRaises(IndexDefect):
+    echo toOpenArray(cast[ptr array[0, int]](p)[], 0, 1)[0] # Does not raise IndexDefect
+
+block: # bug #20987
+  var v: array[1, byte]
+
+  var p = cast[ptr array[0, byte]](addr v)
+
+  doAssertRaises(IndexDefect):
+    echo toOpenArray(p[], 1, 2)
+