authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-08 19:02:15+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-08 19:03:27+03:00
log336ddb5b7656367d074ab7d8a6899321a041452c
treeebf575313f251d7e4d60f6b3c5ffc3f8e2ebd30f
parent92a423739d91bd0677940fc1a86b593649cafaa6
signaturelock-open Commit is signed but in an unrecognized format.

std: add test for mem.zeroes on sentinel terminated arrays


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

lib/std/mem.zig+7-3
...@@ -341,8 +341,8 @@ pub fn zeroes(comptime T: type) T {...@@ -341,8 +341,8 @@ pub fn zeroes(comptime T: type) T {
341 }341 }
342 },342 },
343 .Array => |info| {343 .Array => |info| {
344 if (info.sentinel) |sentinel| { 344 if (info.sentinel) |sentinel| {
345 return [_:info.sentinel]info.child{zeroes(info.child)} ** info.len; 345 return [_:sentinel]info.child{zeroes(info.child)} ** info.len;
346 }346 }
347 return [_]info.child{zeroes(info.child)} ** info.len;347 return [_]info.child{zeroes(info.child)} ** info.len;
348 },348 },
...@@ -407,6 +407,7 @@ test "mem.zeroes" {...@@ -407,6 +407,7 @@ test "mem.zeroes" {
407 array: [2]u32,407 array: [2]u32,
408 optional_int: ?u8,408 optional_int: ?u8,
409 empty: void,409 empty: void,
410 sentinel: [3:0]u8,
410 };411 };
411412
412 const b = zeroes(ZigStruct);413 const b = zeroes(ZigStruct);
...@@ -431,6 +432,9 @@ test "mem.zeroes" {...@@ -431,6 +432,9 @@ test "mem.zeroes" {
431 testing.expectEqual(@as(u32, 0), e);432 testing.expectEqual(@as(u32, 0), e);
432 }433 }
433 testing.expectEqual(@as(?u8, null), b.optional_int);434 testing.expectEqual(@as(?u8, null), b.optional_int);
435 for (b.sentinel) |e| {
436 testing.expectEqual(@as(u8, 0), e);
437 }
434}438}
435439
436pub fn secureZero(comptime T: type, s: []T) void {440pub fn secureZero(comptime T: type, s: []T) void {
...@@ -504,7 +508,7 @@ pub const toSlice = @compileError("deprecated; use std.mem.spanZ");...@@ -504,7 +508,7 @@ pub const toSlice = @compileError("deprecated; use std.mem.spanZ");
504/// the constness of the input type. `[*c]` pointers are assumed to be 0-terminated,508/// the constness of the input type. `[*c]` pointers are assumed to be 0-terminated,
505/// and assumed to not allow null.509/// and assumed to not allow null.
506pub fn Span(comptime T: type) type {510pub fn Span(comptime T: type) type {
507 switch(@typeInfo(T)) {511 switch (@typeInfo(T)) {
508 .Optional => |optional_info| {512 .Optional => |optional_info| {
509 return ?Span(optional_info.child);513 return ?Span(optional_info.child);
510 },514 },