authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-08 22:37:27+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-05-08 22:37:27+03:00
log453df1cc1e362005e5f302d151447dc062cce02f
treeed5b0d7e697cab98fac8389a30ec395d80d3d320
parentf2d326607505f1f16d4964a824444aaa0da2c259
parent336ddb5b7656367d074ab7d8a6899321a041452c
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4892 from Sobeston/patch-4

mem.zeroes - add sentinel terminated array support

1 files changed, 7 insertions(+), 0 deletions(-)

lib/std/mem.zig+7
......@@ -382,6 +382,9 @@ pub fn zeroes(comptime T: type) T {
382382 }
383383 },
384384 .Array => |info| {
385 if (info.sentinel) |sentinel| {
386 return [_:sentinel]info.child{zeroes(info.child)} ** info.len;
387 }
385388 return [_]info.child{zeroes(info.child)} ** info.len;
386389 },
387390 .Vector,
......@@ -442,6 +445,7 @@ test "mem.zeroes" {
442445 array: [2]u32,
443446 optional_int: ?u8,
444447 empty: void,
448 sentinel: [3:0]u8,
445449 };
446450
447451 const b = zeroes(ZigStruct);
......@@ -466,6 +470,9 @@ test "mem.zeroes" {
466470 testing.expectEqual(@as(u32, 0), e);
467471 }
468472 testing.expectEqual(@as(?u8, null), b.optional_int);
473 for (b.sentinel) |e| {
474 testing.expectEqual(@as(u8, 0), e);
475 }
469476}
470477
471478pub fn secureZero(comptime T: type, s: []T) void {