diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-09-28 17:16:12 +0200 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2020-09-28 17:16:12 +0200 |
| commit | 56b52dd0a357f87627fe96dc99377a397f3bb9a1 (patch) | |
| tree | e5f493a75bf845d7c88c5ebc6fe5025afe366d15 /src/ir.cpp | |
| parent | 8794ce6f79886e5ebbf0476d56917e219b52c561 (diff) | |
| download | zig-56b52dd0a357f87627fe96dc99377a397f3bb9a1.tar.gz zig-56b52dd0a357f87627fe96dc99377a397f3bb9a1.zip | |
stage1: Detect OOB access of vector value
Fixes #5710
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 7d446c82a0..871c6739e6 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -21934,7 +21934,17 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP return ira->codegen->invalid_inst_gen; } safety_check_on = false; + } else if (array_type->id == ZigTypeIdVector) { + uint64_t vector_len = array_type->data.vector.len; + if (index >= vector_len) { + ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, + buf_sprintf("index %" ZIG_PRI_u64 " outside vector of size %" ZIG_PRI_u64, + index, vector_len)); + return ira->codegen->invalid_inst_gen; + } + safety_check_on = false; } + if (array_type->id == ZigTypeIdVector) { ZigType *elem_type = array_type->data.vector.elem_type; uint32_t host_vec_len = array_type->data.vector.len; |
