Skip to content

Commit a031324

Browse files
author
Felix "xq" Queißner
committed
Fixes bug in makeMutableSlice for empty slices.
1 parent c51627a commit a031324

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

s2s.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,12 @@ fn recursiveDeserialize(stream: anytype, comptime T: type, allocator: ?std.mem.A
330330
}
331331

332332
fn makeMutableSlice(comptime T: type, slice: []const T) []T {
333-
return @intToPtr([*]T, @ptrToInt(slice.ptr))[0..slice.len];
333+
if (slice.len == 0) {
334+
var buf: [0]T = .{};
335+
return &buf;
336+
} else {
337+
return @intToPtr([*]T, @ptrToInt(slice.ptr))[0..slice.len];
338+
}
334339
}
335340

336341
fn makeMutablePtr(comptime T: type, ptr: *const T) *T {

0 commit comments

Comments
 (0)