mirror of
https://github.com/ziglang/zig.git
synced 2025-12-15 18:53:07 +00:00
Merge pull request #4892 from Sobeston/patch-4
mem.zeroes - add sentinel terminated array support
This commit is contained in:
commit
453df1cc1e
@ -382,6 +382,9 @@ pub fn zeroes(comptime T: type) T {
|
||||
}
|
||||
},
|
||||
.Array => |info| {
|
||||
if (info.sentinel) |sentinel| {
|
||||
return [_:sentinel]info.child{zeroes(info.child)} ** info.len;
|
||||
}
|
||||
return [_]info.child{zeroes(info.child)} ** info.len;
|
||||
},
|
||||
.Vector,
|
||||
@ -442,6 +445,7 @@ test "mem.zeroes" {
|
||||
array: [2]u32,
|
||||
optional_int: ?u8,
|
||||
empty: void,
|
||||
sentinel: [3:0]u8,
|
||||
};
|
||||
|
||||
const b = zeroes(ZigStruct);
|
||||
@ -466,6 +470,9 @@ test "mem.zeroes" {
|
||||
testing.expectEqual(@as(u32, 0), e);
|
||||
}
|
||||
testing.expectEqual(@as(?u8, null), b.optional_int);
|
||||
for (b.sentinel) |e| {
|
||||
testing.expectEqual(@as(u8, 0), e);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn secureZero(comptime T: type, s: []T) void {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user