mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 08:33:06 +00:00
stage1: Fix seg-fault when slicing string literal with sentinel
This commit is contained in:
parent
75c33ba85e
commit
cbc85f4516
@ -21575,6 +21575,7 @@ done_with_return_type:
|
||||
// handle `[N]T`
|
||||
target_len = target->type->data.array.len;
|
||||
target_sentinel = target->type->data.array.sentinel;
|
||||
expand_undef_array(ira->codegen, target);
|
||||
target_elements = target->data.x_array.data.s_none.elements;
|
||||
break;
|
||||
} else if (target->type->id == ZigTypeIdPointer && target->type->data.pointer.child_type->id == ZigTypeIdArray) {
|
||||
|
@ -83,6 +83,7 @@ test {
|
||||
_ = @import("behavior/bugs/11181.zig");
|
||||
_ = @import("behavior/bugs/11213.zig");
|
||||
_ = @import("behavior/bugs/12003.zig");
|
||||
_ = @import("behavior/bugs/12033.zig");
|
||||
_ = @import("behavior/byteswap.zig");
|
||||
_ = @import("behavior/byval_arg_var.zig");
|
||||
_ = @import("behavior/call.zig");
|
||||
|
12
test/behavior/bugs/12033.zig
Normal file
12
test/behavior/bugs/12033.zig
Normal file
@ -0,0 +1,12 @@
|
||||
const std = @import("std");
|
||||
|
||||
test {
|
||||
const string = "Hello!\x00World!";
|
||||
try std.testing.expect(@TypeOf(string) == *const [13:0]u8);
|
||||
|
||||
const slice_without_sentinel: []const u8 = string[0..6];
|
||||
try std.testing.expect(@TypeOf(slice_without_sentinel) == []const u8);
|
||||
|
||||
const slice_with_sentinel: [:0]const u8 = string[0..6 :0];
|
||||
try std.testing.expect(@TypeOf(slice_with_sentinel) == [:0]const u8);
|
||||
}
|
Loading…
Reference in New Issue
Block a user