aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorInKryption <inkryption07@gmail.com>2023-03-16 01:02:10 +0100
committerVeikka Tuominen <git@vexu.eu>2023-03-16 13:00:36 +0200
commit9964f1c160acd0bf994708333cd69bc070d6c77e (patch)
tree95038ad8fe5011ad7df08a567e8c3bc545c3532e /src
parente1e414e62a86cc460ef215ea8050c953b68b6080 (diff)
downloadzig-9964f1c160acd0bf994708333cd69bc070d6c77e.tar.gz
zig-9964f1c160acd0bf994708333cd69bc070d6c77e.zip
Add error for bad cast from `*T` to `*[n]T`
Casting `*T` to `*[1]T` should still work, but every other length will now be a compiler error instead of a potential OOB access.
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index fc39fbb9fc..8b476d4542 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -24853,6 +24853,7 @@ fn coerceExtra(
const array_ty = dest_info.pointee_type;
if (array_ty.zigTypeTag() != .Array) break :single_item;
const array_elem_ty = array_ty.childType();
+ if (array_ty.arrayLen() != 1) break :single_item;
const dest_is_mut = dest_info.mutable;
switch (try sema.coerceInMemoryAllowed(block, array_elem_ty, ptr_elem_ty, dest_is_mut, target, dest_ty_src, inst_src)) {
.ok => {},