diff options
| author | xackus <14938807+xackus@users.noreply.github.com> | 2020-04-23 03:06:41 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-04-23 12:45:32 -0400 |
| commit | a9eb4a6740e0bb00e1984de3768a7de6001c25dd (patch) | |
| tree | 5677ec8acfae34ec61eb74d775dc4289193c3224 /src/ir.cpp | |
| parent | e6428f94013132b6a6284b053afb36d35af63c59 (diff) | |
| download | zig-a9eb4a6740e0bb00e1984de3768a7de6001c25dd.tar.gz zig-a9eb4a6740e0bb00e1984de3768a7de6001c25dd.zip | |
stage1: fix crash on accessing an array of size zero with runtime index
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 00bd83f95e..5c8d8157d2 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -21199,6 +21199,11 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP } if (array_type->id == ZigTypeIdArray) { + if(array_type->data.array.len == 0 && array_type->data.array.sentinel == nullptr){ + ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf("accessing a zero length array is not allowed")); + return ira->codegen->invalid_inst_gen; + } + ZigType *child_type = array_type->data.array.child_type; if (ptr_type->data.pointer.host_int_bytes == 0) { return_type = get_pointer_to_type_extra(ira->codegen, child_type, |
