| ... | @@ -382,6 +382,9 @@ pub fn zeroes(comptime T: type) T { | ... | @@ -382,6 +382,9 @@ pub fn zeroes(comptime T: type) T { |
| 382 | } | 382 | } |
| 383 | }, | 383 | }, |
| 384 | .Array => |info| { | 384 | .Array => |info| { |
| | 385 | if (info.sentinel) |sentinel| { |
| | 386 | return [_:sentinel]info.child{zeroes(info.child)} ** info.len; |
| | 387 | } |
| 385 | return [_]info.child{zeroes(info.child)} ** info.len; | 388 | return [_]info.child{zeroes(info.child)} ** info.len; |
| 386 | }, | 389 | }, |
| 387 | .Vector, | 390 | .Vector, |
| ... | @@ -442,6 +445,7 @@ test "mem.zeroes" { | ... | @@ -442,6 +445,7 @@ test "mem.zeroes" { |
| 442 | array: [2]u32, | 445 | array: [2]u32, |
| 443 | optional_int: ?u8, | 446 | optional_int: ?u8, |
| 444 | empty: void, | 447 | empty: void, |
| | 448 | sentinel: [3:0]u8, |
| 445 | }; | 449 | }; |
| 446 | | 450 | |
| 447 | const b = zeroes(ZigStruct); | 451 | const b = zeroes(ZigStruct); |
| ... | @@ -466,6 +470,9 @@ test "mem.zeroes" { | ... | @@ -466,6 +470,9 @@ test "mem.zeroes" { |
| 466 | testing.expectEqual(@as(u32, 0), e); | 470 | testing.expectEqual(@as(u32, 0), e); |
| 467 | } | 471 | } |
| 468 | testing.expectEqual(@as(?u8, null), b.optional_int); | 472 | testing.expectEqual(@as(?u8, null), b.optional_int); |
| | 473 | for (b.sentinel) |e| { |
| | 474 | testing.expectEqual(@as(u8, 0), e); |
| | 475 | } |
| 469 | } | 476 | } |
| 470 | | 477 | |
| 471 | pub fn secureZero(comptime T: type, s: []T) void { | 478 | pub fn secureZero(comptime T: type, s: []T) void { |