authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-26 13:57:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-28 13:24:43-07:00
log6261c1373168b265047db5704d9d0fd5f2e458f2
tree18d6f31107b2c42ac9c6567b42f577bca41d769b
parent57ea6207d3cb2db706bdc06c14605e4b901736dd

update codebase to use `@memset` and `@memcpy`


121 files changed, 558 insertions(+), 541 deletions(-)

lib/std/Build.zig+2-2
...@@ -1693,10 +1693,10 @@ pub fn constructCMacro(allocator: Allocator, name: []const u8, value: ?[]const u...@@ -1693,10 +1693,10 @@ pub fn constructCMacro(allocator: Allocator, name: []const u8, value: ?[]const u
1693 u8,1693 u8,
1694 name.len + if (value) |value_slice| value_slice.len + 1 else 0,1694 name.len + if (value) |value_slice| value_slice.len + 1 else 0,
1695 ) catch |err| if (err == error.OutOfMemory) @panic("Out of memory") else unreachable;1695 ) catch |err| if (err == error.OutOfMemory) @panic("Out of memory") else unreachable;
1696 mem.copy(u8, macro, name);1696 @memcpy(macro[0..name.len], name);
1697 if (value) |value_slice| {1697 if (value) |value_slice| {
1698 macro[name.len] = '=';1698 macro[name.len] = '=';
1699 mem.copy(u8, macro[name.len + 1 ..], value_slice);1699 @memcpy(macro[name.len + 1 ..][0..value_slice.len], value_slice);
1700 }1700 }
1701 return macro;1701 return macro;
1702}1702}
lib/std/Build/Cache.zig+1-1
...@@ -388,7 +388,7 @@ pub const Manifest = struct {...@@ -388,7 +388,7 @@ pub const Manifest = struct {
388 self.hash.hasher = hasher_init;388 self.hash.hasher = hasher_init;
389 self.hash.hasher.update(&bin_digest);389 self.hash.hasher.update(&bin_digest);
390390
391 mem.copy(u8, &manifest_file_path, &self.hex_digest);391 @memcpy(manifest_file_path[0..self.hex_digest.len], &self.hex_digest);
392 manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*;392 manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*;
393393
394 if (self.files.items.len == 0) {394 if (self.files.items.len == 0) {
lib/std/Build/CompileStep.zig+1-1
...@@ -1139,7 +1139,7 @@ fn appendModuleArgs(...@@ -1139,7 +1139,7 @@ fn appendModuleArgs(
1139 // We'll use this buffer to store the name we decide on1139 // We'll use this buffer to store the name we decide on
1140 var buf = try b.allocator.alloc(u8, dep.name.len + 32);1140 var buf = try b.allocator.alloc(u8, dep.name.len + 32);
1141 // First, try just the exposed dependency name1141 // First, try just the exposed dependency name
1142 std.mem.copy(u8, buf, dep.name);1142 @memcpy(buf[0..dep.name.len], dep.name);
1143 var name = buf[0..dep.name.len];1143 var name = buf[0..dep.name.len];
1144 var n: usize = 0;1144 var n: usize = 0;
1145 while (names.contains(name)) {1145 while (names.contains(name)) {
lib/std/Progress.zig+1-1
...@@ -374,7 +374,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any...@@ -374,7 +374,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any
374 self.columns_written += self.output_buffer.len - end.*;374 self.columns_written += self.output_buffer.len - end.*;
375 end.* = self.output_buffer.len;375 end.* = self.output_buffer.len;
376 const suffix = "... ";376 const suffix = "... ";
377 std.mem.copy(u8, self.output_buffer[self.output_buffer.len - suffix.len ..], suffix);377 @memcpy(self.output_buffer[self.output_buffer.len - suffix.len ..], suffix);
378 },378 },
379 }379 }
380}380}
lib/std/Thread.zig+1-1
...@@ -56,7 +56,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {...@@ -56,7 +56,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
5656
57 const name_with_terminator = blk: {57 const name_with_terminator = blk: {
58 var name_buf: [max_name_len:0]u8 = undefined;58 var name_buf: [max_name_len:0]u8 = undefined;
59 std.mem.copy(u8, &name_buf, name);59 @memcpy(name_buf[0..name.len], name);
60 name_buf[name.len] = 0;60 name_buf[name.len] = 0;
61 break :blk name_buf[0..name.len :0];61 break :blk name_buf[0..name.len :0];
62 };62 };
lib/std/array_hash_map.zig+3-3
...@@ -578,9 +578,9 @@ pub fn ArrayHashMapUnmanaged(...@@ -578,9 +578,9 @@ pub fn ArrayHashMapUnmanaged(
578 self.entries.len = 0;578 self.entries.len = 0;
579 if (self.index_header) |header| {579 if (self.index_header) |header| {
580 switch (header.capacityIndexType()) {580 switch (header.capacityIndexType()) {
581 .u8 => mem.set(Index(u8), header.indexes(u8), Index(u8).empty),581 .u8 => @memset(header.indexes(u8), Index(u8).empty),
582 .u16 => mem.set(Index(u16), header.indexes(u16), Index(u16).empty),582 .u16 => @memset(header.indexes(u16), Index(u16).empty),
583 .u32 => mem.set(Index(u32), header.indexes(u32), Index(u32).empty),583 .u32 => @memset(header.indexes(u32), Index(u32).empty),
584 }584 }
585 }585 }
586 }586 }
lib/std/array_list.zig+12-12
...@@ -120,7 +120,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -120,7 +120,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
120 }120 }
121121
122 const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);122 const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
123 mem.copy(T, new_memory, self.items);123 @memcpy(new_memory, self.items);
124 @memset(self.items, undefined);124 @memset(self.items, undefined);
125 self.clearAndFree();125 self.clearAndFree();
126 return new_memory;126 return new_memory;
...@@ -170,7 +170,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -170,7 +170,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
170 self.items.len += items.len;170 self.items.len += items.len;
171171
172 mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);172 mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);
173 mem.copy(T, self.items[i .. i + items.len], items);173 @memcpy(self.items[i..][0..items.len], items);
174 }174 }
175175
176 /// Replace range of elements `list[start..start+len]` with `new_items`.176 /// Replace range of elements `list[start..start+len]` with `new_items`.
...@@ -182,15 +182,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -182,15 +182,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
182 const range = self.items[start..after_range];182 const range = self.items[start..after_range];
183183
184 if (range.len == new_items.len)184 if (range.len == new_items.len)
185 mem.copy(T, range, new_items)185 @memcpy(range[0..new_items.len], new_items)
186 else if (range.len < new_items.len) {186 else if (range.len < new_items.len) {
187 const first = new_items[0..range.len];187 const first = new_items[0..range.len];
188 const rest = new_items[range.len..];188 const rest = new_items[range.len..];
189189
190 mem.copy(T, range, first);190 @memcpy(range[0..first.len], first);
191 try self.insertSlice(after_range, rest);191 try self.insertSlice(after_range, rest);
192 } else {192 } else {
193 mem.copy(T, range, new_items);193 @memcpy(range[0..new_items.len], new_items);
194 const after_subrange = start + new_items.len;194 const after_subrange = start + new_items.len;
195195
196 for (self.items[after_range..], 0..) |item, i| {196 for (self.items[after_range..], 0..) |item, i| {
...@@ -260,7 +260,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -260,7 +260,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
260 const new_len = old_len + items.len;260 const new_len = old_len + items.len;
261 assert(new_len <= self.capacity);261 assert(new_len <= self.capacity);
262 self.items.len = new_len;262 self.items.len = new_len;
263 mem.copy(T, self.items[old_len..], items);263 @memcpy(self.items[old_len..][0..items.len], items);
264 }264 }
265265
266 /// Append an unaligned slice of items to the list. Allocates more266 /// Append an unaligned slice of items to the list. Allocates more
...@@ -401,7 +401,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -401,7 +401,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
401 self.capacity = new_capacity;401 self.capacity = new_capacity;
402 } else {402 } else {
403 const new_memory = try self.allocator.alignedAlloc(T, alignment, new_capacity);403 const new_memory = try self.allocator.alignedAlloc(T, alignment, new_capacity);
404 mem.copy(T, new_memory, self.items);404 @memcpy(new_memory[0..self.items.len], self.items);
405 self.allocator.free(old_memory);405 self.allocator.free(old_memory);
406 self.items.ptr = new_memory.ptr;406 self.items.ptr = new_memory.ptr;
407 self.capacity = new_memory.len;407 self.capacity = new_memory.len;
...@@ -600,7 +600,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -600,7 +600,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
600 }600 }
601601
602 const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);602 const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
603 mem.copy(T, new_memory, self.items);603 @memcpy(new_memory, self.items);
604 @memset(self.items, undefined);604 @memset(self.items, undefined);
605 self.clearAndFree(allocator);605 self.clearAndFree(allocator);
606 return new_memory;606 return new_memory;
...@@ -651,7 +651,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -651,7 +651,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
651 self.items.len += items.len;651 self.items.len += items.len;
652652
653 mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);653 mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);
654 mem.copy(T, self.items[i .. i + items.len], items);654 @memcpy(self.items[i..][0..items.len], items);
655 }655 }
656656
657 /// Replace range of elements `list[start..start+len]` with `new_items`657 /// Replace range of elements `list[start..start+len]` with `new_items`
...@@ -720,7 +720,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -720,7 +720,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
720 const new_len = old_len + items.len;720 const new_len = old_len + items.len;
721 assert(new_len <= self.capacity);721 assert(new_len <= self.capacity);
722 self.items.len = new_len;722 self.items.len = new_len;
723 mem.copy(T, self.items[old_len..], items);723 @memcpy(self.items[old_len..][0..items.len], items);
724 }724 }
725725
726 /// Append the slice of items to the list. Allocates more726 /// Append the slice of items to the list. Allocates more
...@@ -823,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -823,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
823 },823 },
824 };824 };
825825
826 mem.copy(T, new_memory, self.items[0..new_len]);826 @memcpy(new_memory, self.items[0..new_len]);
827 allocator.free(old_memory);827 allocator.free(old_memory);
828 self.items = new_memory;828 self.items = new_memory;
829 self.capacity = new_memory.len;829 self.capacity = new_memory.len;
...@@ -885,7 +885,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -885,7 +885,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
885 self.capacity = new_capacity;885 self.capacity = new_capacity;
886 } else {886 } else {
887 const new_memory = try allocator.alignedAlloc(T, alignment, new_capacity);887 const new_memory = try allocator.alignedAlloc(T, alignment, new_capacity);
888 mem.copy(T, new_memory, self.items);888 @memcpy(new_memory[0..self.items.len], self.items);
889 allocator.free(old_memory);889 allocator.free(old_memory);
890 self.items.ptr = new_memory.ptr;890 self.items.ptr = new_memory.ptr;
891 self.capacity = new_memory.len;891 self.capacity = new_memory.len;
lib/std/base64.zig+2-2
...@@ -309,11 +309,11 @@ test "base64 padding dest overflow" {...@@ -309,11 +309,11 @@ test "base64 padding dest overflow" {
309 const input = "foo";309 const input = "foo";
310310
311 var expect: [128]u8 = undefined;311 var expect: [128]u8 = undefined;
312 std.mem.set(u8, &expect, 0);312 @memset(&expect, 0);
313 _ = url_safe.Encoder.encode(expect[0..url_safe.Encoder.calcSize(input.len)], input);313 _ = url_safe.Encoder.encode(expect[0..url_safe.Encoder.calcSize(input.len)], input);
314314
315 var got: [128]u8 = undefined;315 var got: [128]u8 = undefined;
316 std.mem.set(u8, &got, 0);316 @memset(&got, 0);
317 _ = url_safe.Encoder.encode(&got, input);317 _ = url_safe.Encoder.encode(&got, input);
318318
319 try std.testing.expectEqualSlices(u8, &expect, &got);319 try std.testing.expectEqualSlices(u8, &expect, &got);
lib/std/bit_set.zig+1-1
...@@ -738,7 +738,7 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -738,7 +738,7 @@ pub const DynamicBitSetUnmanaged = struct {
738 // fill in any new masks738 // fill in any new masks
739 if (new_masks > old_masks) {739 if (new_masks > old_masks) {
740 const fill_value = std.math.boolMask(MaskInt, fill);740 const fill_value = std.math.boolMask(MaskInt, fill);
741 std.mem.set(MaskInt, self.masks[old_masks..new_masks], fill_value);741 @memset(self.masks[old_masks..new_masks], fill_value);
742 }742 }
743 }743 }
744744
lib/std/bounded_array.zig+10-10
...@@ -73,7 +73,7 @@ pub fn BoundedArrayAligned(...@@ -73,7 +73,7 @@ pub fn BoundedArrayAligned(
73 /// Copy the content of an existing slice.73 /// Copy the content of an existing slice.
74 pub fn fromSlice(m: []const T) error{Overflow}!Self {74 pub fn fromSlice(m: []const T) error{Overflow}!Self {
75 var list = try init(m.len);75 var list = try init(m.len);
76 std.mem.copy(T, list.slice(), m);76 @memcpy(list.slice(), m);
77 return list;77 return list;
78 }78 }
7979
...@@ -165,7 +165,7 @@ pub fn BoundedArrayAligned(...@@ -165,7 +165,7 @@ pub fn BoundedArrayAligned(
165 try self.ensureUnusedCapacity(items.len);165 try self.ensureUnusedCapacity(items.len);
166 self.len += items.len;166 self.len += items.len;
167 mem.copyBackwards(T, self.slice()[i + items.len .. self.len], self.constSlice()[i .. self.len - items.len]);167 mem.copyBackwards(T, self.slice()[i + items.len .. self.len], self.constSlice()[i .. self.len - items.len]);
168 mem.copy(T, self.slice()[i .. i + items.len], items);168 @memcpy(self.slice()[i..][0..items.len], items);
169 }169 }
170170
171 /// Replace range of elements `slice[start..start+len]` with `new_items`.171 /// Replace range of elements `slice[start..start+len]` with `new_items`.
...@@ -181,14 +181,14 @@ pub fn BoundedArrayAligned(...@@ -181,14 +181,14 @@ pub fn BoundedArrayAligned(
181 var range = self.slice()[start..after_range];181 var range = self.slice()[start..after_range];
182182
183 if (range.len == new_items.len) {183 if (range.len == new_items.len) {
184 mem.copy(T, range, new_items);184 @memcpy(range[0..new_items.len], new_items);
185 } else if (range.len < new_items.len) {185 } else if (range.len < new_items.len) {
186 const first = new_items[0..range.len];186 const first = new_items[0..range.len];
187 const rest = new_items[range.len..];187 const rest = new_items[range.len..];
188 mem.copy(T, range, first);188 @memcpy(range[0..first.len], first);
189 try self.insertSlice(after_range, rest);189 try self.insertSlice(after_range, rest);
190 } else {190 } else {
191 mem.copy(T, range, new_items);191 @memcpy(range[0..new_items.len], new_items);
192 const after_subrange = start + new_items.len;192 const after_subrange = start + new_items.len;
193 for (self.constSlice()[after_range..], 0..) |item, i| {193 for (self.constSlice()[after_range..], 0..) |item, i| {
194 self.slice()[after_subrange..][i] = item;194 self.slice()[after_subrange..][i] = item;
...@@ -243,9 +243,9 @@ pub fn BoundedArrayAligned(...@@ -243,9 +243,9 @@ pub fn BoundedArrayAligned(
243 /// Append the slice of items to the slice, asserting the capacity is already243 /// Append the slice of items to the slice, asserting the capacity is already
244 /// enough to store the new items.244 /// enough to store the new items.
245 pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {245 pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {
246 const oldlen = self.len;246 const old_len = self.len;
247 self.len += items.len;247 self.len += items.len;
248 mem.copy(T, self.slice()[oldlen..], items);248 @memcpy(self.slice()[old_len..][0..items.len], items);
249 }249 }
250250
251 /// Append a value to the slice `n` times.251 /// Append a value to the slice `n` times.
...@@ -253,7 +253,7 @@ pub fn BoundedArrayAligned(...@@ -253,7 +253,7 @@ pub fn BoundedArrayAligned(
253 pub fn appendNTimes(self: *Self, value: T, n: usize) error{Overflow}!void {253 pub fn appendNTimes(self: *Self, value: T, n: usize) error{Overflow}!void {
254 const old_len = self.len;254 const old_len = self.len;
255 try self.resize(old_len + n);255 try self.resize(old_len + n);
256 mem.set(T, self.slice()[old_len..self.len], value);256 @memset(self.slice()[old_len..self.len], value);
257 }257 }
258258
259 /// Append a value to the slice `n` times.259 /// Append a value to the slice `n` times.
...@@ -262,7 +262,7 @@ pub fn BoundedArrayAligned(...@@ -262,7 +262,7 @@ pub fn BoundedArrayAligned(
262 const old_len = self.len;262 const old_len = self.len;
263 self.len += n;263 self.len += n;
264 assert(self.len <= buffer_capacity);264 assert(self.len <= buffer_capacity);
265 mem.set(T, self.slice()[old_len..self.len], value);265 @memset(self.slice()[old_len..self.len], value);
266 }266 }
267267
268 pub const Writer = if (T != u8)268 pub const Writer = if (T != u8)
...@@ -329,7 +329,7 @@ test "BoundedArray" {...@@ -329,7 +329,7 @@ test "BoundedArray" {
329 try testing.expectEqual(a.popOrNull(), 0);329 try testing.expectEqual(a.popOrNull(), 0);
330 try testing.expectEqual(a.popOrNull(), null);330 try testing.expectEqual(a.popOrNull(), null);
331 var unused = a.unusedCapacitySlice();331 var unused = a.unusedCapacitySlice();
332 mem.set(u8, unused[0..8], 2);332 @memset(unused[0..8], 2);
333 unused[8] = 3;333 unused[8] = 3;
334 unused[9] = 4;334 unused[9] = 4;
335 try testing.expectEqual(unused.len, a.capacity());335 try testing.expectEqual(unused.len, a.capacity());
lib/std/buf_set.zig+1-1
...@@ -97,7 +97,7 @@ pub const BufSet = struct {...@@ -97,7 +97,7 @@ pub const BufSet = struct {
9797
98 fn copy(self: *const BufSet, value: []const u8) ![]const u8 {98 fn copy(self: *const BufSet, value: []const u8) ![]const u8 {
99 const result = try self.hash_map.allocator.alloc(u8, value.len);99 const result = try self.hash_map.allocator.alloc(u8, value.len);
100 mem.copy(u8, result, value);100 @memcpy(result, value);
101 return result;101 return result;
102 }102 }
103};103};
lib/std/child_process.zig+3-3
...@@ -259,7 +259,7 @@ pub const ChildProcess = struct {...@@ -259,7 +259,7 @@ pub const ChildProcess = struct {
259259
260 fn fifoToOwnedArrayList(fifo: *std.io.PollFifo) std.ArrayList(u8) {260 fn fifoToOwnedArrayList(fifo: *std.io.PollFifo) std.ArrayList(u8) {
261 if (fifo.head > 0) {261 if (fifo.head > 0) {
262 std.mem.copy(u8, fifo.buf[0..fifo.count], fifo.buf[fifo.head .. fifo.head + fifo.count]);262 @memcpy(fifo.buf[0..fifo.count], fifo.buf[fifo.head..][0..fifo.count]);
263 }263 }
264 const result = std.ArrayList(u8){264 const result = std.ArrayList(u8){
265 .items = fifo.buf[0..fifo.count],265 .items = fifo.buf[0..fifo.count],
...@@ -1436,9 +1436,9 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) !...@@ -1436,9 +1436,9 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) !
1436 var i: usize = 0;1436 var i: usize = 0;
1437 while (it.next()) |pair| : (i += 1) {1437 while (it.next()) |pair| : (i += 1) {
1438 const env_buf = try arena.allocSentinel(u8, pair.key_ptr.len + pair.value_ptr.len + 1, 0);1438 const env_buf = try arena.allocSentinel(u8, pair.key_ptr.len + pair.value_ptr.len + 1, 0);
1439 mem.copy(u8, env_buf, pair.key_ptr.*);1439 @memcpy(env_buf[0..pair.key_ptr.len], pair.key_ptr.*);
1440 env_buf[pair.key_ptr.len] = '=';1440 env_buf[pair.key_ptr.len] = '=';
1441 mem.copy(u8, env_buf[pair.key_ptr.len + 1 ..], pair.value_ptr.*);1441 @memcpy(env_buf[pair.key_ptr.len + 1 ..][0..pair.value_ptr.len], pair.value_ptr.*);
1442 envp_buf[i] = env_buf.ptr;1442 envp_buf[i] = env_buf.ptr;
1443 }1443 }
1444 assert(i == envp_count);1444 assert(i == envp_count);
lib/std/compress/deflate/compressor.zig+6-6
...@@ -543,7 +543,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -543,7 +543,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
543 self.hash_offset = 1;543 self.hash_offset = 1;
544 self.tokens = try self.allocator.alloc(token.Token, max_flate_block_tokens);544 self.tokens = try self.allocator.alloc(token.Token, max_flate_block_tokens);
545 self.tokens_count = 0;545 self.tokens_count = 0;
546 mem.set(token.Token, self.tokens, 0);546 @memset(self.tokens, 0);
547 self.length = min_match_length - 1;547 self.length = min_match_length - 1;
548 self.offset = 0;548 self.offset = 0;
549 self.byte_available = false;549 self.byte_available = false;
...@@ -841,9 +841,9 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -841,9 +841,9 @@ pub fn Compressor(comptime WriterType: anytype) type {
841 s.hash_head = try allocator.alloc(u32, hash_size);841 s.hash_head = try allocator.alloc(u32, hash_size);
842 s.hash_prev = try allocator.alloc(u32, window_size);842 s.hash_prev = try allocator.alloc(u32, window_size);
843 s.hash_match = try allocator.alloc(u32, max_match_length - 1);843 s.hash_match = try allocator.alloc(u32, max_match_length - 1);
844 mem.set(u32, s.hash_head, 0);844 @memset(s.hash_head, 0);
845 mem.set(u32, s.hash_prev, 0);845 @memset(s.hash_prev, 0);
846 mem.set(u32, s.hash_match, 0);846 @memset(s.hash_match, 0);
847847
848 switch (options.level) {848 switch (options.level) {
849 .no_compression => {849 .no_compression => {
...@@ -936,8 +936,8 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -936,8 +936,8 @@ pub fn Compressor(comptime WriterType: anytype) type {
936 .best_compression,936 .best_compression,
937 => {937 => {
938 self.chain_head = 0;938 self.chain_head = 0;
939 mem.set(u32, self.hash_head, 0);939 @memset(self.hash_head, 0);
940 mem.set(u32, self.hash_prev, 0);940 @memset(self.hash_prev, 0);
941 self.hash_offset = 1;941 self.hash_offset = 1;
942 self.index = 0;942 self.index = 0;
943 self.window_end = 0;943 self.window_end = 0;
lib/std/compress/deflate/decompressor.zig+1-1
...@@ -159,7 +159,7 @@ const HuffmanDecoder = struct {...@@ -159,7 +159,7 @@ const HuffmanDecoder = struct {
159 if (sanity) {159 if (sanity) {
160 // initialize to a known invalid chunk code (0) to see if we overwrite160 // initialize to a known invalid chunk code (0) to see if we overwrite
161 // this value later on161 // this value later on
162 mem.set(u16, self.links[off], 0);162 @memset(self.links[off], 0);
163 }163 }
164 try self.sub_chunks.append(off);164 try self.sub_chunks.append(off);
165 }165 }
lib/std/compress/deflate/deflate_fast.zig+2-2
...@@ -566,11 +566,11 @@ test "best speed match 2/2" {...@@ -566,11 +566,11 @@ test "best speed match 2/2" {
566 for (cases) |c| {566 for (cases) |c| {
567 var previous = try testing.allocator.alloc(u8, c.previous);567 var previous = try testing.allocator.alloc(u8, c.previous);
568 defer testing.allocator.free(previous);568 defer testing.allocator.free(previous);
569 mem.set(u8, previous, 0);569 @memset(previous, 0);
570570
571 var current = try testing.allocator.alloc(u8, c.current);571 var current = try testing.allocator.alloc(u8, c.current);
572 defer testing.allocator.free(current);572 defer testing.allocator.free(current);
573 mem.set(u8, current, 0);573 @memset(current, 0);
574574
575 var e = DeflateFast{575 var e = DeflateFast{
576 .prev = previous,576 .prev = previous,
lib/std/compress/lzma.zig+3-3
...@@ -75,9 +75,9 @@ pub fn Decompress(comptime ReaderType: type) type {...@@ -75,9 +75,9 @@ pub fn Decompress(comptime ReaderType: type) type {
75 }75 }
76 }76 }
77 const input = self.to_read.items;77 const input = self.to_read.items;
78 const n = math.min(input.len, output.len);78 const n = @min(input.len, output.len);
79 mem.copy(u8, output[0..n], input[0..n]);79 @memcpy(output[0..n], input[0..n]);
80 mem.copy(u8, input, input[n..]);80 @memcpy(input[0 .. input.len - n], input[n..]);
81 self.to_read.shrinkRetainingCapacity(input.len - n);81 self.to_read.shrinkRetainingCapacity(input.len - n);
82 return n;82 return n;
83 }83 }
lib/std/compress/lzma/decode/rangecoder.zig+1-1
...@@ -143,7 +143,7 @@ pub fn BitTree(comptime num_bits: usize) type {...@@ -143,7 +143,7 @@ pub fn BitTree(comptime num_bits: usize) type {
143 }143 }
144144
145 pub fn reset(self: *Self) void {145 pub fn reset(self: *Self) void {
146 mem.set(u16, &self.probs, 0x400);146 @memset(&self.probs, 0x400);
147 }147 }
148 };148 };
149}149}
lib/std/compress/lzma/vec2d.zig+2-2
...@@ -13,7 +13,7 @@ pub fn Vec2D(comptime T: type) type {...@@ -13,7 +13,7 @@ pub fn Vec2D(comptime T: type) type {
13 pub fn init(allocator: Allocator, value: T, size: struct { usize, usize }) !Self {13 pub fn init(allocator: Allocator, value: T, size: struct { usize, usize }) !Self {
14 const len = try math.mul(usize, size[0], size[1]);14 const len = try math.mul(usize, size[0], size[1]);
15 const data = try allocator.alloc(T, len);15 const data = try allocator.alloc(T, len);
16 mem.set(T, data, value);16 @memset(data, value);
17 return Self{17 return Self{
18 .data = data,18 .data = data,
19 .cols = size[1],19 .cols = size[1],
...@@ -26,7 +26,7 @@ pub fn Vec2D(comptime T: type) type {...@@ -26,7 +26,7 @@ pub fn Vec2D(comptime T: type) type {
26 }26 }
2727
28 pub fn fill(self: *Self, value: T) void {28 pub fn fill(self: *Self, value: T) void {
29 mem.set(T, self.data, value);29 @memset(self.data, value);
30 }30 }
3131
32 inline fn _get(self: Self, row: usize) ![]T {32 inline fn _get(self: Self, row: usize) ![]T {
lib/std/compress/zstandard/decode/block.zig+7-10
...@@ -293,10 +293,10 @@ pub const DecodeState = struct {...@@ -293,10 +293,10 @@ pub const DecodeState = struct {
293293
294 try self.decodeLiteralsSlice(dest[write_pos..], sequence.literal_length);294 try self.decodeLiteralsSlice(dest[write_pos..], sequence.literal_length);
295 const copy_start = write_pos + sequence.literal_length - sequence.offset;295 const copy_start = write_pos + sequence.literal_length - sequence.offset;
296 const copy_end = copy_start + sequence.match_length;296 for (
297 // NOTE: we ignore the usage message for std.mem.copy and copy with dest.ptr >= src.ptr297 dest[write_pos + sequence.literal_length ..][0..sequence.match_length],
298 // to allow repeats298 dest[copy_start..][0..sequence.match_length],
299 std.mem.copy(u8, dest[write_pos + sequence.literal_length ..], dest[copy_start..copy_end]);299 ) |*d, s| d.* = s;
300 self.written_count += sequence.match_length;300 self.written_count += sequence.match_length;
301 }301 }
302302
...@@ -311,7 +311,6 @@ pub const DecodeState = struct {...@@ -311,7 +311,6 @@ pub const DecodeState = struct {
311 try self.decodeLiteralsRingBuffer(dest, sequence.literal_length);311 try self.decodeLiteralsRingBuffer(dest, sequence.literal_length);
312 const copy_start = dest.write_index + dest.data.len - sequence.offset;312 const copy_start = dest.write_index + dest.data.len - sequence.offset;
313 const copy_slice = dest.sliceAt(copy_start, sequence.match_length);313 const copy_slice = dest.sliceAt(copy_start, sequence.match_length);
314 // TODO: would std.mem.copy and figuring out dest slice be better/faster?
315 for (copy_slice.first) |b| dest.writeAssumeCapacity(b);314 for (copy_slice.first) |b| dest.writeAssumeCapacity(b);
316 for (copy_slice.second) |b| dest.writeAssumeCapacity(b);315 for (copy_slice.second) |b| dest.writeAssumeCapacity(b);
317 self.written_count += sequence.match_length;316 self.written_count += sequence.match_length;
...@@ -444,9 +443,8 @@ pub const DecodeState = struct {...@@ -444,9 +443,8 @@ pub const DecodeState = struct {
444443
445 switch (self.literal_header.block_type) {444 switch (self.literal_header.block_type) {
446 .raw => {445 .raw => {
447 const literals_end = self.literal_written_count + len;446 const literal_data = self.literal_streams.one[self.literal_written_count..][0..len];
448 const literal_data = self.literal_streams.one[self.literal_written_count..literals_end];447 @memcpy(dest[0..len], literal_data);
449 std.mem.copy(u8, dest, literal_data);
450 self.literal_written_count += len;448 self.literal_written_count += len;
451 self.written_count += len;449 self.written_count += len;
452 },450 },
...@@ -615,8 +613,7 @@ pub fn decodeBlock(...@@ -615,8 +613,7 @@ pub fn decodeBlock(
615 .raw => {613 .raw => {
616 if (src.len < block_size) return error.MalformedBlockSize;614 if (src.len < block_size) return error.MalformedBlockSize;
617 if (dest[written_count..].len < block_size) return error.DestTooSmall;615 if (dest[written_count..].len < block_size) return error.DestTooSmall;
618 const data = src[0..block_size];616 @memcpy(dest[written_count..][0..block_size], src[0..block_size]);
619 std.mem.copy(u8, dest[written_count..], data);
620 consumed_count.* += block_size;617 consumed_count.* += block_size;
621 decode_state.written_count += block_size;618 decode_state.written_count += block_size;
622 return block_size;619 return block_size;
lib/std/crypto/25519/ed25519.zig+9-9
...@@ -79,8 +79,8 @@ pub const Ed25519 = struct {...@@ -79,8 +79,8 @@ pub const Ed25519 = struct {
79 const r_bytes = r.toBytes();79 const r_bytes = r.toBytes();
8080
81 var t: [64]u8 = undefined;81 var t: [64]u8 = undefined;
82 mem.copy(u8, t[0..32], &r_bytes);82 t[0..32].* = r_bytes;
83 mem.copy(u8, t[32..], &public_key.bytes);83 t[32..].* = public_key.bytes;
84 var h = Sha512.init(.{});84 var h = Sha512.init(.{});
85 h.update(&t);85 h.update(&t);
8686
...@@ -200,8 +200,8 @@ pub const Ed25519 = struct {...@@ -200,8 +200,8 @@ pub const Ed25519 = struct {
200 /// Return the raw signature (r, s) in little-endian format.200 /// Return the raw signature (r, s) in little-endian format.
201 pub fn toBytes(self: Signature) [encoded_length]u8 {201 pub fn toBytes(self: Signature) [encoded_length]u8 {
202 var bytes: [encoded_length]u8 = undefined;202 var bytes: [encoded_length]u8 = undefined;
203 mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);203 bytes[0 .. encoded_length / 2].* = self.r;
204 mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);204 bytes[encoded_length / 2 ..].* = self.s;
205 return bytes;205 return bytes;
206 }206 }
207207
...@@ -260,8 +260,8 @@ pub const Ed25519 = struct {...@@ -260,8 +260,8 @@ pub const Ed25519 = struct {
260 const pk_p = Curve.basePoint.clampedMul(az[0..32].*) catch return error.IdentityElement;260 const pk_p = Curve.basePoint.clampedMul(az[0..32].*) catch return error.IdentityElement;
261 const pk_bytes = pk_p.toBytes();261 const pk_bytes = pk_p.toBytes();
262 var sk_bytes: [SecretKey.encoded_length]u8 = undefined;262 var sk_bytes: [SecretKey.encoded_length]u8 = undefined;
263 mem.copy(u8, &sk_bytes, &ss);263 sk_bytes[0..ss.len].* = ss;
264 mem.copy(u8, sk_bytes[seed_length..], &pk_bytes);264 sk_bytes[seed_length..].* = pk_bytes;
265 return KeyPair{265 return KeyPair{
266 .public_key = PublicKey.fromBytes(pk_bytes) catch unreachable,266 .public_key = PublicKey.fromBytes(pk_bytes) catch unreachable,
267 .secret_key = try SecretKey.fromBytes(sk_bytes),267 .secret_key = try SecretKey.fromBytes(sk_bytes),
...@@ -373,7 +373,7 @@ pub const Ed25519 = struct {...@@ -373,7 +373,7 @@ pub const Ed25519 = struct {
373 var z_batch: [count]Curve.scalar.CompressedScalar = undefined;373 var z_batch: [count]Curve.scalar.CompressedScalar = undefined;
374 for (&z_batch) |*z| {374 for (&z_batch) |*z| {
375 crypto.random.bytes(z[0..16]);375 crypto.random.bytes(z[0..16]);
376 mem.set(u8, z[16..], 0);376 @memset(z[16..], 0);
377 }377 }
378378
379 var zs_sum = Curve.scalar.zero;379 var zs_sum = Curve.scalar.zero;
...@@ -444,8 +444,8 @@ pub const Ed25519 = struct {...@@ -444,8 +444,8 @@ pub const Ed25519 = struct {
444 };444 };
445445
446 var prefix: [64]u8 = undefined;446 var prefix: [64]u8 = undefined;
447 mem.copy(u8, prefix[0..32], h[32..64]);447 prefix[0..32].* = h[32..64].*;
448 mem.copy(u8, prefix[32..64], blind_h[32..64]);448 prefix[32..64].* = blind_h[32..64].*;
449449
450 const blind_secret_key = BlindSecretKey{450 const blind_secret_key = BlindSecretKey{
451 .prefix = prefix,451 .prefix = prefix,
lib/std/crypto/25519/edwards25519.zig+4-4
...@@ -306,7 +306,7 @@ pub const Edwards25519 = struct {...@@ -306,7 +306,7 @@ pub const Edwards25519 = struct {
306 var pcs: [count][9]Edwards25519 = undefined;306 var pcs: [count][9]Edwards25519 = undefined;
307307
308 var bpc: [9]Edwards25519 = undefined;308 var bpc: [9]Edwards25519 = undefined;
309 mem.copy(Edwards25519, bpc[0..], basePointPc[0..bpc.len]);309 @memcpy(&bpc, basePointPc[0..bpc.len]);
310310
311 for (ps, 0..) |p, i| {311 for (ps, 0..) |p, i| {
312 if (p.is_base) {312 if (p.is_base) {
...@@ -439,7 +439,7 @@ pub const Edwards25519 = struct {...@@ -439,7 +439,7 @@ pub const Edwards25519 = struct {
439 var u: [n * H.digest_length]u8 = undefined;439 var u: [n * H.digest_length]u8 = undefined;
440 var i: usize = 0;440 var i: usize = 0;
441 while (i < n * H.digest_length) : (i += H.digest_length) {441 while (i < n * H.digest_length) : (i += H.digest_length) {
442 mem.copy(u8, u[i..][0..H.digest_length], u_0[0..]);442 u[i..][0..H.digest_length].* = u_0;
443 var j: usize = 0;443 var j: usize = 0;
444 while (i > 0 and j < H.digest_length) : (j += 1) {444 while (i > 0 and j < H.digest_length) : (j += 1) {
445 u[i + j] ^= u[i + j - H.digest_length];445 u[i + j] ^= u[i + j - H.digest_length];
...@@ -455,8 +455,8 @@ pub const Edwards25519 = struct {...@@ -455,8 +455,8 @@ pub const Edwards25519 = struct {
455 var px: [n]Edwards25519 = undefined;455 var px: [n]Edwards25519 = undefined;
456 i = 0;456 i = 0;
457 while (i < n) : (i += 1) {457 while (i < n) : (i += 1) {
458 mem.set(u8, u_0[0 .. H.digest_length - h_l], 0);458 @memset(u_0[0 .. H.digest_length - h_l], 0);
459 mem.copy(u8, u_0[H.digest_length - h_l ..][0..h_l], u[i * h_l ..][0..h_l]);459 u_0[H.digest_length - h_l ..][0..h_l].* = u[i * h_l ..][0..h_l].*;
460 px[i] = fromHash(u_0);460 px[i] = fromHash(u_0);
461 }461 }
462 return px;462 return px;
lib/std/crypto/25519/scalar.zig+3-3
...@@ -83,8 +83,8 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar {...@@ -83,8 +83,8 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar {
83pub fn neg(s: CompressedScalar) CompressedScalar {83pub fn neg(s: CompressedScalar) CompressedScalar {
84 const fs: [64]u8 = field_order_s ++ [_]u8{0} ** 32;84 const fs: [64]u8 = field_order_s ++ [_]u8{0} ** 32;
85 var sx: [64]u8 = undefined;85 var sx: [64]u8 = undefined;
86 mem.copy(u8, sx[0..32], s[0..]);86 sx[0..32].* = s;
87 mem.set(u8, sx[32..], 0);87 @memset(sx[32..], 0);
88 var carry: u32 = 0;88 var carry: u32 = 0;
89 var i: usize = 0;89 var i: usize = 0;
90 while (i < 64) : (i += 1) {90 while (i < 64) : (i += 1) {
...@@ -593,7 +593,7 @@ const ScalarDouble = struct {...@@ -593,7 +593,7 @@ const ScalarDouble = struct {
593 limbs[i] = mem.readIntLittle(u64, bytes[i * 7 ..][0..8]) & 0xffffffffffffff;593 limbs[i] = mem.readIntLittle(u64, bytes[i * 7 ..][0..8]) & 0xffffffffffffff;
594 }594 }
595 limbs[i] = @as(u64, mem.readIntLittle(u32, bytes[i * 7 ..][0..4]));595 limbs[i] = @as(u64, mem.readIntLittle(u32, bytes[i * 7 ..][0..4]));
596 mem.set(u64, limbs[5..], 0);596 @memset(limbs[5..], 0);
597 return ScalarDouble{ .limbs = limbs };597 return ScalarDouble{ .limbs = limbs };
598 }598 }
599599
lib/std/crypto/25519/x25519.zig+7-7
...@@ -37,7 +37,7 @@ pub const X25519 = struct {...@@ -37,7 +37,7 @@ pub const X25519 = struct {
37 break :sk random_seed;37 break :sk random_seed;
38 };38 };
39 var kp: KeyPair = undefined;39 var kp: KeyPair = undefined;
40 mem.copy(u8, &kp.secret_key, sk[0..]);40 kp.secret_key = sk;
41 kp.public_key = try X25519.recoverPublicKey(sk);41 kp.public_key = try X25519.recoverPublicKey(sk);
42 return kp;42 return kp;
43 }43 }
...@@ -120,8 +120,8 @@ test "x25519 rfc7748 one iteration" {...@@ -120,8 +120,8 @@ test "x25519 rfc7748 one iteration" {
120 var i: usize = 0;120 var i: usize = 0;
121 while (i < 1) : (i += 1) {121 while (i < 1) : (i += 1) {
122 const output = try X25519.scalarmult(k, u);122 const output = try X25519.scalarmult(k, u);
123 mem.copy(u8, u[0..], k[0..]);123 u = k;
124 mem.copy(u8, k[0..], output[0..]);124 k = output;
125 }125 }
126126
127 try std.testing.expectEqual(k, expected_output);127 try std.testing.expectEqual(k, expected_output);
...@@ -142,8 +142,8 @@ test "x25519 rfc7748 1,000 iterations" {...@@ -142,8 +142,8 @@ test "x25519 rfc7748 1,000 iterations" {
142 var i: usize = 0;142 var i: usize = 0;
143 while (i < 1000) : (i += 1) {143 while (i < 1000) : (i += 1) {
144 const output = try X25519.scalarmult(&k, &u);144 const output = try X25519.scalarmult(&k, &u);
145 mem.copy(u8, u[0..], k[0..]);145 u = k;
146 mem.copy(u8, k[0..], output[0..]);146 k = output;
147 }147 }
148148
149 try std.testing.expectEqual(k, expected_output);149 try std.testing.expectEqual(k, expected_output);
...@@ -163,8 +163,8 @@ test "x25519 rfc7748 1,000,000 iterations" {...@@ -163,8 +163,8 @@ test "x25519 rfc7748 1,000,000 iterations" {
163 var i: usize = 0;163 var i: usize = 0;
164 while (i < 1000000) : (i += 1) {164 while (i < 1000000) : (i += 1) {
165 const output = try X25519.scalarmult(&k, &u);165 const output = try X25519.scalarmult(&k, &u);
166 mem.copy(u8, u[0..], k[0..]);166 u = k;
167 mem.copy(u8, k[0..], output[0..]);167 k = output;
168 }168 }
169169
170 try std.testing.expectEqual(k[0..], expected_output);170 try std.testing.expectEqual(k[0..], expected_output);
lib/std/crypto/Certificate.zig+7-7
...@@ -928,7 +928,7 @@ pub const rsa = struct {...@@ -928,7 +928,7 @@ pub const rsa = struct {
928 pub const PSSSignature = struct {928 pub const PSSSignature = struct {
929 pub fn fromBytes(comptime modulus_len: usize, msg: []const u8) [modulus_len]u8 {929 pub fn fromBytes(comptime modulus_len: usize, msg: []const u8) [modulus_len]u8 {
930 var result = [1]u8{0} ** modulus_len;930 var result = [1]u8{0} ** modulus_len;
931 std.mem.copy(u8, &result, msg);931 std.mem.copyForwards(u8, &result, msg);
932 return result;932 return result;
933 }933 }
934934
...@@ -1025,9 +1025,9 @@ pub const rsa = struct {...@@ -1025,9 +1025,9 @@ pub const rsa = struct {
1025 // initial zero octets.1025 // initial zero octets.
1026 var m_p = try allocator.alloc(u8, 8 + Hash.digest_length + sLen);1026 var m_p = try allocator.alloc(u8, 8 + Hash.digest_length + sLen);
1027 defer allocator.free(m_p);1027 defer allocator.free(m_p);
1028 std.mem.copy(u8, m_p, &([_]u8{0} ** 8));1028 std.mem.copyForwards(u8, m_p, &([_]u8{0} ** 8));
1029 std.mem.copy(u8, m_p[8..], &mHash);1029 std.mem.copyForwards(u8, m_p[8..], &mHash);
1030 std.mem.copy(u8, m_p[(8 + Hash.digest_length)..], salt);1030 std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt);
10311031
1032 // 13. Let H' = Hash(M'), an octet string of length hLen.1032 // 13. Let H' = Hash(M'), an octet string of length hLen.
1033 var h_p: [Hash.digest_length]u8 = undefined;1033 var h_p: [Hash.digest_length]u8 = undefined;
...@@ -1047,7 +1047,7 @@ pub const rsa = struct {...@@ -1047,7 +1047,7 @@ pub const rsa = struct {
10471047
1048 var hash = try allocator.alloc(u8, seed.len + c.len);1048 var hash = try allocator.alloc(u8, seed.len + c.len);
1049 defer allocator.free(hash);1049 defer allocator.free(hash);
1050 std.mem.copy(u8, hash, seed);1050 std.mem.copyForwards(u8, hash, seed);
1051 var hashed: [Hash.digest_length]u8 = undefined;1051 var hashed: [Hash.digest_length]u8 = undefined;
10521052
1053 while (idx < len) {1053 while (idx < len) {
...@@ -1056,10 +1056,10 @@ pub const rsa = struct {...@@ -1056,10 +1056,10 @@ pub const rsa = struct {
1056 c[2] = @intCast(u8, (counter >> 8) & 0xFF);1056 c[2] = @intCast(u8, (counter >> 8) & 0xFF);
1057 c[3] = @intCast(u8, counter & 0xFF);1057 c[3] = @intCast(u8, counter & 0xFF);
10581058
1059 std.mem.copy(u8, hash[seed.len..], &c);1059 std.mem.copyForwards(u8, hash[seed.len..], &c);
1060 Hash.hash(hash, &hashed, .{});1060 Hash.hash(hash, &hashed, .{});
10611061
1062 std.mem.copy(u8, out[idx..], &hashed);1062 std.mem.copyForwards(u8, out[idx..], &hashed);
1063 idx += hashed.len;1063 idx += hashed.len;
10641064
1065 counter += 1;1065 counter += 1;
lib/std/crypto/aegis.zig+25-25
...@@ -152,8 +152,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {...@@ -152,8 +152,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
152 state.absorb(ad[i..][0..32]);152 state.absorb(ad[i..][0..32]);
153 }153 }
154 if (ad.len % 32 != 0) {154 if (ad.len % 32 != 0) {
155 mem.set(u8, src[0..], 0);155 @memset(src[0..], 0);
156 mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);156 @memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
157 state.absorb(&src);157 state.absorb(&src);
158 }158 }
159 i = 0;159 i = 0;
...@@ -161,10 +161,10 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {...@@ -161,10 +161,10 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
161 state.enc(c[i..][0..32], m[i..][0..32]);161 state.enc(c[i..][0..32], m[i..][0..32]);
162 }162 }
163 if (m.len % 32 != 0) {163 if (m.len % 32 != 0) {
164 mem.set(u8, src[0..], 0);164 @memset(src[0..], 0);
165 mem.copy(u8, src[0 .. m.len % 32], m[i .. i + m.len % 32]);165 @memcpy(src[0 .. m.len % 32], m[i..][0 .. m.len % 32]);
166 state.enc(&dst, &src);166 state.enc(&dst, &src);
167 mem.copy(u8, c[i .. i + m.len % 32], dst[0 .. m.len % 32]);167 @memcpy(c[i..][0 .. m.len % 32], dst[0 .. m.len % 32]);
168 }168 }
169 tag.* = state.mac(tag_bits, ad.len, m.len);169 tag.* = state.mac(tag_bits, ad.len, m.len);
170 }170 }
...@@ -185,8 +185,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {...@@ -185,8 +185,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
185 state.absorb(ad[i..][0..32]);185 state.absorb(ad[i..][0..32]);
186 }186 }
187 if (ad.len % 32 != 0) {187 if (ad.len % 32 != 0) {
188 mem.set(u8, src[0..], 0);188 @memset(src[0..], 0);
189 mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);189 @memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
190 state.absorb(&src);190 state.absorb(&src);
191 }191 }
192 i = 0;192 i = 0;
...@@ -194,11 +194,11 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {...@@ -194,11 +194,11 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
194 state.dec(m[i..][0..32], c[i..][0..32]);194 state.dec(m[i..][0..32], c[i..][0..32]);
195 }195 }
196 if (m.len % 32 != 0) {196 if (m.len % 32 != 0) {
197 mem.set(u8, src[0..], 0);197 @memset(src[0..], 0);
198 mem.copy(u8, src[0 .. m.len % 32], c[i .. i + m.len % 32]);198 @memcpy(src[0 .. m.len % 32], c[i..][0 .. m.len % 32]);
199 state.dec(&dst, &src);199 state.dec(&dst, &src);
200 mem.copy(u8, m[i .. i + m.len % 32], dst[0 .. m.len % 32]);200 @memcpy(m[i..][0 .. m.len % 32], dst[0 .. m.len % 32]);
201 mem.set(u8, dst[0 .. m.len % 32], 0);201 @memset(dst[0 .. m.len % 32], 0);
202 const blocks = &state.blocks;202 const blocks = &state.blocks;
203 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(dst[0..16]));203 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(dst[0..16]));
204 blocks[4] = blocks[4].xorBlocks(AesBlock.fromBytes(dst[16..32]));204 blocks[4] = blocks[4].xorBlocks(AesBlock.fromBytes(dst[16..32]));
...@@ -334,8 +334,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {...@@ -334,8 +334,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
334 state.enc(&dst, ad[i..][0..16]);334 state.enc(&dst, ad[i..][0..16]);
335 }335 }
336 if (ad.len % 16 != 0) {336 if (ad.len % 16 != 0) {
337 mem.set(u8, src[0..], 0);337 @memset(src[0..], 0);
338 mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);338 @memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
339 state.enc(&dst, &src);339 state.enc(&dst, &src);
340 }340 }
341 i = 0;341 i = 0;
...@@ -343,10 +343,10 @@ fn Aegis256Generic(comptime tag_bits: u9) type {...@@ -343,10 +343,10 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
343 state.enc(c[i..][0..16], m[i..][0..16]);343 state.enc(c[i..][0..16], m[i..][0..16]);
344 }344 }
345 if (m.len % 16 != 0) {345 if (m.len % 16 != 0) {
346 mem.set(u8, src[0..], 0);346 @memset(src[0..], 0);
347 mem.copy(u8, src[0 .. m.len % 16], m[i .. i + m.len % 16]);347 @memcpy(src[0 .. m.len % 16], m[i..][0 .. m.len % 16]);
348 state.enc(&dst, &src);348 state.enc(&dst, &src);
349 mem.copy(u8, c[i .. i + m.len % 16], dst[0 .. m.len % 16]);349 @memcpy(c[i..][0 .. m.len % 16], dst[0 .. m.len % 16]);
350 }350 }
351 tag.* = state.mac(tag_bits, ad.len, m.len);351 tag.* = state.mac(tag_bits, ad.len, m.len);
352 }352 }
...@@ -367,8 +367,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {...@@ -367,8 +367,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
367 state.enc(&dst, ad[i..][0..16]);367 state.enc(&dst, ad[i..][0..16]);
368 }368 }
369 if (ad.len % 16 != 0) {369 if (ad.len % 16 != 0) {
370 mem.set(u8, src[0..], 0);370 @memset(src[0..], 0);
371 mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);371 @memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
372 state.enc(&dst, &src);372 state.enc(&dst, &src);
373 }373 }
374 i = 0;374 i = 0;
...@@ -376,11 +376,11 @@ fn Aegis256Generic(comptime tag_bits: u9) type {...@@ -376,11 +376,11 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
376 state.dec(m[i..][0..16], c[i..][0..16]);376 state.dec(m[i..][0..16], c[i..][0..16]);
377 }377 }
378 if (m.len % 16 != 0) {378 if (m.len % 16 != 0) {
379 mem.set(u8, src[0..], 0);379 @memset(src[0..], 0);
380 mem.copy(u8, src[0 .. m.len % 16], c[i .. i + m.len % 16]);380 @memcpy(src[0 .. m.len % 16], c[i..][0 .. m.len % 16]);
381 state.dec(&dst, &src);381 state.dec(&dst, &src);
382 mem.copy(u8, m[i .. i + m.len % 16], dst[0 .. m.len % 16]);382 @memcpy(m[i..][0 .. m.len % 16], dst[0 .. m.len % 16]);
383 mem.set(u8, dst[0 .. m.len % 16], 0);383 @memset(dst[0 .. m.len % 16], 0);
384 const blocks = &state.blocks;384 const blocks = &state.blocks;
385 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(&dst));385 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(&dst));
386 }386 }
...@@ -457,7 +457,7 @@ fn AegisMac(comptime T: type) type {...@@ -457,7 +457,7 @@ fn AegisMac(comptime T: type) type {
457 self.msg_len += b.len;457 self.msg_len += b.len;
458458
459 const len_partial = @min(b.len, block_length - self.off);459 const len_partial = @min(b.len, block_length - self.off);
460 mem.copy(u8, self.buf[self.off..][0..len_partial], b[0..len_partial]);460 @memcpy(self.buf[self.off..][0..len_partial], b[0..len_partial]);
461 self.off += len_partial;461 self.off += len_partial;
462 if (self.off < block_length) {462 if (self.off < block_length) {
463 return;463 return;
...@@ -470,7 +470,7 @@ fn AegisMac(comptime T: type) type {...@@ -470,7 +470,7 @@ fn AegisMac(comptime T: type) type {
470 self.state.absorb(b[i..][0..block_length]);470 self.state.absorb(b[i..][0..block_length]);
471 }471 }
472 if (i != b.len) {472 if (i != b.len) {
473 mem.copy(u8, self.buf[0..], b[i..]);473 @memcpy(self.buf[0..], b[i..]);
474 self.off = b.len - i;474 self.off = b.len - i;
475 }475 }
476 }476 }
...@@ -479,7 +479,7 @@ fn AegisMac(comptime T: type) type {...@@ -479,7 +479,7 @@ fn AegisMac(comptime T: type) type {
479 pub fn final(self: *Self, out: *[mac_length]u8) void {479 pub fn final(self: *Self, out: *[mac_length]u8) void {
480 if (self.off > 0) {480 if (self.off > 0) {
481 var pad = [_]u8{0} ** block_length;481 var pad = [_]u8{0} ** block_length;
482 mem.copy(u8, pad[0..], self.buf[0..self.off]);482 @memcpy(pad[0..self.off], self.buf[0..self.off]);
483 self.state.absorb(&pad);483 self.state.absorb(&pad);
484 }484 }
485 out.* = self.state.mac(T.tag_length * 8, self.msg_len, 0);485 out.* = self.state.mac(T.tag_length * 8, self.msg_len, 0);
lib/std/crypto/aes_gcm.zig+2-2
...@@ -31,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type {...@@ -31,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type {
3131
32 var t: [16]u8 = undefined;32 var t: [16]u8 = undefined;
33 var j: [16]u8 = undefined;33 var j: [16]u8 = undefined;
34 mem.copy(u8, j[0..nonce_length], npub[0..]);34 j[0..nonce_length].* = npub;
35 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);35 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
36 aes.encrypt(&t, &j);36 aes.encrypt(&t, &j);
3737
...@@ -64,7 +64,7 @@ fn AesGcm(comptime Aes: anytype) type {...@@ -64,7 +64,7 @@ fn AesGcm(comptime Aes: anytype) type {
6464
65 var t: [16]u8 = undefined;65 var t: [16]u8 = undefined;
66 var j: [16]u8 = undefined;66 var j: [16]u8 = undefined;
67 mem.copy(u8, j[0..nonce_length], npub[0..]);67 j[0..nonce_length].* = npub;
68 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);68 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
69 aes.encrypt(&t, &j);69 aes.encrypt(&t, &j);
7070
lib/std/crypto/aes_ocb.zig+10-10
...@@ -75,7 +75,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -75,7 +75,7 @@ fn AesOcb(comptime Aes: anytype) type {
75 if (leftover > 0) {75 if (leftover > 0) {
76 xorWith(&offset, lx.star);76 xorWith(&offset, lx.star);
77 var padded = [_]u8{0} ** 16;77 var padded = [_]u8{0} ** 16;
78 mem.copy(u8, padded[0..leftover], a[i * 16 ..][0..leftover]);78 @memcpy(padded[0..leftover], a[i * 16 ..][0..leftover]);
79 padded[leftover] = 1;79 padded[leftover] = 1;
80 var e = xorBlocks(offset, padded);80 var e = xorBlocks(offset, padded);
81 aes_enc_ctx.encrypt(&e, &e);81 aes_enc_ctx.encrypt(&e, &e);
...@@ -88,7 +88,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -88,7 +88,7 @@ fn AesOcb(comptime Aes: anytype) type {
88 var nx = [_]u8{0} ** 16;88 var nx = [_]u8{0} ** 16;
89 nx[0] = @intCast(u8, @truncate(u7, tag_length * 8) << 1);89 nx[0] = @intCast(u8, @truncate(u7, tag_length * 8) << 1);
90 nx[16 - nonce_length - 1] = 1;90 nx[16 - nonce_length - 1] = 1;
91 mem.copy(u8, nx[16 - nonce_length ..], &npub);91 nx[nx.len - nonce_length ..].* = npub;
9292
93 const bottom = @truncate(u6, nx[15]);93 const bottom = @truncate(u6, nx[15]);
94 nx[15] &= 0xc0;94 nx[15] &= 0xc0;
...@@ -132,14 +132,14 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -132,14 +132,14 @@ fn AesOcb(comptime Aes: anytype) type {
132 xorWith(&offset, lt[@ctz(i + 1 + j)]);132 xorWith(&offset, lt[@ctz(i + 1 + j)]);
133 offsets[j] = offset;133 offsets[j] = offset;
134 const p = m[(i + j) * 16 ..][0..16].*;134 const p = m[(i + j) * 16 ..][0..16].*;
135 mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(p, offsets[j]));135 es[j * 16 ..][0..16].* = xorBlocks(p, offsets[j]);
136 xorWith(&sum, p);136 xorWith(&sum, p);
137 }137 }
138 aes_enc_ctx.encryptWide(wb, &es, &es);138 aes_enc_ctx.encryptWide(wb, &es, &es);
139 j = 0;139 j = 0;
140 while (j < wb) : (j += 1) {140 while (j < wb) : (j += 1) {
141 const e = es[j * 16 ..][0..16].*;141 const e = es[j * 16 ..][0..16].*;
142 mem.copy(u8, c[(i + j) * 16 ..][0..16], &xorBlocks(e, offsets[j]));142 c[(i + j) * 16 ..][0..16].* = xorBlocks(e, offsets[j]);
143 }143 }
144 }144 }
145 while (i < full_blocks) : (i += 1) {145 while (i < full_blocks) : (i += 1) {
...@@ -147,7 +147,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -147,7 +147,7 @@ fn AesOcb(comptime Aes: anytype) type {
147 const p = m[i * 16 ..][0..16].*;147 const p = m[i * 16 ..][0..16].*;
148 var e = xorBlocks(p, offset);148 var e = xorBlocks(p, offset);
149 aes_enc_ctx.encrypt(&e, &e);149 aes_enc_ctx.encrypt(&e, &e);
150 mem.copy(u8, c[i * 16 ..][0..16], &xorBlocks(e, offset));150 c[i * 16 ..][0..16].* = xorBlocks(e, offset);
151 xorWith(&sum, p);151 xorWith(&sum, p);
152 }152 }
153 const leftover = m.len % 16;153 const leftover = m.len % 16;
...@@ -159,7 +159,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -159,7 +159,7 @@ fn AesOcb(comptime Aes: anytype) type {
159 c[i * 16 + j] = pad[j] ^ x;159 c[i * 16 + j] = pad[j] ^ x;
160 }160 }
161 var e = [_]u8{0} ** 16;161 var e = [_]u8{0} ** 16;
162 mem.copy(u8, e[0..leftover], m[i * 16 ..][0..leftover]);162 @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
163 e[leftover] = 0x80;163 e[leftover] = 0x80;
164 xorWith(&sum, e);164 xorWith(&sum, e);
165 }165 }
...@@ -196,13 +196,13 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -196,13 +196,13 @@ fn AesOcb(comptime Aes: anytype) type {
196 xorWith(&offset, lt[@ctz(i + 1 + j)]);196 xorWith(&offset, lt[@ctz(i + 1 + j)]);
197 offsets[j] = offset;197 offsets[j] = offset;
198 const q = c[(i + j) * 16 ..][0..16].*;198 const q = c[(i + j) * 16 ..][0..16].*;
199 mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(q, offsets[j]));199 es[j * 16 ..][0..16].* = xorBlocks(q, offsets[j]);
200 }200 }
201 aes_dec_ctx.decryptWide(wb, &es, &es);201 aes_dec_ctx.decryptWide(wb, &es, &es);
202 j = 0;202 j = 0;
203 while (j < wb) : (j += 1) {203 while (j < wb) : (j += 1) {
204 const p = xorBlocks(es[j * 16 ..][0..16].*, offsets[j]);204 const p = xorBlocks(es[j * 16 ..][0..16].*, offsets[j]);
205 mem.copy(u8, m[(i + j) * 16 ..][0..16], &p);205 m[(i + j) * 16 ..][0..16].* = p;
206 xorWith(&sum, p);206 xorWith(&sum, p);
207 }207 }
208 }208 }
...@@ -212,7 +212,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -212,7 +212,7 @@ fn AesOcb(comptime Aes: anytype) type {
212 var e = xorBlocks(q, offset);212 var e = xorBlocks(q, offset);
213 aes_dec_ctx.decrypt(&e, &e);213 aes_dec_ctx.decrypt(&e, &e);
214 const p = xorBlocks(e, offset);214 const p = xorBlocks(e, offset);
215 mem.copy(u8, m[i * 16 ..][0..16], &p);215 m[i * 16 ..][0..16].* = p;
216 xorWith(&sum, p);216 xorWith(&sum, p);
217 }217 }
218 const leftover = m.len % 16;218 const leftover = m.len % 16;
...@@ -224,7 +224,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -224,7 +224,7 @@ fn AesOcb(comptime Aes: anytype) type {
224 m[i * 16 + j] = pad[j] ^ x;224 m[i * 16 + j] = pad[j] ^ x;
225 }225 }
226 var e = [_]u8{0} ** 16;226 var e = [_]u8{0} ** 16;
227 mem.copy(u8, e[0..leftover], m[i * 16 ..][0..leftover]);227 @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
228 e[leftover] = 0x80;228 e[leftover] = 0x80;
229 xorWith(&sum, e);229 xorWith(&sum, e);
230 }230 }
lib/std/crypto/argon2.zig+2-2
...@@ -494,7 +494,7 @@ pub fn kdf(...@@ -494,7 +494,7 @@ pub fn kdf(
494 if (params.t < 1 or params.p < 1) return KdfError.WeakParameters;494 if (params.t < 1 or params.p < 1) return KdfError.WeakParameters;
495495
496 var h0 = initHash(password, salt, params, derived_key.len, mode);496 var h0 = initHash(password, salt, params, derived_key.len, mode);
497 const memory = math.max(497 const memory = @max(
498 params.m / (sync_points * params.p) * (sync_points * params.p),498 params.m / (sync_points * params.p) * (sync_points * params.p),
499 2 * sync_points * params.p,499 2 * sync_points * params.p,
500 );500 );
...@@ -877,7 +877,7 @@ test "kdf" {...@@ -877,7 +877,7 @@ test "kdf" {
877 .hash = "1640b932f4b60e272f5d2207b9a9c626ffa1bd88d2349016",877 .hash = "1640b932f4b60e272f5d2207b9a9c626ffa1bd88d2349016",
878 },878 },
879 };879 };
880 inline for (test_vectors) |v| {880 for (test_vectors) |v| {
881 var want: [24]u8 = undefined;881 var want: [24]u8 = undefined;
882 _ = try std.fmt.hexToBytes(&want, v.hash);882 _ = try std.fmt.hexToBytes(&want, v.hash);
883883
lib/std/crypto/ascon.zig+7-7
...@@ -34,7 +34,7 @@ pub fn State(comptime endian: builtin.Endian) type {...@@ -34,7 +34,7 @@ pub fn State(comptime endian: builtin.Endian) type {
34 /// Initialize the state from a slice of bytes.34 /// Initialize the state from a slice of bytes.
35 pub fn init(initial_state: [block_bytes]u8) Self {35 pub fn init(initial_state: [block_bytes]u8) Self {
36 var state = Self{ .st = undefined };36 var state = Self{ .st = undefined };
37 mem.copy(u8, state.asBytes(), &initial_state);37 @memcpy(state.asBytes(), &initial_state);
38 state.endianSwap();38 state.endianSwap();
39 return state;39 return state;
40 }40 }
...@@ -87,7 +87,7 @@ pub fn State(comptime endian: builtin.Endian) type {...@@ -87,7 +87,7 @@ pub fn State(comptime endian: builtin.Endian) type {
87 }87 }
88 if (i < bytes.len) {88 if (i < bytes.len) {
89 var padded = [_]u8{0} ** 8;89 var padded = [_]u8{0} ** 8;
90 mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);90 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
91 self.st[i / 8] = mem.readInt(u64, padded[0..], endian);91 self.st[i / 8] = mem.readInt(u64, padded[0..], endian);
92 }92 }
93 }93 }
...@@ -109,7 +109,7 @@ pub fn State(comptime endian: builtin.Endian) type {...@@ -109,7 +109,7 @@ pub fn State(comptime endian: builtin.Endian) type {
109 }109 }
110 if (i < bytes.len) {110 if (i < bytes.len) {
111 var padded = [_]u8{0} ** 8;111 var padded = [_]u8{0} ** 8;
112 mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);112 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
113 self.st[i / 8] ^= mem.readInt(u64, padded[0..], endian);113 self.st[i / 8] ^= mem.readInt(u64, padded[0..], endian);
114 }114 }
115 }115 }
...@@ -123,7 +123,7 @@ pub fn State(comptime endian: builtin.Endian) type {...@@ -123,7 +123,7 @@ pub fn State(comptime endian: builtin.Endian) type {
123 if (i < out.len) {123 if (i < out.len) {
124 var padded = [_]u8{0} ** 8;124 var padded = [_]u8{0} ** 8;
125 mem.writeInt(u64, padded[0..], self.st[i / 8], endian);125 mem.writeInt(u64, padded[0..], self.st[i / 8], endian);
126 mem.copy(u8, out[i..], padded[0 .. out.len - i]);126 @memcpy(out[i..], padded[0 .. out.len - i]);
127 }127 }
128 }128 }
129129
...@@ -138,16 +138,16 @@ pub fn State(comptime endian: builtin.Endian) type {...@@ -138,16 +138,16 @@ pub fn State(comptime endian: builtin.Endian) type {
138 }138 }
139 if (i < in.len) {139 if (i < in.len) {
140 var padded = [_]u8{0} ** 8;140 var padded = [_]u8{0} ** 8;
141 mem.copy(u8, padded[0 .. in.len - i], in[i..]);141 @memcpy(padded[0 .. in.len - i], in[i..]);
142 const x = mem.readIntNative(u64, &padded) ^ mem.nativeTo(u64, self.st[i / 8], endian);142 const x = mem.readIntNative(u64, &padded) ^ mem.nativeTo(u64, self.st[i / 8], endian);
143 mem.writeIntNative(u64, &padded, x);143 mem.writeIntNative(u64, &padded, x);
144 mem.copy(u8, out[i..], padded[0 .. in.len - i]);144 @memcpy(out[i..], padded[0 .. in.len - i]);
145 }145 }
146 }146 }
147147
148 /// Set the words storing the bytes of a given range to zero.148 /// Set the words storing the bytes of a given range to zero.
149 pub fn clear(self: *Self, from: usize, to: usize) void {149 pub fn clear(self: *Self, from: usize, to: usize) void {
150 mem.set(u64, self.st[from / 8 .. (to + 7) / 8], 0);150 @memset(self.st[from / 8 .. (to + 7) / 8], 0);
151 }151 }
152152
153 /// Clear the entire state, disabling compiler optimizations.153 /// Clear the entire state, disabling compiler optimizations.
lib/std/crypto/bcrypt.zig+3-3
...@@ -416,8 +416,8 @@ pub fn bcrypt(...@@ -416,8 +416,8 @@ pub fn bcrypt(
416) [dk_length]u8 {416) [dk_length]u8 {
417 var state = State{};417 var state = State{};
418 var password_buf: [73]u8 = undefined;418 var password_buf: [73]u8 = undefined;
419 const trimmed_len = math.min(password.len, password_buf.len - 1);419 const trimmed_len = @min(password.len, password_buf.len - 1);
420 mem.copy(u8, password_buf[0..], password[0..trimmed_len]);420 @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]);
421 password_buf[trimmed_len] = 0;421 password_buf[trimmed_len] = 0;
422 var passwordZ = password_buf[0 .. trimmed_len + 1];422 var passwordZ = password_buf[0 .. trimmed_len + 1];
423 state.expand(salt[0..], passwordZ);423 state.expand(salt[0..], passwordZ);
...@@ -626,7 +626,7 @@ const CryptFormatHasher = struct {...@@ -626,7 +626,7 @@ const CryptFormatHasher = struct {
626 crypto.random.bytes(&salt);626 crypto.random.bytes(&salt);
627627
628 const hash = crypt_format.strHashInternal(password, salt, params);628 const hash = crypt_format.strHashInternal(password, salt, params);
629 mem.copy(u8, buf, &hash);629 @memcpy(buf[0..hash.len], &hash);
630630
631 return buf[0..pwhash_str_length];631 return buf[0..pwhash_str_length];
632 }632 }
lib/std/crypto/benchmark.zig+2-2
...@@ -113,8 +113,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c...@@ -113,8 +113,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c
113 var i: usize = 0;113 var i: usize = 0;
114 while (i < exchange_count) : (i += 1) {114 while (i < exchange_count) : (i += 1) {
115 const out = try DhKeyExchange.scalarmult(secret, public);115 const out = try DhKeyExchange.scalarmult(secret, public);
116 mem.copy(u8, secret[0..16], out[0..16]);116 secret[0..16].* = out[0..16].*;
117 mem.copy(u8, public[0..16], out[16..32]);117 public[0..16].* = out[16..32].*;
118 mem.doNotOptimizeAway(&out);118 mem.doNotOptimizeAway(&out);
119 }119 }
120 }120 }
lib/std/crypto/blake2.zig+16-14
...@@ -76,7 +76,7 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -76,7 +76,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
76 comptime debug.assert(8 <= out_bits and out_bits <= 256);76 comptime debug.assert(8 <= out_bits and out_bits <= 256);
7777
78 var d: Self = undefined;78 var d: Self = undefined;
79 mem.copy(u32, d.h[0..], iv[0..]);79 d.h = iv;
8080
81 const key_len = if (options.key) |key| key.len else 0;81 const key_len = if (options.key) |key| key.len else 0;
82 // default parameters82 // default parameters
...@@ -93,7 +93,7 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -93,7 +93,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
93 d.h[7] ^= mem.readIntLittle(u32, context[4..8]);93 d.h[7] ^= mem.readIntLittle(u32, context[4..8]);
94 }94 }
95 if (key_len > 0) {95 if (key_len > 0) {
96 mem.set(u8, d.buf[key_len..], 0);96 @memset(d.buf[key_len..], 0);
97 d.update(options.key.?);97 d.update(options.key.?);
98 d.buf_len = 64;98 d.buf_len = 64;
99 }99 }
...@@ -112,7 +112,7 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -112,7 +112,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
112 // Partial buffer exists from previous update. Copy into buffer then hash.112 // Partial buffer exists from previous update. Copy into buffer then hash.
113 if (d.buf_len != 0 and d.buf_len + b.len > 64) {113 if (d.buf_len != 0 and d.buf_len + b.len > 64) {
114 off += 64 - d.buf_len;114 off += 64 - d.buf_len;
115 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);115 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
116 d.t += 64;116 d.t += 64;
117 d.round(d.buf[0..], false);117 d.round(d.buf[0..], false);
118 d.buf_len = 0;118 d.buf_len = 0;
...@@ -125,16 +125,17 @@ pub fn Blake2s(comptime out_bits: usize) type {...@@ -125,16 +125,17 @@ pub fn Blake2s(comptime out_bits: usize) type {
125 }125 }
126126
127 // Copy any remainder for next pass.127 // Copy any remainder for next pass.
128 mem.copy(u8, d.buf[d.buf_len..], b[off..]);128 const b_slice = b[off..];
129 d.buf_len += @intCast(u8, b[off..].len);129 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
130 d.buf_len += @intCast(u8, b_slice.len);
130 }131 }
131132
132 pub fn final(d: *Self, out: *[digest_length]u8) void {133 pub fn final(d: *Self, out: *[digest_length]u8) void {
133 mem.set(u8, d.buf[d.buf_len..], 0);134 @memset(d.buf[d.buf_len..], 0);
134 d.t += d.buf_len;135 d.t += d.buf_len;
135 d.round(d.buf[0..], true);136 d.round(d.buf[0..], true);
136 for (&d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);137 for (&d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);
137 mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));138 out.* = @ptrCast(*[digest_length]u8, &d.h).*;
138 }139 }
139140
140 fn round(d: *Self, b: *const [64]u8, last: bool) void {141 fn round(d: *Self, b: *const [64]u8, last: bool) void {
...@@ -511,7 +512,7 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -511,7 +512,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
511 comptime debug.assert(8 <= out_bits and out_bits <= 512);512 comptime debug.assert(8 <= out_bits and out_bits <= 512);
512513
513 var d: Self = undefined;514 var d: Self = undefined;
514 mem.copy(u64, d.h[0..], iv[0..]);515 d.h = iv;
515516
516 const key_len = if (options.key) |key| key.len else 0;517 const key_len = if (options.key) |key| key.len else 0;
517 // default parameters518 // default parameters
...@@ -528,7 +529,7 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -528,7 +529,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
528 d.h[7] ^= mem.readIntLittle(u64, context[8..16]);529 d.h[7] ^= mem.readIntLittle(u64, context[8..16]);
529 }530 }
530 if (key_len > 0) {531 if (key_len > 0) {
531 mem.set(u8, d.buf[key_len..], 0);532 @memset(d.buf[key_len..], 0);
532 d.update(options.key.?);533 d.update(options.key.?);
533 d.buf_len = 128;534 d.buf_len = 128;
534 }535 }
...@@ -547,7 +548,7 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -547,7 +548,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
547 // Partial buffer exists from previous update. Copy into buffer then hash.548 // Partial buffer exists from previous update. Copy into buffer then hash.
548 if (d.buf_len != 0 and d.buf_len + b.len > 128) {549 if (d.buf_len != 0 and d.buf_len + b.len > 128) {
549 off += 128 - d.buf_len;550 off += 128 - d.buf_len;
550 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);551 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
551 d.t += 128;552 d.t += 128;
552 d.round(d.buf[0..], false);553 d.round(d.buf[0..], false);
553 d.buf_len = 0;554 d.buf_len = 0;
...@@ -560,16 +561,17 @@ pub fn Blake2b(comptime out_bits: usize) type {...@@ -560,16 +561,17 @@ pub fn Blake2b(comptime out_bits: usize) type {
560 }561 }
561562
562 // Copy any remainder for next pass.563 // Copy any remainder for next pass.
563 mem.copy(u8, d.buf[d.buf_len..], b[off..]);564 const b_slice = b[off..];
564 d.buf_len += @intCast(u8, b[off..].len);565 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
566 d.buf_len += @intCast(u8, b_slice.len);
565 }567 }
566568
567 pub fn final(d: *Self, out: *[digest_length]u8) void {569 pub fn final(d: *Self, out: *[digest_length]u8) void {
568 mem.set(u8, d.buf[d.buf_len..], 0);570 @memset(d.buf[d.buf_len..], 0);
569 d.t += d.buf_len;571 d.t += d.buf_len;
570 d.round(d.buf[0..], true);572 d.round(d.buf[0..], true);
571 for (&d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);573 for (&d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);
572 mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));574 out.* = @ptrCast(*[digest_length]u8, &d.h).*;
573 }575 }
574576
575 fn round(d: *Self, b: *const [128]u8, last: bool) void {577 fn round(d: *Self, b: *const [128]u8, last: bool) void {
lib/std/crypto/blake3.zig+4-4
...@@ -253,7 +253,7 @@ const Output = struct {...@@ -253,7 +253,7 @@ const Output = struct {
253 while (out_word_it.next()) |out_word| {253 while (out_word_it.next()) |out_word| {
254 var word_bytes: [4]u8 = undefined;254 var word_bytes: [4]u8 = undefined;
255 mem.writeIntLittle(u32, &word_bytes, words[word_counter]);255 mem.writeIntLittle(u32, &word_bytes, words[word_counter]);
256 mem.copy(u8, out_word, word_bytes[0..out_word.len]);256 @memcpy(out_word, word_bytes[0..out_word.len]);
257 word_counter += 1;257 word_counter += 1;
258 }258 }
259 output_block_counter += 1;259 output_block_counter += 1;
...@@ -284,7 +284,7 @@ const ChunkState = struct {...@@ -284,7 +284,7 @@ const ChunkState = struct {
284 fn fillBlockBuf(self: *ChunkState, input: []const u8) []const u8 {284 fn fillBlockBuf(self: *ChunkState, input: []const u8) []const u8 {
285 const want = BLOCK_LEN - self.block_len;285 const want = BLOCK_LEN - self.block_len;
286 const take = math.min(want, input.len);286 const take = math.min(want, input.len);
287 mem.copy(u8, self.block[self.block_len..][0..take], input[0..take]);287 @memcpy(self.block[self.block_len..][0..take], input[0..take]);
288 self.block_len += @truncate(u8, take);288 self.block_len += @truncate(u8, take);
289 return input[take..];289 return input[take..];
290 }290 }
...@@ -336,8 +336,8 @@ fn parentOutput(...@@ -336,8 +336,8 @@ fn parentOutput(
336 flags: u8,336 flags: u8,
337) Output {337) Output {
338 var block_words: [16]u32 align(16) = undefined;338 var block_words: [16]u32 align(16) = undefined;
339 mem.copy(u32, block_words[0..8], left_child_cv[0..]);339 block_words[0..8].* = left_child_cv;
340 mem.copy(u32, block_words[8..], right_child_cv[0..]);340 block_words[8..].* = right_child_cv;
341 return Output{341 return Output{
342 .input_chaining_value = key,342 .input_chaining_value = key,
343 .block_words = block_words,343 .block_words = block_words,
lib/std/crypto/chacha20.zig+4-4
...@@ -211,7 +211,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type {...@@ -211,7 +211,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type {
211211
212 var buf: [64]u8 = undefined;212 var buf: [64]u8 = undefined;
213 hashToBytes(buf[0..], x);213 hashToBytes(buf[0..], x);
214 mem.copy(u8, out[i..], buf[0 .. out.len - i]);214 @memcpy(out[i..], buf[0 .. out.len - i]);
215 }215 }
216 }216 }
217217
...@@ -372,7 +372,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {...@@ -372,7 +372,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
372372
373 var buf: [64]u8 = undefined;373 var buf: [64]u8 = undefined;
374 hashToBytes(buf[0..], x);374 hashToBytes(buf[0..], x);
375 mem.copy(u8, out[i..], buf[0 .. out.len - i]);375 @memcpy(out[i..], buf[0 .. out.len - i]);
376 }376 }
377 }377 }
378378
...@@ -413,8 +413,8 @@ fn keyToWords(key: [32]u8) [8]u32 {...@@ -413,8 +413,8 @@ fn keyToWords(key: [32]u8) [8]u32 {
413413
414fn extend(key: [32]u8, nonce: [24]u8, comptime rounds_nb: usize) struct { key: [32]u8, nonce: [12]u8 } {414fn extend(key: [32]u8, nonce: [24]u8, comptime rounds_nb: usize) struct { key: [32]u8, nonce: [12]u8 } {
415 var subnonce: [12]u8 = undefined;415 var subnonce: [12]u8 = undefined;
416 mem.set(u8, subnonce[0..4], 0);416 @memset(subnonce[0..4], 0);
417 mem.copy(u8, subnonce[4..], nonce[16..24]);417 subnonce[4..].* = nonce[16..24].*;
418 return .{418 return .{
419 .key = ChaChaImpl(rounds_nb).hchacha20(nonce[0..16].*, key),419 .key = ChaChaImpl(rounds_nb).hchacha20(nonce[0..16].*, key),
420 .nonce = subnonce,420 .nonce = subnonce,
lib/std/crypto/ecdsa.zig+9-11
...@@ -102,8 +102,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {...@@ -102,8 +102,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
102 /// Return the raw signature (r, s) in big-endian format.102 /// Return the raw signature (r, s) in big-endian format.
103 pub fn toBytes(self: Signature) [encoded_length]u8 {103 pub fn toBytes(self: Signature) [encoded_length]u8 {
104 var bytes: [encoded_length]u8 = undefined;104 var bytes: [encoded_length]u8 = undefined;
105 mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);105 @memcpy(bytes[0 .. encoded_length / 2], &self.r);
106 mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);106 @memcpy(bytes[encoded_length / 2 ..], &self.s);
107 return bytes;107 return bytes;
108 }108 }
109109
...@@ -325,11 +325,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {...@@ -325,11 +325,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
325 fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar {325 fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar {
326 if (unreduced_len >= 48) {326 if (unreduced_len >= 48) {
327 var xs = [_]u8{0} ** 64;327 var xs = [_]u8{0} ** 64;
328 mem.copy(u8, xs[xs.len - s.len ..], s[0..]);328 @memcpy(xs[xs.len - s.len ..], s[0..]);
329 return Curve.scalar.Scalar.fromBytes64(xs, .Big);329 return Curve.scalar.Scalar.fromBytes64(xs, .Big);
330 }330 }
331 var xs = [_]u8{0} ** 48;331 var xs = [_]u8{0} ** 48;
332 mem.copy(u8, xs[xs.len - s.len ..], s[0..]);332 @memcpy(xs[xs.len - s.len ..], s[0..]);
333 return Curve.scalar.Scalar.fromBytes48(xs, .Big);333 return Curve.scalar.Scalar.fromBytes48(xs, .Big);
334 }334 }
335335
...@@ -345,14 +345,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {...@@ -345,14 +345,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
345 const m_x = m[m_v.len + 1 + noise_length ..][0..secret_key.len];345 const m_x = m[m_v.len + 1 + noise_length ..][0..secret_key.len];
346 const m_h = m[m.len - h.len ..];346 const m_h = m[m.len - h.len ..];
347347
348 mem.set(u8, m_v, 0x01);348 @memset(m_v, 0x01);
349 m_i.* = 0x00;349 m_i.* = 0x00;
350 if (noise) |n| mem.copy(u8, m_z, &n);350 if (noise) |n| @memcpy(m_z, &n);
351 mem.copy(u8, m_x, &secret_key);351 @memcpy(m_x, &secret_key);
352 mem.copy(u8, m_h, &h);352 @memcpy(m_h, &h);
353 Hmac.create(&k, &m, &k);353 Hmac.create(&k, &m, &k);
354 Hmac.create(m_v, m_v, &k);354 Hmac.create(m_v, m_v, &k);
355 mem.copy(u8, m_v, m_v);
356 m_i.* = 0x01;355 m_i.* = 0x01;
357 Hmac.create(&k, &m, &k);356 Hmac.create(&k, &m, &k);
358 Hmac.create(m_v, m_v, &k);357 Hmac.create(m_v, m_v, &k);
...@@ -361,10 +360,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {...@@ -361,10 +360,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
361 while (t_off < t.len) : (t_off += m_v.len) {360 while (t_off < t.len) : (t_off += m_v.len) {
362 const t_end = @min(t_off + m_v.len, t.len);361 const t_end = @min(t_off + m_v.len, t.len);
363 Hmac.create(m_v, m_v, &k);362 Hmac.create(m_v, m_v, &k);
364 std.mem.copy(u8, t[t_off..t_end], m_v[0 .. t_end - t_off]);363 @memcpy(t[t_off..t_end], m_v[0 .. t_end - t_off]);
365 }364 }
366 if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {}365 if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {}
367 mem.copy(u8, m_v, m_v);
368 m_i.* = 0x00;366 m_i.* = 0x00;
369 Hmac.create(&k, m[0 .. m_v.len + 1], &k);367 Hmac.create(&k, m[0 .. m_v.len + 1], &k);
370 Hmac.create(m_v, m_v, &k);368 Hmac.create(m_v, m_v, &k);
lib/std/crypto/hkdf.zig+1-1
...@@ -63,7 +63,7 @@ pub fn Hkdf(comptime Hmac: type) type {...@@ -63,7 +63,7 @@ pub fn Hkdf(comptime Hmac: type) type {
63 st.update(&counter);63 st.update(&counter);
64 var tmp: [prk_length]u8 = undefined;64 var tmp: [prk_length]u8 = undefined;
65 st.final(tmp[0..prk_length]);65 st.final(tmp[0..prk_length]);
66 mem.copy(u8, out[i..][0..left], tmp[0..left]);66 @memcpy(out[i..][0..left], tmp[0..left]);
67 }67 }
68 }68 }
69 };69 };
lib/std/crypto/hmac.zig+4-4
...@@ -38,12 +38,12 @@ pub fn Hmac(comptime Hash: type) type {...@@ -38,12 +38,12 @@ pub fn Hmac(comptime Hash: type) type {
38 // Normalize key length to block size of hash38 // Normalize key length to block size of hash
39 if (key.len > Hash.block_length) {39 if (key.len > Hash.block_length) {
40 Hash.hash(key, scratch[0..mac_length], .{});40 Hash.hash(key, scratch[0..mac_length], .{});
41 mem.set(u8, scratch[mac_length..Hash.block_length], 0);41 @memset(scratch[mac_length..Hash.block_length], 0);
42 } else if (key.len < Hash.block_length) {42 } else if (key.len < Hash.block_length) {
43 mem.copy(u8, scratch[0..key.len], key);43 @memcpy(scratch[0..key.len], key);
44 mem.set(u8, scratch[key.len..Hash.block_length], 0);44 @memset(scratch[key.len..Hash.block_length], 0);
45 } else {45 } else {
46 mem.copy(u8, scratch[0..], key);46 @memcpy(&scratch, key);
47 }47 }
4848
49 for (&ctx.o_key_pad, 0..) |*b, i| {49 for (&ctx.o_key_pad, 0..) |*b, i| {
lib/std/crypto/isap.zig+1-1
...@@ -43,7 +43,7 @@ pub const IsapA128A = struct {...@@ -43,7 +43,7 @@ pub const IsapA128A = struct {
43 }43 }
44 } else {44 } else {
45 var padded = [_]u8{0} ** 8;45 var padded = [_]u8{0} ** 8;
46 mem.copy(u8, padded[0..left], m[i..]);46 @memcpy(padded[0..left], m[i..]);
47 padded[left] = 0x80;47 padded[left] = 0x80;
48 isap.st.addBytes(&padded);48 isap.st.addBytes(&padded);
49 isap.st.permute();49 isap.st.permute();
lib/std/crypto/keccak_p.zig+8-8
...@@ -68,7 +68,7 @@ pub fn KeccakF(comptime f: u11) type {...@@ -68,7 +68,7 @@ pub fn KeccakF(comptime f: u11) type {
68 }68 }
69 if (i < bytes.len) {69 if (i < bytes.len) {
70 var padded = [_]u8{0} ** @sizeOf(T);70 var padded = [_]u8{0} ** @sizeOf(T);
71 mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);71 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
72 self.st[i / @sizeOf(T)] = mem.readIntLittle(T, padded[0..]);72 self.st[i / @sizeOf(T)] = mem.readIntLittle(T, padded[0..]);
73 }73 }
74 }74 }
...@@ -87,7 +87,7 @@ pub fn KeccakF(comptime f: u11) type {...@@ -87,7 +87,7 @@ pub fn KeccakF(comptime f: u11) type {
87 }87 }
88 if (i < bytes.len) {88 if (i < bytes.len) {
89 var padded = [_]u8{0} ** @sizeOf(T);89 var padded = [_]u8{0} ** @sizeOf(T);
90 mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);90 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
91 self.st[i / @sizeOf(T)] ^= mem.readIntLittle(T, padded[0..]);91 self.st[i / @sizeOf(T)] ^= mem.readIntLittle(T, padded[0..]);
92 }92 }
93 }93 }
...@@ -101,7 +101,7 @@ pub fn KeccakF(comptime f: u11) type {...@@ -101,7 +101,7 @@ pub fn KeccakF(comptime f: u11) type {
101 if (i < out.len) {101 if (i < out.len) {
102 var padded = [_]u8{0} ** @sizeOf(T);102 var padded = [_]u8{0} ** @sizeOf(T);
103 mem.writeIntLittle(T, padded[0..], self.st[i / @sizeOf(T)]);103 mem.writeIntLittle(T, padded[0..], self.st[i / @sizeOf(T)]);
104 mem.copy(u8, out[i..], padded[0 .. out.len - i]);104 @memcpy(out[i..], padded[0 .. out.len - i]);
105 }105 }
106 }106 }
107107
...@@ -116,16 +116,16 @@ pub fn KeccakF(comptime f: u11) type {...@@ -116,16 +116,16 @@ pub fn KeccakF(comptime f: u11) type {
116 }116 }
117 if (i < in.len) {117 if (i < in.len) {
118 var padded = [_]u8{0} ** @sizeOf(T);118 var padded = [_]u8{0} ** @sizeOf(T);
119 mem.copy(u8, padded[0 .. in.len - i], in[i..]);119 @memcpy(padded[0 .. in.len - i], in[i..]);
120 const x = mem.readIntNative(T, &padded) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);120 const x = mem.readIntNative(T, &padded) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
121 mem.writeIntNative(T, &padded, x);121 mem.writeIntNative(T, &padded, x);
122 mem.copy(u8, out[i..], padded[0 .. in.len - i]);122 @memcpy(out[i..], padded[0 .. in.len - i]);
123 }123 }
124 }124 }
125125
126 /// Set the words storing the bytes of a given range to zero.126 /// Set the words storing the bytes of a given range to zero.
127 pub fn clear(self: *Self, from: usize, to: usize) void {127 pub fn clear(self: *Self, from: usize, to: usize) void {
128 mem.set(T, self.st[from / @sizeOf(T) .. (to + @sizeOf(T) - 1) / @sizeOf(T)], 0);128 @memset(self.st[from / @sizeOf(T) .. (to + @sizeOf(T) - 1) / @sizeOf(T)], 0);
129 }129 }
130130
131 /// Clear the entire state, disabling compiler optimizations.131 /// Clear the entire state, disabling compiler optimizations.
...@@ -215,7 +215,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti...@@ -215,7 +215,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
215 var bytes = bytes_;215 var bytes = bytes_;
216 if (self.offset > 0) {216 if (self.offset > 0) {
217 const left = math.min(rate - self.offset, bytes.len);217 const left = math.min(rate - self.offset, bytes.len);
218 mem.copy(u8, self.buf[self.offset..], bytes[0..left]);218 @memcpy(self.buf[self.offset..][0..left], bytes[0..left]);
219 self.offset += left;219 self.offset += left;
220 if (self.offset == rate) {220 if (self.offset == rate) {
221 self.offset = 0;221 self.offset = 0;
...@@ -231,7 +231,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti...@@ -231,7 +231,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
231 bytes = bytes[rate..];231 bytes = bytes[rate..];
232 }232 }
233 if (bytes.len > 0) {233 if (bytes.len > 0) {
234 mem.copy(u8, &self.buf, bytes);234 @memcpy(self.buf[0..bytes.len], bytes);
235 self.offset = bytes.len;235 self.offset = bytes.len;
236 }236 }
237 }237 }
lib/std/crypto/kyber_d00.zig+1-1
...@@ -1479,7 +1479,7 @@ test "MulHat" {...@@ -1479,7 +1479,7 @@ test "MulHat" {
1479 const p2 = a.ntt().mulHat(b.ntt()).barrettReduce().invNTT().normalize();1479 const p2 = a.ntt().mulHat(b.ntt()).barrettReduce().invNTT().normalize();
1480 var p: Poly = undefined;1480 var p: Poly = undefined;
14811481
1482 mem.set(i16, &p.cs, 0);1482 @memset(&p.cs, 0);
14831483
1484 for (0..N) |i| {1484 for (0..N) |i| {
1485 for (0..N) |j| {1485 for (0..N) |j| {
lib/std/crypto/md5.zig+6-5
...@@ -66,7 +66,7 @@ pub const Md5 = struct {...@@ -66,7 +66,7 @@ pub const Md5 = struct {
66 // Partial buffer exists from previous update. Copy into buffer then hash.66 // Partial buffer exists from previous update. Copy into buffer then hash.
67 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {67 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
68 off += 64 - d.buf_len;68 off += 64 - d.buf_len;
69 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);69 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
7070
71 d.round(&d.buf);71 d.round(&d.buf);
72 d.buf_len = 0;72 d.buf_len = 0;
...@@ -78,8 +78,9 @@ pub const Md5 = struct {...@@ -78,8 +78,9 @@ pub const Md5 = struct {
78 }78 }
7979
80 // Copy any remainder for next pass.80 // Copy any remainder for next pass.
81 mem.copy(u8, d.buf[d.buf_len..], b[off..]);81 const b_slice = b[off..];
82 d.buf_len += @intCast(u8, b[off..].len);82 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
83 d.buf_len += @intCast(u8, b_slice.len);
8384
84 // Md5 uses the bottom 64-bits for length padding85 // Md5 uses the bottom 64-bits for length padding
85 d.total_len +%= b.len;86 d.total_len +%= b.len;
...@@ -87,7 +88,7 @@ pub const Md5 = struct {...@@ -87,7 +88,7 @@ pub const Md5 = struct {
8788
88 pub fn final(d: *Self, out: *[digest_length]u8) void {89 pub fn final(d: *Self, out: *[digest_length]u8) void {
89 // The buffer here will never be completely full.90 // The buffer here will never be completely full.
90 mem.set(u8, d.buf[d.buf_len..], 0);91 @memset(d.buf[d.buf_len..], 0);
9192
92 // Append padding bits.93 // Append padding bits.
93 d.buf[d.buf_len] = 0x80;94 d.buf[d.buf_len] = 0x80;
...@@ -96,7 +97,7 @@ pub const Md5 = struct {...@@ -96,7 +97,7 @@ pub const Md5 = struct {
96 // > 448 mod 512 so need to add an extra round to wrap around.97 // > 448 mod 512 so need to add an extra round to wrap around.
97 if (64 - d.buf_len < 8) {98 if (64 - d.buf_len < 8) {
98 d.round(d.buf[0..]);99 d.round(d.buf[0..]);
99 mem.set(u8, d.buf[0..], 0);100 @memset(d.buf[0..], 0);
100 }101 }
101102
102 // Append message length.103 // Append message length.
lib/std/crypto/modes.zig+4-2
...@@ -38,8 +38,10 @@ pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8,...@@ -38,8 +38,10 @@ pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8,
38 if (i < src.len) {38 if (i < src.len) {
39 mem.writeInt(u128, &counter, counterInt, endian);39 mem.writeInt(u128, &counter, counterInt, endian);
40 var pad = [_]u8{0} ** block_length;40 var pad = [_]u8{0} ** block_length;
41 mem.copy(u8, &pad, src[i..]);41 const src_slice = src[i..];
42 @memcpy(pad[0..src_slice.len], src_slice);
42 block_cipher.xor(&pad, &pad, counter);43 block_cipher.xor(&pad, &pad, counter);
43 mem.copy(u8, dst[i..], pad[0 .. src.len - i]);44 const pad_slice = pad[0 .. src.len - i];
45 @memcpy(dst[i..][0..pad_slice.len], pad_slice);
44 }46 }
45}47}
lib/std/crypto/pbkdf2.zig+2-2
...@@ -129,13 +129,13 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com...@@ -129,13 +129,13 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com
129 const offset = block * h_len;129 const offset = block * h_len;
130 const block_len = if (block != blocks_count - 1) h_len else r;130 const block_len = if (block != blocks_count - 1) h_len else r;
131 const dk_block: []u8 = dk[offset..][0..block_len];131 const dk_block: []u8 = dk[offset..][0..block_len];
132 mem.copy(u8, dk_block, prev_block[0..dk_block.len]);132 @memcpy(dk_block, prev_block[0..dk_block.len]);
133133
134 var i: u32 = 1;134 var i: u32 = 1;
135 while (i < rounds) : (i += 1) {135 while (i < rounds) : (i += 1) {
136 // U_c = PRF (P, U_{c-1})136 // U_c = PRF (P, U_{c-1})
137 Prf.create(&new_block, prev_block[0..], password);137 Prf.create(&new_block, prev_block[0..], password);
138 mem.copy(u8, prev_block[0..], new_block[0..]);138 prev_block = new_block;
139139
140 // F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c140 // F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c
141 for (dk_block, 0..) |_, j| {141 for (dk_block, 0..) |_, j| {
lib/std/crypto/pcurves/common.zig+2-2
...@@ -228,8 +228,8 @@ pub fn Field(comptime params: FieldParams) type {...@@ -228,8 +228,8 @@ pub fn Field(comptime params: FieldParams) type {
228 }228 }
229 if (iterations % 2 != 0) {229 if (iterations % 2 != 0) {
230 fiat.divstep(&out1, &out2, &out3, &out4, &out5, d, f, g, v, r);230 fiat.divstep(&out1, &out2, &out3, &out4, &out5, d, f, g, v, r);
231 mem.copy(Word, &v, &out4);231 v = out4;
232 mem.copy(Word, &f, &out2);232 f = out2;
233 }233 }
234 var v_opp: Limbs = undefined;234 var v_opp: Limbs = undefined;
235 fiat.opp(&v_opp, v);235 fiat.opp(&v_opp, v);
lib/std/crypto/pcurves/p256.zig+3-3
...@@ -105,7 +105,7 @@ pub const P256 = struct {...@@ -105,7 +105,7 @@ pub const P256 = struct {
105 var out: [33]u8 = undefined;105 var out: [33]u8 = undefined;
106 const xy = p.affineCoordinates();106 const xy = p.affineCoordinates();
107 out[0] = if (xy.y.isOdd()) 3 else 2;107 out[0] = if (xy.y.isOdd()) 3 else 2;
108 mem.copy(u8, out[1..], &xy.x.toBytes(.Big));108 out[1..].* = xy.x.toBytes(.Big);
109 return out;109 return out;
110 }110 }
111111
...@@ -114,8 +114,8 @@ pub const P256 = struct {...@@ -114,8 +114,8 @@ pub const P256 = struct {
114 var out: [65]u8 = undefined;114 var out: [65]u8 = undefined;
115 out[0] = 4;115 out[0] = 4;
116 const xy = p.affineCoordinates();116 const xy = p.affineCoordinates();
117 mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));117 out[1..33].* = xy.x.toBytes(.Big);
118 mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));118 out[33..65].* = xy.y.toBytes(.Big);
119 return out;119 return out;
120 }120 }
121121
lib/std/crypto/pcurves/p256/scalar.zig+5-5
...@@ -192,20 +192,20 @@ const ScalarDouble = struct {...@@ -192,20 +192,20 @@ const ScalarDouble = struct {
192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
193 {193 {
194 var b = [_]u8{0} ** encoded_length;194 var b = [_]u8{0} ** encoded_length;
195 const len = math.min(s.len, 24);195 const len = @min(s.len, 24);
196 mem.copy(u8, b[0..len], s[0..len]);196 b[0..len].* = s[0..len].*;
197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
198 }198 }
199 if (s_.len >= 24) {199 if (s_.len >= 24) {
200 var b = [_]u8{0} ** encoded_length;200 var b = [_]u8{0} ** encoded_length;
201 const len = math.min(s.len - 24, 24);201 const len = @min(s.len - 24, 24);
202 mem.copy(u8, b[0..len], s[24..][0..len]);202 b[0..len].* = s[24..][0..len].*;
203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
204 }204 }
205 if (s_.len >= 48) {205 if (s_.len >= 48) {
206 var b = [_]u8{0} ** encoded_length;206 var b = [_]u8{0} ** encoded_length;
207 const len = s.len - 48;207 const len = s.len - 48;
208 mem.copy(u8, b[0..len], s[48..][0..len]);208 b[0..len].* = s[48..][0..len].*;
209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
210 }210 }
211 return t;211 return t;
lib/std/crypto/pcurves/p384.zig+3-3
...@@ -105,7 +105,7 @@ pub const P384 = struct {...@@ -105,7 +105,7 @@ pub const P384 = struct {
105 var out: [49]u8 = undefined;105 var out: [49]u8 = undefined;
106 const xy = p.affineCoordinates();106 const xy = p.affineCoordinates();
107 out[0] = if (xy.y.isOdd()) 3 else 2;107 out[0] = if (xy.y.isOdd()) 3 else 2;
108 mem.copy(u8, out[1..], &xy.x.toBytes(.Big));108 out[1..].* = xy.x.toBytes(.Big);
109 return out;109 return out;
110 }110 }
111111
...@@ -114,8 +114,8 @@ pub const P384 = struct {...@@ -114,8 +114,8 @@ pub const P384 = struct {
114 var out: [97]u8 = undefined;114 var out: [97]u8 = undefined;
115 out[0] = 4;115 out[0] = 4;
116 const xy = p.affineCoordinates();116 const xy = p.affineCoordinates();
117 mem.copy(u8, out[1..49], &xy.x.toBytes(.Big));117 out[1..49].* = xy.x.toBytes(.Big);
118 mem.copy(u8, out[49..97], &xy.y.toBytes(.Big));118 out[49..97].* = xy.y.toBytes(.Big);
119 return out;119 return out;
120 }120 }
121121
lib/std/crypto/pcurves/p384/scalar.zig+4-4
...@@ -180,14 +180,14 @@ const ScalarDouble = struct {...@@ -180,14 +180,14 @@ const ScalarDouble = struct {
180 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };180 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };
181 {181 {
182 var b = [_]u8{0} ** encoded_length;182 var b = [_]u8{0} ** encoded_length;
183 const len = math.min(s.len, 32);183 const len = @min(s.len, 32);
184 mem.copy(u8, b[0..len], s[0..len]);184 b[0..len].* = s[0..len].*;
185 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;185 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
186 }186 }
187 if (s_.len >= 32) {187 if (s_.len >= 32) {
188 var b = [_]u8{0} ** encoded_length;188 var b = [_]u8{0} ** encoded_length;
189 const len = math.min(s.len - 32, 32);189 const len = @min(s.len - 32, 32);
190 mem.copy(u8, b[0..len], s[32..][0..len]);190 b[0..len].* = s[32..][0..len].*;
191 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;191 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
192 }192 }
193 return t;193 return t;
lib/std/crypto/pcurves/secp256k1.zig+3-3
...@@ -158,7 +158,7 @@ pub const Secp256k1 = struct {...@@ -158,7 +158,7 @@ pub const Secp256k1 = struct {
158 var out: [33]u8 = undefined;158 var out: [33]u8 = undefined;
159 const xy = p.affineCoordinates();159 const xy = p.affineCoordinates();
160 out[0] = if (xy.y.isOdd()) 3 else 2;160 out[0] = if (xy.y.isOdd()) 3 else 2;
161 mem.copy(u8, out[1..], &xy.x.toBytes(.Big));161 out[1..].* = xy.x.toBytes(.Big);
162 return out;162 return out;
163 }163 }
164164
...@@ -167,8 +167,8 @@ pub const Secp256k1 = struct {...@@ -167,8 +167,8 @@ pub const Secp256k1 = struct {
167 var out: [65]u8 = undefined;167 var out: [65]u8 = undefined;
168 out[0] = 4;168 out[0] = 4;
169 const xy = p.affineCoordinates();169 const xy = p.affineCoordinates();
170 mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));170 out[1..33].* = xy.x.toBytes(.Big);
171 mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));171 out[33..65].* = xy.y.toBytes(.Big);
172 return out;172 return out;
173 }173 }
174174
lib/std/crypto/pcurves/secp256k1/scalar.zig+5-5
...@@ -192,20 +192,20 @@ const ScalarDouble = struct {...@@ -192,20 +192,20 @@ const ScalarDouble = struct {
192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
193 {193 {
194 var b = [_]u8{0} ** encoded_length;194 var b = [_]u8{0} ** encoded_length;
195 const len = math.min(s.len, 24);195 const len = @min(s.len, 24);
196 mem.copy(u8, b[0..len], s[0..len]);196 b[0..len].* = s[0..len].*;
197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
198 }198 }
199 if (s_.len >= 24) {199 if (s_.len >= 24) {
200 var b = [_]u8{0} ** encoded_length;200 var b = [_]u8{0} ** encoded_length;
201 const len = math.min(s.len - 24, 24);201 const len = @min(s.len - 24, 24);
202 mem.copy(u8, b[0..len], s[24..][0..len]);202 b[0..len].* = s[24..][0..len].*;
203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
204 }204 }
205 if (s_.len >= 48) {205 if (s_.len >= 48) {
206 var b = [_]u8{0} ** encoded_length;206 var b = [_]u8{0} ** encoded_length;
207 const len = s.len - 48;207 const len = s.len - 48;
208 mem.copy(u8, b[0..len], s[48..][0..len]);208 b[0..len].* = s[48..][0..len].*;
209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
210 }210 }
211 return t;211 return t;
lib/std/crypto/phc_encoding.zig+1-1
...@@ -35,7 +35,7 @@ pub fn BinValue(comptime max_len: usize) type {...@@ -35,7 +35,7 @@ pub fn BinValue(comptime max_len: usize) type {
35 pub fn fromSlice(slice: []const u8) Error!Self {35 pub fn fromSlice(slice: []const u8) Error!Self {
36 if (slice.len > capacity) return Error.NoSpaceLeft;36 if (slice.len > capacity) return Error.NoSpaceLeft;
37 var bin_value: Self = undefined;37 var bin_value: Self = undefined;
38 mem.copy(u8, &bin_value.buf, slice);38 @memcpy(bin_value.buf[0..slice.len], slice);
39 bin_value.len = slice.len;39 bin_value.len = slice.len;
40 return bin_value;40 return bin_value;
41 }41 }
lib/std/crypto/salsa20.zig+6-6
...@@ -383,10 +383,10 @@ pub const XSalsa20Poly1305 = struct {...@@ -383,10 +383,10 @@ pub const XSalsa20Poly1305 = struct {
383 debug.assert(c.len == m.len);383 debug.assert(c.len == m.len);
384 const extended = extend(rounds, k, npub);384 const extended = extend(rounds, k, npub);
385 var block0 = [_]u8{0} ** 64;385 var block0 = [_]u8{0} ** 64;
386 const mlen0 = math.min(32, m.len);386 const mlen0 = @min(32, m.len);
387 mem.copy(u8, block0[32..][0..mlen0], m[0..mlen0]);387 @memcpy(block0[32..][0..mlen0], m[0..mlen0]);
388 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);388 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
389 mem.copy(u8, c[0..mlen0], block0[32..][0..mlen0]);389 @memcpy(c[0..mlen0], block0[32..][0..mlen0]);
390 Salsa20.xor(c[mlen0..], m[mlen0..], 1, extended.key, extended.nonce);390 Salsa20.xor(c[mlen0..], m[mlen0..], 1, extended.key, extended.nonce);
391 var mac = Poly1305.init(block0[0..32]);391 var mac = Poly1305.init(block0[0..32]);
392 mac.update(ad);392 mac.update(ad);
...@@ -405,7 +405,7 @@ pub const XSalsa20Poly1305 = struct {...@@ -405,7 +405,7 @@ pub const XSalsa20Poly1305 = struct {
405 const extended = extend(rounds, k, npub);405 const extended = extend(rounds, k, npub);
406 var block0 = [_]u8{0} ** 64;406 var block0 = [_]u8{0} ** 64;
407 const mlen0 = math.min(32, c.len);407 const mlen0 = math.min(32, c.len);
408 mem.copy(u8, block0[32..][0..mlen0], c[0..mlen0]);408 @memcpy(block0[32..][0..mlen0], c[0..mlen0]);
409 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);409 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
410 var mac = Poly1305.init(block0[0..32]);410 var mac = Poly1305.init(block0[0..32]);
411 mac.update(ad);411 mac.update(ad);
...@@ -420,7 +420,7 @@ pub const XSalsa20Poly1305 = struct {...@@ -420,7 +420,7 @@ pub const XSalsa20Poly1305 = struct {
420 utils.secureZero(u8, &computedTag);420 utils.secureZero(u8, &computedTag);
421 return error.AuthenticationFailed;421 return error.AuthenticationFailed;
422 }422 }
423 mem.copy(u8, m[0..mlen0], block0[32..][0..mlen0]);423 @memcpy(m[0..mlen0], block0[32..][0..mlen0]);
424 Salsa20.xor(m[mlen0..], c[mlen0..], 1, extended.key, extended.nonce);424 Salsa20.xor(m[mlen0..], c[mlen0..], 1, extended.key, extended.nonce);
425 }425 }
426};426};
...@@ -533,7 +533,7 @@ pub const SealedBox = struct {...@@ -533,7 +533,7 @@ pub const SealedBox = struct {
533 debug.assert(c.len == m.len + seal_length);533 debug.assert(c.len == m.len + seal_length);
534 var ekp = try KeyPair.create(null);534 var ekp = try KeyPair.create(null);
535 const nonce = createNonce(ekp.public_key, public_key);535 const nonce = createNonce(ekp.public_key, public_key);
536 mem.copy(u8, c[0..public_length], ekp.public_key[0..]);536 c[0..public_length].* = ekp.public_key;
537 try Box.seal(c[Box.public_length..], m, nonce, public_key, ekp.secret_key);537 try Box.seal(c[Box.public_length..], m, nonce, public_key, ekp.secret_key);
538 utils.secureZero(u8, ekp.secret_key[0..]);538 utils.secureZero(u8, ekp.secret_key[0..]);
539 }539 }
lib/std/crypto/sha1.zig+4-4
...@@ -62,7 +62,7 @@ pub const Sha1 = struct {...@@ -62,7 +62,7 @@ pub const Sha1 = struct {
62 // Partial buffer exists from previous update. Copy into buffer then hash.62 // Partial buffer exists from previous update. Copy into buffer then hash.
63 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {63 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
64 off += 64 - d.buf_len;64 off += 64 - d.buf_len;
65 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);65 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
6666
67 d.round(d.buf[0..]);67 d.round(d.buf[0..]);
68 d.buf_len = 0;68 d.buf_len = 0;
...@@ -74,7 +74,7 @@ pub const Sha1 = struct {...@@ -74,7 +74,7 @@ pub const Sha1 = struct {
74 }74 }
7575
76 // Copy any remainder for next pass.76 // Copy any remainder for next pass.
77 mem.copy(u8, d.buf[d.buf_len..], b[off..]);77 @memcpy(d.buf[d.buf_len..][0 .. b.len - off], b[off..]);
78 d.buf_len += @intCast(u8, b[off..].len);78 d.buf_len += @intCast(u8, b[off..].len);
7979
80 d.total_len += b.len;80 d.total_len += b.len;
...@@ -82,7 +82,7 @@ pub const Sha1 = struct {...@@ -82,7 +82,7 @@ pub const Sha1 = struct {
8282
83 pub fn final(d: *Self, out: *[digest_length]u8) void {83 pub fn final(d: *Self, out: *[digest_length]u8) void {
84 // The buffer here will never be completely full.84 // The buffer here will never be completely full.
85 mem.set(u8, d.buf[d.buf_len..], 0);85 @memset(d.buf[d.buf_len..], 0);
8686
87 // Append padding bits.87 // Append padding bits.
88 d.buf[d.buf_len] = 0x80;88 d.buf[d.buf_len] = 0x80;
...@@ -91,7 +91,7 @@ pub const Sha1 = struct {...@@ -91,7 +91,7 @@ pub const Sha1 = struct {
91 // > 448 mod 512 so need to add an extra round to wrap around.91 // > 448 mod 512 so need to add an extra round to wrap around.
92 if (64 - d.buf_len < 8) {92 if (64 - d.buf_len < 8) {
93 d.round(d.buf[0..]);93 d.round(d.buf[0..]);
94 mem.set(u8, d.buf[0..], 0);94 @memset(d.buf[0..], 0);
95 }95 }
9696
97 // Append message length.97 // Append message length.
lib/std/crypto/sha2.zig+10-8
...@@ -118,7 +118,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -118,7 +118,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
118 // Partial buffer exists from previous update. Copy into buffer then hash.118 // Partial buffer exists from previous update. Copy into buffer then hash.
119 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {119 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
120 off += 64 - d.buf_len;120 off += 64 - d.buf_len;
121 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);121 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
122122
123 d.round(&d.buf);123 d.round(&d.buf);
124 d.buf_len = 0;124 d.buf_len = 0;
...@@ -130,7 +130,8 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -130,7 +130,8 @@ fn Sha2x32(comptime params: Sha2Params32) type {
130 }130 }
131131
132 // Copy any remainder for next pass.132 // Copy any remainder for next pass.
133 mem.copy(u8, d.buf[d.buf_len..], b[off..]);133 const b_slice = b[off..];
134 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
134 d.buf_len += @intCast(u8, b[off..].len);135 d.buf_len += @intCast(u8, b[off..].len);
135136
136 d.total_len += b.len;137 d.total_len += b.len;
...@@ -143,7 +144,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -143,7 +144,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
143144
144 pub fn final(d: *Self, out: *[digest_length]u8) void {145 pub fn final(d: *Self, out: *[digest_length]u8) void {
145 // The buffer here will never be completely full.146 // The buffer here will never be completely full.
146 mem.set(u8, d.buf[d.buf_len..], 0);147 @memset(d.buf[d.buf_len..], 0);
147148
148 // Append padding bits.149 // Append padding bits.
149 d.buf[d.buf_len] = 0x80;150 d.buf[d.buf_len] = 0x80;
...@@ -152,7 +153,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -152,7 +153,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
152 // > 448 mod 512 so need to add an extra round to wrap around.153 // > 448 mod 512 so need to add an extra round to wrap around.
153 if (64 - d.buf_len < 8) {154 if (64 - d.buf_len < 8) {
154 d.round(&d.buf);155 d.round(&d.buf);
155 mem.set(u8, d.buf[0..], 0);156 @memset(d.buf[0..], 0);
156 }157 }
157158
158 // Append message length.159 // Append message length.
...@@ -609,7 +610,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -609,7 +610,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
609 // Partial buffer exists from previous update. Copy into buffer then hash.610 // Partial buffer exists from previous update. Copy into buffer then hash.
610 if (d.buf_len != 0 and d.buf_len + b.len >= 128) {611 if (d.buf_len != 0 and d.buf_len + b.len >= 128) {
611 off += 128 - d.buf_len;612 off += 128 - d.buf_len;
612 mem.copy(u8, d.buf[d.buf_len..], b[0..off]);613 @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
613614
614 d.round(&d.buf);615 d.round(&d.buf);
615 d.buf_len = 0;616 d.buf_len = 0;
...@@ -621,7 +622,8 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -621,7 +622,8 @@ fn Sha2x64(comptime params: Sha2Params64) type {
621 }622 }
622623
623 // Copy any remainder for next pass.624 // Copy any remainder for next pass.
624 mem.copy(u8, d.buf[d.buf_len..], b[off..]);625 const b_slice = b[off..];
626 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
625 d.buf_len += @intCast(u8, b[off..].len);627 d.buf_len += @intCast(u8, b[off..].len);
626628
627 d.total_len += b.len;629 d.total_len += b.len;
...@@ -634,7 +636,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -634,7 +636,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
634636
635 pub fn final(d: *Self, out: *[digest_length]u8) void {637 pub fn final(d: *Self, out: *[digest_length]u8) void {
636 // The buffer here will never be completely full.638 // The buffer here will never be completely full.
637 mem.set(u8, d.buf[d.buf_len..], 0);639 @memset(d.buf[d.buf_len..], 0);
638640
639 // Append padding bits.641 // Append padding bits.
640 d.buf[d.buf_len] = 0x80;642 d.buf[d.buf_len] = 0x80;
...@@ -643,7 +645,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {...@@ -643,7 +645,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
643 // > 896 mod 1024 so need to add an extra round to wrap around.645 // > 896 mod 1024 so need to add an extra round to wrap around.
644 if (128 - d.buf_len < 16) {646 if (128 - d.buf_len < 16) {
645 d.round(d.buf[0..]);647 d.round(d.buf[0..]);
646 mem.set(u8, d.buf[0..], 0);648 @memset(d.buf[0..], 0);
647 }649 }
648650
649 // Append message length.651 // Append message length.
lib/std/crypto/sha3.zig+2-2
...@@ -149,7 +149,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:...@@ -149,7 +149,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
149 const left = self.buf.len - self.offset;149 const left = self.buf.len - self.offset;
150 if (left > 0) {150 if (left > 0) {
151 const n = math.min(left, out.len);151 const n = math.min(left, out.len);
152 mem.copy(u8, out[0..n], self.buf[self.offset..][0..n]);152 @memcpy(out[0..n], self.buf[self.offset..][0..n]);
153 out = out[n..];153 out = out[n..];
154 self.offset += n;154 self.offset += n;
155 if (out.len == 0) {155 if (out.len == 0) {
...@@ -164,7 +164,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:...@@ -164,7 +164,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
164 }164 }
165 if (out.len > 0) {165 if (out.len > 0) {
166 self.st.squeeze(self.buf[0..]);166 self.st.squeeze(self.buf[0..]);
167 mem.copy(u8, out[0..], self.buf[0..out.len]);167 @memcpy(out[0..], self.buf[0..out.len]);
168 self.offset = out.len;168 self.offset = out.len;
169 }169 }
170 }170 }
lib/std/crypto/siphash.zig+5-4
...@@ -98,7 +98,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round...@@ -98,7 +98,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
98 self.msg_len +%= @truncate(u8, b.len);98 self.msg_len +%= @truncate(u8, b.len);
9999
100 var buf = [_]u8{0} ** 8;100 var buf = [_]u8{0} ** 8;
101 mem.copy(u8, buf[0..], b[0..]);101 @memcpy(buf[0..b.len], b);
102 buf[7] = self.msg_len;102 buf[7] = self.msg_len;
103 self.round(buf);103 self.round(buf);
104104
...@@ -203,7 +203,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -203,7 +203,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
203203
204 if (self.buf_len != 0 and self.buf_len + b.len >= 8) {204 if (self.buf_len != 0 and self.buf_len + b.len >= 8) {
205 off += 8 - self.buf_len;205 off += 8 - self.buf_len;
206 mem.copy(u8, self.buf[self.buf_len..], b[0..off]);206 @memcpy(self.buf[self.buf_len..][0..off], b[0..off]);
207 self.state.update(self.buf[0..]);207 self.state.update(self.buf[0..]);
208 self.buf_len = 0;208 self.buf_len = 0;
209 }209 }
...@@ -212,8 +212,9 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)...@@ -212,8 +212,9 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
212 const aligned_len = remain_len - (remain_len % 8);212 const aligned_len = remain_len - (remain_len % 8);
213 self.state.update(b[off .. off + aligned_len]);213 self.state.update(b[off .. off + aligned_len]);
214214
215 mem.copy(u8, self.buf[self.buf_len..], b[off + aligned_len ..]);215 const b_slice = b[off + aligned_len ..];
216 self.buf_len += @intCast(u8, b[off + aligned_len ..].len);216 @memcpy(self.buf[self.buf_len..][0..b_slice.len], b_slice);
217 self.buf_len += @intCast(u8, b_slice.len);
217 }218 }
218219
219 pub fn peek(self: Self) [mac_length]u8 {220 pub fn peek(self: Self) [mac_length]u8 {
lib/std/crypto/tls/Client.zig+15-15
...@@ -685,7 +685,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -685,7 +685,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
685 .application_cipher = app_cipher,685 .application_cipher = app_cipher,
686 .partially_read_buffer = undefined,686 .partially_read_buffer = undefined,
687 };687 };
688 mem.copy(u8, &client.partially_read_buffer, leftover);688 @memcpy(client.partially_read_buffer[0..leftover.len], leftover);
689 return client;689 return client;
690 },690 },
691 else => {691 else => {
...@@ -809,7 +809,7 @@ fn prepareCiphertextRecord(...@@ -809,7 +809,7 @@ fn prepareCiphertextRecord(
809 .overhead_len = overhead_len,809 .overhead_len = overhead_len,
810 };810 };
811811
812 mem.copy(u8, &cleartext_buf, bytes[bytes_i..][0..encrypted_content_len]);812 @memcpy(cleartext_buf[0..encrypted_content_len], bytes[bytes_i..][0..encrypted_content_len]);
813 cleartext_buf[encrypted_content_len] = @enumToInt(inner_content_type);813 cleartext_buf[encrypted_content_len] = @enumToInt(inner_content_type);
814 bytes_i += encrypted_content_len;814 bytes_i += encrypted_content_len;
815 const ciphertext_len = encrypted_content_len + 1;815 const ciphertext_len = encrypted_content_len + 1;
...@@ -1029,8 +1029,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1029,8 +1029,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1029 if (frag1.len < second_len)1029 if (frag1.len < second_len)
1030 return finishRead2(c, first, frag1, vp.total);1030 return finishRead2(c, first, frag1, vp.total);
10311031
1032 mem.copy(u8, frag[0..in], first);1032 @memcpy(frag[0..in], first);
1033 mem.copy(u8, frag[first.len..], frag1[0..second_len]);1033 @memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
1034 frag = frag[0..full_record_len];1034 frag = frag[0..full_record_len];
1035 frag1 = frag1[second_len..];1035 frag1 = frag1[second_len..];
1036 in = 0;1036 in = 0;
...@@ -1059,8 +1059,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1059,8 +1059,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1059 if (frag1.len < second_len)1059 if (frag1.len < second_len)
1060 return finishRead2(c, first, frag1, vp.total);1060 return finishRead2(c, first, frag1, vp.total);
10611061
1062 mem.copy(u8, frag[0..in], first);1062 @memcpy(frag[0..in], first);
1063 mem.copy(u8, frag[first.len..], frag1[0..second_len]);1063 @memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
1064 frag = frag[0..full_record_len];1064 frag = frag[0..full_record_len];
1065 frag1 = frag1[second_len..];1065 frag1 = frag1[second_len..];
1066 in = 0;1066 in = 0;
...@@ -1177,7 +1177,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1177,7 +1177,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1177 // We have already run out of room in iovecs. Continue1177 // We have already run out of room in iovecs. Continue
1178 // appending to `partially_read_buffer`.1178 // appending to `partially_read_buffer`.
1179 const dest = c.partially_read_buffer[c.partial_ciphertext_idx..];1179 const dest = c.partially_read_buffer[c.partial_ciphertext_idx..];
1180 mem.copy(u8, dest, msg);1180 @memcpy(dest[0..msg.len], msg);
1181 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), c.partial_ciphertext_idx + msg.len);1181 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), c.partial_ciphertext_idx + msg.len);
1182 } else {1182 } else {
1183 const amt = vp.put(msg);1183 const amt = vp.put(msg);
...@@ -1185,7 +1185,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)...@@ -1185,7 +1185,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
1185 const rest = msg[amt..];1185 const rest = msg[amt..];
1186 c.partial_cleartext_idx = 0;1186 c.partial_cleartext_idx = 0;
1187 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), rest.len);1187 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), rest.len);
1188 mem.copy(u8, &c.partially_read_buffer, rest);1188 @memcpy(c.partially_read_buffer[0..rest.len], rest);
1189 }1189 }
1190 }1190 }
1191 } else {1191 } else {
...@@ -1213,12 +1213,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {...@@ -1213,12 +1213,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {
1213 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {1213 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
1214 // There is cleartext at the beginning already which we need to preserve.1214 // There is cleartext at the beginning already which we need to preserve.
1215 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + saved_buf.len);1215 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + saved_buf.len);
1216 mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx..], saved_buf);1216 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..saved_buf.len], saved_buf);
1217 } else {1217 } else {
1218 c.partial_cleartext_idx = 0;1218 c.partial_cleartext_idx = 0;
1219 c.partial_ciphertext_idx = 0;1219 c.partial_ciphertext_idx = 0;
1220 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), saved_buf.len);1220 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), saved_buf.len);
1221 mem.copy(u8, &c.partially_read_buffer, saved_buf);1221 @memcpy(c.partially_read_buffer[0..saved_buf.len], saved_buf);
1222 }1222 }
1223 return out;1223 return out;
1224}1224}
...@@ -1227,14 +1227,14 @@ fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usi...@@ -1227,14 +1227,14 @@ fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usi
1227 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {1227 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
1228 // There is cleartext at the beginning already which we need to preserve.1228 // There is cleartext at the beginning already which we need to preserve.
1229 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + first.len + frag1.len);1229 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + first.len + frag1.len);
1230 mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx..], first);1230 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..first.len], first);
1231 mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..], frag1);1231 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..][0..frag1.len], frag1);
1232 } else {1232 } else {
1233 c.partial_cleartext_idx = 0;1233 c.partial_cleartext_idx = 0;
1234 c.partial_ciphertext_idx = 0;1234 c.partial_ciphertext_idx = 0;
1235 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), first.len + frag1.len);1235 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), first.len + frag1.len);
1236 mem.copy(u8, &c.partially_read_buffer, first);1236 @memcpy(c.partially_read_buffer[0..first.len], first);
1237 mem.copy(u8, c.partially_read_buffer[first.len..], frag1);1237 @memcpy(c.partially_read_buffer[first.len..][0..frag1.len], frag1);
1238 }1238 }
1239 return out;1239 return out;
1240}1240}
...@@ -1282,7 +1282,7 @@ const VecPut = struct {...@@ -1282,7 +1282,7 @@ const VecPut = struct {
1282 const v = vp.iovecs[vp.idx];1282 const v = vp.iovecs[vp.idx];
1283 const dest = v.iov_base[vp.off..v.iov_len];1283 const dest = v.iov_base[vp.off..v.iov_len];
1284 const src = bytes[bytes_i..][0..@min(dest.len, bytes.len - bytes_i)];1284 const src = bytes[bytes_i..][0..@min(dest.len, bytes.len - bytes_i)];
1285 mem.copy(u8, dest, src);1285 @memcpy(dest[0..src.len], src);
1286 bytes_i += src.len;1286 bytes_i += src.len;
1287 vp.off += src.len;1287 vp.off += src.len;
1288 if (vp.off >= v.iov_len) {1288 if (vp.off >= v.iov_len) {
lib/std/crypto/utils.zig+4-8
...@@ -134,12 +134,8 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T,...@@ -134,12 +134,8 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T,
134134
135/// Sets a slice to zeroes.135/// Sets a slice to zeroes.
136/// Prevents the store from being optimized out.136/// Prevents the store from being optimized out.
137pub fn secureZero(comptime T: type, s: []T) void {137pub inline fn secureZero(comptime T: type, s: []T) void {
138 // TODO: implement `@memset` for non-byte-sized element type in the llvm backend138 @memset(@as([]volatile T, s), 0);
139 //@memset(@as([]volatile T, s), 0);
140 const ptr = @ptrCast([*]volatile u8, s.ptr);
141 const length = s.len * @sizeOf(T);
142 @memset(ptr[0..length], 0);
143}139}
144140
145test "crypto.utils.timingSafeEql" {141test "crypto.utils.timingSafeEql" {
...@@ -148,7 +144,7 @@ test "crypto.utils.timingSafeEql" {...@@ -148,7 +144,7 @@ test "crypto.utils.timingSafeEql" {
148 random.bytes(a[0..]);144 random.bytes(a[0..]);
149 random.bytes(b[0..]);145 random.bytes(b[0..]);
150 try testing.expect(!timingSafeEql([100]u8, a, b));146 try testing.expect(!timingSafeEql([100]u8, a, b));
151 mem.copy(u8, a[0..], b[0..]);147 a = b;
152 try testing.expect(timingSafeEql([100]u8, a, b));148 try testing.expect(timingSafeEql([100]u8, a, b));
153}149}
154150
...@@ -201,7 +197,7 @@ test "crypto.utils.secureZero" {...@@ -201,7 +197,7 @@ test "crypto.utils.secureZero" {
201 var a = [_]u8{0xfe} ** 8;197 var a = [_]u8{0xfe} ** 8;
202 var b = [_]u8{0xfe} ** 8;198 var b = [_]u8{0xfe} ** 8;
203199
204 mem.set(u8, a[0..], 0);200 @memset(a[0..], 0);
205 secureZero(u8, b[0..]);201 secureZero(u8, b[0..]);
206202
207 try testing.expectEqualSlices(u8, a[0..], b[0..]);203 try testing.expectEqualSlices(u8, a[0..], b[0..]);
lib/std/cstr.zig+2-2
...@@ -34,7 +34,7 @@ fn testCStrFnsImpl() !void {...@@ -34,7 +34,7 @@ fn testCStrFnsImpl() !void {
34/// Caller owns the returned memory.34/// Caller owns the returned memory.
35pub fn addNullByte(allocator: mem.Allocator, slice: []const u8) ![:0]u8 {35pub fn addNullByte(allocator: mem.Allocator, slice: []const u8) ![:0]u8 {
36 const result = try allocator.alloc(u8, slice.len + 1);36 const result = try allocator.alloc(u8, slice.len + 1);
37 mem.copy(u8, result, slice);37 @memcpy(result[0..slice.len], slice);
38 result[slice.len] = 0;38 result[slice.len] = 0;
39 return result[0..slice.len :0];39 return result[0..slice.len :0];
40}40}
...@@ -78,7 +78,7 @@ pub const NullTerminated2DArray = struct {...@@ -78,7 +78,7 @@ pub const NullTerminated2DArray = struct {
78 for (slice) |inner| {78 for (slice) |inner| {
79 index_buf[i] = buf.ptr + write_index;79 index_buf[i] = buf.ptr + write_index;
80 i += 1;80 i += 1;
81 mem.copy(u8, buf[write_index..], inner);81 @memcpy(buf[write_index..][0..inner.len], inner);
82 write_index += inner.len;82 write_index += inner.len;
83 buf[write_index] = 0;83 buf[write_index] = 0;
84 write_index += 1;84 write_index += 1;
lib/std/dynamic_library.zig+1-1
...@@ -210,7 +210,7 @@ pub const ElfDynLib = struct {...@@ -210,7 +210,7 @@ pub const ElfDynLib = struct {
210 -1,210 -1,
211 0,211 0,
212 );212 );
213 mem.copy(u8, sect_mem, file_bytes[0..ph.p_filesz]);213 @memcpy(sect_mem[0..ph.p_filesz], file_bytes[0..ph.p_filesz]);
214 }214 }
215 },215 },
216 else => {},216 else => {},
lib/std/enums.zig+2-2
...@@ -275,7 +275,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {...@@ -275,7 +275,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
275 .bits = Self.BitSet.initFull(),275 .bits = Self.BitSet.initFull(),
276 .values = undefined,276 .values = undefined,
277 };277 };
278 std.mem.set(V, &result.values, value);278 @memset(&result.values, value);
279 return result;279 return result;
280 }280 }
281 /// Initializes a full mapping with supplied values.281 /// Initializes a full mapping with supplied values.
...@@ -1175,7 +1175,7 @@ pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type)...@@ -1175,7 +1175,7 @@ pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type)
11751175
1176 pub fn initFill(v: Value) Self {1176 pub fn initFill(v: Value) Self {
1177 var self: Self = undefined;1177 var self: Self = undefined;
1178 std.mem.set(Value, &self.values, v);1178 @memset(&self.values, v);
1179 return self;1179 return self;
1180 }1180 }
11811181
lib/std/fifo.zig+12-14
...@@ -86,19 +86,17 @@ pub fn LinearFifo(...@@ -86,19 +86,17 @@ pub fn LinearFifo(
8686
87 pub fn realign(self: *Self) void {87 pub fn realign(self: *Self) void {
88 if (self.buf.len - self.head >= self.count) {88 if (self.buf.len - self.head >= self.count) {
89 // this copy overlaps89 mem.copyForwards(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
90 mem.copy(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
91 self.head = 0;90 self.head = 0;
92 } else {91 } else {
93 var tmp: [mem.page_size / 2 / @sizeOf(T)]T = undefined;92 var tmp: [mem.page_size / 2 / @sizeOf(T)]T = undefined;
9493
95 while (self.head != 0) {94 while (self.head != 0) {
96 const n = math.min(self.head, tmp.len);95 const n = @min(self.head, tmp.len);
97 const m = self.buf.len - n;96 const m = self.buf.len - n;
98 mem.copy(T, tmp[0..n], self.buf[0..n]);97 @memcpy(tmp[0..n], self.buf[0..n]);
99 // this middle copy overlaps; the others here don't98 mem.copyForwards(T, self.buf[0..m], self.buf[n..][0..m]);
100 mem.copy(T, self.buf[0..m], self.buf[n..][0..m]);99 @memcpy(self.buf[m..][0..n], tmp[0..n]);
101 mem.copy(T, self.buf[m..], tmp[0..n]);
102 self.head -= n;100 self.head -= n;
103 }101 }
104 }102 }
...@@ -223,8 +221,8 @@ pub fn LinearFifo(...@@ -223,8 +221,8 @@ pub fn LinearFifo(
223 while (dst_left.len > 0) {221 while (dst_left.len > 0) {
224 const slice = self.readableSlice(0);222 const slice = self.readableSlice(0);
225 if (slice.len == 0) break;223 if (slice.len == 0) break;
226 const n = math.min(slice.len, dst_left.len);224 const n = @min(slice.len, dst_left.len);
227 mem.copy(T, dst_left, slice[0..n]);225 @memcpy(dst_left[0..n], slice[0..n]);
228 self.discard(n);226 self.discard(n);
229 dst_left = dst_left[n..];227 dst_left = dst_left[n..];
230 }228 }
...@@ -289,8 +287,8 @@ pub fn LinearFifo(...@@ -289,8 +287,8 @@ pub fn LinearFifo(
289 while (src_left.len > 0) {287 while (src_left.len > 0) {
290 const writable_slice = self.writableSlice(0);288 const writable_slice = self.writableSlice(0);
291 assert(writable_slice.len != 0);289 assert(writable_slice.len != 0);
292 const n = math.min(writable_slice.len, src_left.len);290 const n = @min(writable_slice.len, src_left.len);
293 mem.copy(T, writable_slice, src_left[0..n]);291 @memcpy(writable_slice[0..n], src_left[0..n]);
294 self.update(n);292 self.update(n);
295 src_left = src_left[n..];293 src_left = src_left[n..];
296 }294 }
...@@ -354,11 +352,11 @@ pub fn LinearFifo(...@@ -354,11 +352,11 @@ pub fn LinearFifo(
354352
355 const slice = self.readableSliceMut(0);353 const slice = self.readableSliceMut(0);
356 if (src.len < slice.len) {354 if (src.len < slice.len) {
357 mem.copy(T, slice, src);355 @memcpy(slice[0..src.len], src);
358 } else {356 } else {
359 mem.copy(T, slice, src[0..slice.len]);357 @memcpy(slice, src[0..slice.len]);
360 const slice2 = self.readableSliceMut(slice.len);358 const slice2 = self.readableSliceMut(slice.len);
361 mem.copy(T, slice2, src[slice.len..]);359 @memcpy(slice2[0 .. src.len - slice.len], src[slice.len..]);
362 }360 }
363 }361 }
364362
lib/std/fmt/errol.zig+2-2
...@@ -84,8 +84,8 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {...@@ -84,8 +84,8 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
84 const i = tableLowerBound(bits);84 const i = tableLowerBound(bits);
85 if (i < enum3.len and enum3[i] == bits) {85 if (i < enum3.len and enum3[i] == bits) {
86 const data = enum3_data[i];86 const data = enum3_data[i];
87 const digits = buffer[1 .. data.str.len + 1];87 const digits = buffer[1..][0..data.str.len];
88 mem.copy(u8, digits, data.str);88 @memcpy(digits, data.str);
89 return FloatDecimal{89 return FloatDecimal{
90 .digits = digits,90 .digits = digits,
91 .exp = data.exp,91 .exp = data.exp,
lib/std/fs/path.zig+6-6
...@@ -79,7 +79,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn...@@ -79,7 +79,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
79 const buf = try allocator.alloc(u8, total_len);79 const buf = try allocator.alloc(u8, total_len);
80 errdefer allocator.free(buf);80 errdefer allocator.free(buf);
8181
82 mem.copy(u8, buf, paths[first_path_index]);82 @memcpy(buf[0..paths[first_path_index].len], paths[first_path_index]);
83 var buf_index: usize = paths[first_path_index].len;83 var buf_index: usize = paths[first_path_index].len;
84 var prev_path = paths[first_path_index];84 var prev_path = paths[first_path_index];
85 assert(prev_path.len > 0);85 assert(prev_path.len > 0);
...@@ -94,7 +94,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn...@@ -94,7 +94,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
94 buf_index += 1;94 buf_index += 1;
95 }95 }
96 const adjusted_path = if (prev_sep and this_sep) this_path[1..] else this_path;96 const adjusted_path = if (prev_sep and this_sep) this_path[1..] else this_path;
97 mem.copy(u8, buf[buf_index..], adjusted_path);97 @memcpy(buf[buf_index..][0..adjusted_path.len], adjusted_path);
98 buf_index += adjusted_path.len;98 buf_index += adjusted_path.len;
99 prev_path = this_path;99 prev_path = this_path;
100 }100 }
...@@ -631,7 +631,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {...@@ -631,7 +631,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
631 real_result[i..][0..3].* = "..\\".*;631 real_result[i..][0..3].* = "..\\".*;
632 i += 3;632 i += 3;
633 }633 }
634 mem.copy(u8, real_result[i..], result.items);634 @memcpy(real_result[i..][0..result.items.len], result.items);
635 return real_result;635 return real_result;
636 }636 }
637}637}
...@@ -710,7 +710,7 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E...@@ -710,7 +710,7 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E
710 real_result[i..][0..3].* = "../".*;710 real_result[i..][0..3].* = "../".*;
711 i += 3;711 i += 3;
712 }712 }
713 mem.copy(u8, real_result[i..], result.items);713 @memcpy(real_result[i..][0..result.items.len], result.items);
714 return real_result;714 return real_result;
715 }715 }
716}716}
...@@ -1106,7 +1106,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !...@@ -1106,7 +1106,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
1106 while (rest_it.next()) |to_component| {1106 while (rest_it.next()) |to_component| {
1107 result[result_index] = '\\';1107 result[result_index] = '\\';
1108 result_index += 1;1108 result_index += 1;
1109 mem.copy(u8, result[result_index..], to_component);1109 @memcpy(result[result_index..][0..to_component.len], to_component);
1110 result_index += to_component.len;1110 result_index += to_component.len;
1111 }1111 }
11121112
...@@ -1151,7 +1151,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]...@@ -1151,7 +1151,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
1151 return allocator.realloc(result, result_index - 1);1151 return allocator.realloc(result, result_index - 1);
1152 }1152 }
11531153
1154 mem.copy(u8, result[result_index..], to_rest);1154 @memcpy(result[result_index..][0..to_rest.len], to_rest);
1155 return result;1155 return result;
1156 }1156 }
11571157
lib/std/hash/cityhash.zig+2-2
...@@ -348,8 +348,8 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {...@@ -348,8 +348,8 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
348 var key: [256]u8 = undefined;348 var key: [256]u8 = undefined;
349 var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;349 var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;
350350
351 std.mem.set(u8, &key, 0);351 @memset(&key, 0);
352 std.mem.set(u8, &hashes_bytes, 0);352 @memset(&hashes_bytes, 0);
353353
354 var i: u32 = 0;354 var i: u32 = 0;
355 while (i < 256) : (i += 1) {355 while (i < 256) : (i += 1) {
lib/std/hash/wyhash.zig+3-2
...@@ -147,7 +147,7 @@ pub const Wyhash = struct {...@@ -147,7 +147,7 @@ pub const Wyhash = struct {
147147
148 if (self.buf_len != 0 and self.buf_len + b.len >= 32) {148 if (self.buf_len != 0 and self.buf_len + b.len >= 32) {
149 off += 32 - self.buf_len;149 off += 32 - self.buf_len;
150 mem.copy(u8, self.buf[self.buf_len..], b[0..off]);150 @memcpy(self.buf[self.buf_len..][0..off], b[0..off]);
151 self.state.update(self.buf[0..]);151 self.state.update(self.buf[0..]);
152 self.buf_len = 0;152 self.buf_len = 0;
153 }153 }
...@@ -156,7 +156,8 @@ pub const Wyhash = struct {...@@ -156,7 +156,8 @@ pub const Wyhash = struct {
156 const aligned_len = remain_len - (remain_len % 32);156 const aligned_len = remain_len - (remain_len % 32);
157 self.state.update(b[off .. off + aligned_len]);157 self.state.update(b[off .. off + aligned_len]);
158158
159 mem.copy(u8, self.buf[self.buf_len..], b[off + aligned_len ..]);159 const src = b[off + aligned_len ..];
160 @memcpy(self.buf[self.buf_len..][0..src.len], src);
160 self.buf_len += @intCast(u8, b[off + aligned_len ..].len);161 self.buf_len += @intCast(u8, b[off + aligned_len ..].len);
161 }162 }
162163
lib/std/hash/xxhash.zig+6-6
...@@ -36,7 +36,7 @@ pub const XxHash64 = struct {...@@ -36,7 +36,7 @@ pub const XxHash64 = struct {
3636
37 pub fn update(self: *XxHash64, input: []const u8) void {37 pub fn update(self: *XxHash64, input: []const u8) void {
38 if (input.len < 32 - self.buf_len) {38 if (input.len < 32 - self.buf_len) {
39 mem.copy(u8, self.buf[self.buf_len..], input);39 @memcpy(self.buf[self.buf_len..][0..input.len], input);
40 self.buf_len += input.len;40 self.buf_len += input.len;
41 return;41 return;
42 }42 }
...@@ -45,7 +45,7 @@ pub const XxHash64 = struct {...@@ -45,7 +45,7 @@ pub const XxHash64 = struct {
4545
46 if (self.buf_len > 0) {46 if (self.buf_len > 0) {
47 i = 32 - self.buf_len;47 i = 32 - self.buf_len;
48 mem.copy(u8, self.buf[self.buf_len..], input[0..i]);48 @memcpy(self.buf[self.buf_len..][0..i], input[0..i]);
49 self.processStripe(&self.buf);49 self.processStripe(&self.buf);
50 self.buf_len = 0;50 self.buf_len = 0;
51 }51 }
...@@ -55,7 +55,7 @@ pub const XxHash64 = struct {...@@ -55,7 +55,7 @@ pub const XxHash64 = struct {
55 }55 }
5656
57 const remaining_bytes = input[i..];57 const remaining_bytes = input[i..];
58 mem.copy(u8, &self.buf, remaining_bytes);58 @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
59 self.buf_len = remaining_bytes.len;59 self.buf_len = remaining_bytes.len;
60 }60 }
6161
...@@ -165,7 +165,7 @@ pub const XxHash32 = struct {...@@ -165,7 +165,7 @@ pub const XxHash32 = struct {
165165
166 pub fn update(self: *XxHash32, input: []const u8) void {166 pub fn update(self: *XxHash32, input: []const u8) void {
167 if (input.len < 16 - self.buf_len) {167 if (input.len < 16 - self.buf_len) {
168 mem.copy(u8, self.buf[self.buf_len..], input);168 @memcpy(self.buf[self.buf_len..][0..input.len], input);
169 self.buf_len += input.len;169 self.buf_len += input.len;
170 return;170 return;
171 }171 }
...@@ -174,7 +174,7 @@ pub const XxHash32 = struct {...@@ -174,7 +174,7 @@ pub const XxHash32 = struct {
174174
175 if (self.buf_len > 0) {175 if (self.buf_len > 0) {
176 i = 16 - self.buf_len;176 i = 16 - self.buf_len;
177 mem.copy(u8, self.buf[self.buf_len..], input[0..i]);177 @memcpy(self.buf[self.buf_len..][0..i], input[0..i]);
178 self.processStripe(&self.buf);178 self.processStripe(&self.buf);
179 self.buf_len = 0;179 self.buf_len = 0;
180 }180 }
...@@ -184,7 +184,7 @@ pub const XxHash32 = struct {...@@ -184,7 +184,7 @@ pub const XxHash32 = struct {
184 }184 }
185185
186 const remaining_bytes = input[i..];186 const remaining_bytes = input[i..];
187 mem.copy(u8, &self.buf, remaining_bytes);187 @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
188 self.buf_len = remaining_bytes.len;188 self.buf_len = remaining_bytes.len;
189 }189 }
190190
lib/std/heap/WasmAllocator.zig+1-1
...@@ -230,7 +230,7 @@ test "shrink" {...@@ -230,7 +230,7 @@ test "shrink" {
230 var slice = try test_ally.alloc(u8, 20);230 var slice = try test_ally.alloc(u8, 20);
231 defer test_ally.free(slice);231 defer test_ally.free(slice);
232232
233 mem.set(u8, slice, 0x11);233 @memset(slice, 0x11);
234234
235 try std.testing.expect(test_ally.resize(slice, 17));235 try std.testing.expect(test_ally.resize(slice, 17));
236 slice = slice[0..17];236 slice = slice[0..17];
lib/std/heap/WasmPageAllocator.zig+1-1
...@@ -153,7 +153,7 @@ fn freePages(start: usize, end: usize) void {...@@ -153,7 +153,7 @@ fn freePages(start: usize, end: usize) void {
153153
154 extended.data = @intToPtr([*]u128, new_end * mem.page_size)[0 .. mem.page_size / @sizeOf(u128)];154 extended.data = @intToPtr([*]u128, new_end * mem.page_size)[0 .. mem.page_size / @sizeOf(u128)];
155 // Since this is the first page being freed and we consume it, assume *nothing* is free.155 // Since this is the first page being freed and we consume it, assume *nothing* is free.
156 mem.set(u128, extended.data, PageStatus.none_free);156 @memset(extended.data, PageStatus.none_free);
157 }157 }
158 const clamped_start = @max(extendedOffset(), start);158 const clamped_start = @max(extendedOffset(), start);
159 extended.recycle(clamped_start - extendedOffset(), new_end - clamped_start);159 extended.recycle(clamped_start - extendedOffset(), new_end - clamped_start);
lib/std/heap/general_purpose_allocator.zig+2-2
...@@ -448,7 +448,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -448,7 +448,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
448448
449 fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {449 fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {
450 if (stack_n == 0) return;450 if (stack_n == 0) return;
451 mem.set(usize, addresses, 0);451 @memset(addresses, 0);
452 var stack_trace = StackTrace{452 var stack_trace = StackTrace{
453 .instruction_addresses = addresses,453 .instruction_addresses = addresses,
454 .index = 0,454 .index = 0,
...@@ -1113,7 +1113,7 @@ test "shrink" {...@@ -1113,7 +1113,7 @@ test "shrink" {
1113 var slice = try allocator.alloc(u8, 20);1113 var slice = try allocator.alloc(u8, 20);
1114 defer allocator.free(slice);1114 defer allocator.free(slice);
11151115
1116 mem.set(u8, slice, 0x11);1116 @memset(slice, 0x11);
11171117
1118 try std.testing.expect(allocator.resize(slice, 17));1118 try std.testing.expect(allocator.resize(slice, 17));
1119 slice = slice[0..17];1119 slice = slice[0..17];
lib/std/io/buffered_reader.zig+4-7
...@@ -20,8 +20,8 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty...@@ -20,8 +20,8 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty
20 var dest_index: usize = 0;20 var dest_index: usize = 0;
2121
22 while (dest_index < dest.len) {22 while (dest_index < dest.len) {
23 const written = std.math.min(dest.len - dest_index, self.end - self.start);23 const written = @min(dest.len - dest_index, self.end - self.start);
24 std.mem.copy(u8, dest[dest_index..], self.buf[self.start .. self.start + written]);24 @memcpy(dest[dest_index..][0..written], self.buf[self.start..][0..written]);
25 if (written == 0) {25 if (written == 0) {
26 // buf empty, fill it26 // buf empty, fill it
27 const n = try self.unbuffered_reader.read(self.buf[0..]);27 const n = try self.unbuffered_reader.read(self.buf[0..]);
...@@ -115,11 +115,8 @@ test "io.BufferedReader Block" {...@@ -115,11 +115,8 @@ test "io.BufferedReader Block" {
115 }115 }
116116
117 fn read(self: *Self, dest: []u8) Error!usize {117 fn read(self: *Self, dest: []u8) Error!usize {
118 if (self.curr_read >= self.reads_allowed) {118 if (self.curr_read >= self.reads_allowed) return 0;
119 return 0;119 @memcpy(dest[0..self.block.len], self.block);
120 }
121 std.debug.assert(dest.len >= self.block.len);
122 std.mem.copy(u8, dest, self.block);
123120
124 self.curr_read += 1;121 self.curr_read += 1;
125 return self.block.len;122 return self.block.len;
lib/std/io/buffered_writer.zig+3-2
...@@ -30,8 +30,9 @@ pub fn BufferedWriter(comptime buffer_size: usize, comptime WriterType: type) ty...@@ -30,8 +30,9 @@ pub fn BufferedWriter(comptime buffer_size: usize, comptime WriterType: type) ty
30 return self.unbuffered_writer.write(bytes);30 return self.unbuffered_writer.write(bytes);
31 }31 }
3232
33 mem.copy(u8, self.buf[self.end..], bytes);33 const new_end = self.end + bytes.len;
34 self.end += bytes.len;34 @memcpy(self.buf[self.end..new_end], bytes);
35 self.end = new_end;
35 return bytes.len;36 return bytes.len;
36 }37 }
37 };38 };
lib/std/io/fixed_buffer_stream.zig+3-3
...@@ -45,10 +45,10 @@ pub fn FixedBufferStream(comptime Buffer: type) type {...@@ -45,10 +45,10 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
45 }45 }
4646
47 pub fn read(self: *Self, dest: []u8) ReadError!usize {47 pub fn read(self: *Self, dest: []u8) ReadError!usize {
48 const size = std.math.min(dest.len, self.buffer.len - self.pos);48 const size = @min(dest.len, self.buffer.len - self.pos);
49 const end = self.pos + size;49 const end = self.pos + size;
5050
51 mem.copy(u8, dest[0..size], self.buffer[self.pos..end]);51 @memcpy(dest[0..size], self.buffer[self.pos..end]);
52 self.pos = end;52 self.pos = end;
5353
54 return size;54 return size;
...@@ -67,7 +67,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {...@@ -67,7 +67,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
67 else67 else
68 self.buffer.len - self.pos;68 self.buffer.len - self.pos;
6969
70 mem.copy(u8, self.buffer[self.pos .. self.pos + n], bytes[0..n]);70 @memcpy(self.buffer[self.pos..][0..n], bytes[0..n]);
71 self.pos += n;71 self.pos += n;
7272
73 if (n == 0) return error.NoSpaceLeft;73 if (n == 0) return error.NoSpaceLeft;
lib/std/io/writer.zig+1-1
...@@ -35,7 +35,7 @@ pub fn Writer(...@@ -35,7 +35,7 @@ pub fn Writer(
3535
36 pub fn writeByteNTimes(self: Self, byte: u8, n: usize) Error!void {36 pub fn writeByteNTimes(self: Self, byte: u8, n: usize) Error!void {
37 var bytes: [256]u8 = undefined;37 var bytes: [256]u8 = undefined;
38 mem.set(u8, bytes[0..], byte);38 @memset(bytes[0..], byte);
3939
40 var remaining: usize = n;40 var remaining: usize = n;
41 while (remaining > 0) {41 while (remaining > 0) {
lib/std/json.zig+2-2
...@@ -1667,7 +1667,7 @@ fn parseInternal(...@@ -1667,7 +1667,7 @@ fn parseInternal(
1667 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);1667 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
1668 if (r.len != stringToken.decodedLength()) return error.LengthMismatch;1668 if (r.len != stringToken.decodedLength()) return error.LengthMismatch;
1669 switch (stringToken.escapes) {1669 switch (stringToken.escapes) {
1670 .None => mem.copy(u8, &r, source_slice),1670 .None => @memcpy(r[0..source_slice.len], source_slice),
1671 .Some => try unescapeValidString(&r, source_slice),1671 .Some => try unescapeValidString(&r, source_slice),
1672 }1672 }
1673 return r;1673 return r;
...@@ -1733,7 +1733,7 @@ fn parseInternal(...@@ -1733,7 +1733,7 @@ fn parseInternal(
1733 try allocator.alloc(u8, len);1733 try allocator.alloc(u8, len);
1734 errdefer allocator.free(output);1734 errdefer allocator.free(output);
1735 switch (stringToken.escapes) {1735 switch (stringToken.escapes) {
1736 .None => mem.copy(u8, output, source_slice),1736 .None => @memcpy(output[0..source_slice.len], source_slice),
1737 .Some => try unescapeValidString(output, source_slice),1737 .Some => try unescapeValidString(output, source_slice),
1738 }1738 }
17391739
lib/std/json/test.zig+1-1
...@@ -2811,7 +2811,7 @@ test "json.serialize issue #5959" {...@@ -2811,7 +2811,7 @@ test "json.serialize issue #5959" {
2811 // StreamingParser has multiple internal fields set to undefined. This causes issues when using2811 // StreamingParser has multiple internal fields set to undefined. This causes issues when using
2812 // expectEqual so these are zeroed. We are testing for equality here only because this is a2812 // expectEqual so these are zeroed. We are testing for equality here only because this is a
2813 // known small test reproduction which hits the relevant LLVM issue.2813 // known small test reproduction which hits the relevant LLVM issue.
2814 std.mem.set(u8, @ptrCast([*]u8, &parser)[0..@sizeOf(StreamingParser)], 0);2814 @memset(@ptrCast([*]u8, &parser)[0..@sizeOf(StreamingParser)], 0);
2815 try std.testing.expectEqual(parser, parser);2815 try std.testing.expectEqual(parser, parser);
2816}2816}
28172817
lib/std/math/big/int.zig+32-32
...@@ -176,7 +176,7 @@ pub const Mutable = struct {...@@ -176,7 +176,7 @@ pub const Mutable = struct {
176 /// Asserts the value fits in the limbs buffer.176 /// Asserts the value fits in the limbs buffer.
177 pub fn copy(self: *Mutable, other: Const) void {177 pub fn copy(self: *Mutable, other: Const) void {
178 if (self.limbs.ptr != other.limbs.ptr) {178 if (self.limbs.ptr != other.limbs.ptr) {
179 mem.copy(Limb, self.limbs[0..], other.limbs[0..other.limbs.len]);179 @memcpy(self.limbs[0..other.limbs.len], other.limbs[0..other.limbs.len]);
180 }180 }
181 self.positive = other.positive;181 self.positive = other.positive;
182 self.len = other.limbs.len;182 self.len = other.limbs.len;
...@@ -199,7 +199,7 @@ pub const Mutable = struct {...@@ -199,7 +199,7 @@ pub const Mutable = struct {
199 /// can be modified separately from the original.199 /// can be modified separately from the original.
200 /// Asserts that limbs is big enough to store the value.200 /// Asserts that limbs is big enough to store the value.
201 pub fn clone(other: Mutable, limbs: []Limb) Mutable {201 pub fn clone(other: Mutable, limbs: []Limb) Mutable {
202 mem.copy(Limb, limbs, other.limbs[0..other.len]);202 @memcpy(limbs[0..other.len], other.limbs[0..other.len]);
203 return .{203 return .{
204 .limbs = limbs,204 .limbs = limbs,
205 .len = other.len,205 .len = other.len,
...@@ -344,7 +344,7 @@ pub const Mutable = struct {...@@ -344,7 +344,7 @@ pub const Mutable = struct {
344 .min => {344 .min => {
345 // Negative bound, signed = -0x80.345 // Negative bound, signed = -0x80.
346 r.len = req_limbs;346 r.len = req_limbs;
347 mem.set(Limb, r.limbs[0 .. r.len - 1], 0);347 @memset(r.limbs[0 .. r.len - 1], 0);
348 r.limbs[r.len - 1] = signmask;348 r.limbs[r.len - 1] = signmask;
349 r.positive = false;349 r.positive = false;
350 },350 },
...@@ -363,7 +363,7 @@ pub const Mutable = struct {...@@ -363,7 +363,7 @@ pub const Mutable = struct {
363 const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.363 const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.
364364
365 r.len = new_req_limbs;365 r.len = new_req_limbs;
366 std.mem.set(Limb, r.limbs[0 .. r.len - 1], maxInt(Limb));366 @memset(r.limbs[0 .. r.len - 1], maxInt(Limb));
367 r.limbs[r.len - 1] = new_mask;367 r.limbs[r.len - 1] = new_mask;
368 }368 }
369 },369 },
...@@ -376,7 +376,7 @@ pub const Mutable = struct {...@@ -376,7 +376,7 @@ pub const Mutable = struct {
376 .max => {376 .max => {
377 // Max bound, unsigned = 0xFF377 // Max bound, unsigned = 0xFF
378 r.len = req_limbs;378 r.len = req_limbs;
379 std.mem.set(Limb, r.limbs[0 .. r.len - 1], maxInt(Limb));379 @memset(r.limbs[0 .. r.len - 1], maxInt(Limb));
380 r.limbs[r.len - 1] = mask;380 r.limbs[r.len - 1] = mask;
381 },381 },
382 },382 },
...@@ -489,7 +489,7 @@ pub const Mutable = struct {...@@ -489,7 +489,7 @@ pub const Mutable = struct {
489 if (msl < req_limbs) {489 if (msl < req_limbs) {
490 r.limbs[msl] = 1;490 r.limbs[msl] = 1;
491 r.len = req_limbs;491 r.len = req_limbs;
492 mem.set(Limb, r.limbs[msl + 1 .. req_limbs], 0);492 @memset(r.limbs[msl + 1 .. req_limbs], 0);
493 } else {493 } else {
494 carry_truncated = true;494 carry_truncated = true;
495 }495 }
...@@ -637,14 +637,14 @@ pub const Mutable = struct {...@@ -637,14 +637,14 @@ pub const Mutable = struct {
637637
638 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {638 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
639 const start = buf_index;639 const start = buf_index;
640 mem.copy(Limb, limbs_buffer[buf_index..], a.limbs);640 @memcpy(limbs_buffer[buf_index..][0..a.limbs.len], a.limbs);
641 buf_index += a.limbs.len;641 buf_index += a.limbs.len;
642 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();642 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
643 } else a;643 } else a;
644644
645 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {645 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
646 const start = buf_index;646 const start = buf_index;
647 mem.copy(Limb, limbs_buffer[buf_index..], b.limbs);647 @memcpy(limbs_buffer[buf_index..][0..b.limbs.len], b.limbs);
648 buf_index += b.limbs.len;648 buf_index += b.limbs.len;
649 break :blk b.toMutable(limbs_buffer[start..buf_index]).toConst();649 break :blk b.toMutable(limbs_buffer[start..buf_index]).toConst();
650 } else b;650 } else b;
...@@ -676,7 +676,7 @@ pub const Mutable = struct {...@@ -676,7 +676,7 @@ pub const Mutable = struct {
676 }676 }
677 }677 }
678678
679 mem.set(Limb, rma.limbs[0 .. a.limbs.len + b.limbs.len], 0);679 @memset(rma.limbs[0 .. a.limbs.len + b.limbs.len], 0);
680680
681 llmulacc(.add, allocator, rma.limbs, a.limbs, b.limbs);681 llmulacc(.add, allocator, rma.limbs, a.limbs, b.limbs);
682682
...@@ -708,7 +708,7 @@ pub const Mutable = struct {...@@ -708,7 +708,7 @@ pub const Mutable = struct {
708 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {708 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
709 const start = buf_index;709 const start = buf_index;
710 const a_len = math.min(req_limbs, a.limbs.len);710 const a_len = math.min(req_limbs, a.limbs.len);
711 mem.copy(Limb, limbs_buffer[buf_index..], a.limbs[0..a_len]);711 @memcpy(limbs_buffer[buf_index..][0..a_len], a.limbs[0..a_len]);
712 buf_index += a_len;712 buf_index += a_len;
713 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();713 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
714 } else a;714 } else a;
...@@ -716,7 +716,7 @@ pub const Mutable = struct {...@@ -716,7 +716,7 @@ pub const Mutable = struct {
716 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {716 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
717 const start = buf_index;717 const start = buf_index;
718 const b_len = math.min(req_limbs, b.limbs.len);718 const b_len = math.min(req_limbs, b.limbs.len);
719 mem.copy(Limb, limbs_buffer[buf_index..], b.limbs[0..b_len]);719 @memcpy(limbs_buffer[buf_index..][0..b_len], b.limbs[0..b_len]);
720 buf_index += b_len;720 buf_index += b_len;
721 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();721 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
722 } else b;722 } else b;
...@@ -751,7 +751,7 @@ pub const Mutable = struct {...@@ -751,7 +751,7 @@ pub const Mutable = struct {
751 const a_limbs = a.limbs[0..math.min(req_limbs, a.limbs.len)];751 const a_limbs = a.limbs[0..math.min(req_limbs, a.limbs.len)];
752 const b_limbs = b.limbs[0..math.min(req_limbs, b.limbs.len)];752 const b_limbs = b.limbs[0..math.min(req_limbs, b.limbs.len)];
753753
754 mem.set(Limb, rma.limbs[0..req_limbs], 0);754 @memset(rma.limbs[0..req_limbs], 0);
755755
756 llmulacc(.add, allocator, rma.limbs, a_limbs, b_limbs);756 llmulacc(.add, allocator, rma.limbs, a_limbs, b_limbs);
757 rma.normalize(math.min(req_limbs, a.limbs.len + b.limbs.len));757 rma.normalize(math.min(req_limbs, a.limbs.len + b.limbs.len));
...@@ -919,7 +919,7 @@ pub const Mutable = struct {...@@ -919,7 +919,7 @@ pub const Mutable = struct {
919 _ = opt_allocator;919 _ = opt_allocator;
920 assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing920 assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing
921921
922 mem.set(Limb, rma.limbs, 0);922 @memset(rma.limbs, 0);
923923
924 llsquareBasecase(rma.limbs, a.limbs);924 llsquareBasecase(rma.limbs, a.limbs);
925925
...@@ -1522,7 +1522,7 @@ pub const Mutable = struct {...@@ -1522,7 +1522,7 @@ pub const Mutable = struct {
1522 if (xy_trailing != 0) {1522 if (xy_trailing != 0) {
1523 // Manually shift here since we know its limb aligned.1523 // Manually shift here since we know its limb aligned.
1524 mem.copyBackwards(Limb, r.limbs[xy_trailing..], r.limbs[0..r.len]);1524 mem.copyBackwards(Limb, r.limbs[xy_trailing..], r.limbs[0..r.len]);
1525 mem.set(Limb, r.limbs[0..xy_trailing], 0);1525 @memset(r.limbs[0..xy_trailing], 0);
1526 r.len += xy_trailing;1526 r.len += xy_trailing;
1527 }1527 }
1528 }1528 }
...@@ -1556,7 +1556,7 @@ pub const Mutable = struct {...@@ -1556,7 +1556,7 @@ pub const Mutable = struct {
1556 // for 0 <= j <= n - t, set q[j] to 01556 // for 0 <= j <= n - t, set q[j] to 0
1557 q.len = shift + 1;1557 q.len = shift + 1;
1558 q.positive = true;1558 q.positive = true;
1559 mem.set(Limb, q.limbs[0..q.len], 0);1559 @memset(q.limbs[0..q.len], 0);
15601560
1561 // 2.1561 // 2.
1562 // while x >= y * b^(n - t):1562 // while x >= y * b^(n - t):
...@@ -1691,7 +1691,7 @@ pub const Mutable = struct {...@@ -1691,7 +1691,7 @@ pub const Mutable = struct {
16911691
1692 r.addScalar(a.abs(), -1);1692 r.addScalar(a.abs(), -1);
1693 if (req_limbs > r.len) {1693 if (req_limbs > r.len) {
1694 mem.set(Limb, r.limbs[r.len..req_limbs], 0);1694 @memset(r.limbs[r.len..req_limbs], 0);
1695 }1695 }
16961696
1697 assert(r.limbs.len >= req_limbs);1697 assert(r.limbs.len >= req_limbs);
...@@ -1730,7 +1730,7 @@ pub const Mutable = struct {...@@ -1730,7 +1730,7 @@ pub const Mutable = struct {
17301730
1731 // Zero-extend the result1731 // Zero-extend the result
1732 if (req_limbs > r.len) {1732 if (req_limbs > r.len) {
1733 mem.set(Limb, r.limbs[r.len..req_limbs], 0);1733 @memset(r.limbs[r.len..req_limbs], 0);
1734 }1734 }
17351735
1736 // Truncate to required number of limbs.1736 // Truncate to required number of limbs.
...@@ -1921,8 +1921,8 @@ pub const Const = struct {...@@ -1921,8 +1921,8 @@ pub const Const = struct {
19211921
1922 /// The result is an independent resource which is managed by the caller.1922 /// The result is an independent resource which is managed by the caller.
1923 pub fn toManaged(self: Const, allocator: Allocator) Allocator.Error!Managed {1923 pub fn toManaged(self: Const, allocator: Allocator) Allocator.Error!Managed {
1924 const limbs = try allocator.alloc(Limb, math.max(Managed.default_capacity, self.limbs.len));1924 const limbs = try allocator.alloc(Limb, @max(Managed.default_capacity, self.limbs.len));
1925 mem.copy(Limb, limbs, self.limbs);1925 @memcpy(limbs[0..self.limbs.len], self.limbs);
1926 return Managed{1926 return Managed{
1927 .allocator = allocator,1927 .allocator = allocator,
1928 .limbs = limbs,1928 .limbs = limbs,
...@@ -1935,7 +1935,7 @@ pub const Const = struct {...@@ -1935,7 +1935,7 @@ pub const Const = struct {
19351935
1936 /// Asserts `limbs` is big enough to store the value.1936 /// Asserts `limbs` is big enough to store the value.
1937 pub fn toMutable(self: Const, limbs: []Limb) Mutable {1937 pub fn toMutable(self: Const, limbs: []Limb) Mutable {
1938 mem.copy(Limb, limbs, self.limbs[0..self.limbs.len]);1938 @memcpy(limbs[0..self.limbs.len], self.limbs[0..self.limbs.len]);
1939 return .{1939 return .{
1940 .limbs = limbs,1940 .limbs = limbs,
1941 .positive = self.positive,1941 .positive = self.positive,
...@@ -2253,7 +2253,7 @@ pub const Const = struct {...@@ -2253,7 +2253,7 @@ pub const Const = struct {
2253 .positive = true, // Make absolute by ignoring self.positive.2253 .positive = true, // Make absolute by ignoring self.positive.
2254 .len = self.limbs.len,2254 .len = self.limbs.len,
2255 };2255 };
2256 mem.copy(Limb, q.limbs, self.limbs);2256 @memcpy(q.limbs[0..self.limbs.len], self.limbs);
22572257
2258 var r: Mutable = .{2258 var r: Mutable = .{
2259 .limbs = limbs_buffer[q.limbs.len..][0..self.limbs.len],2259 .limbs = limbs_buffer[q.limbs.len..][0..self.limbs.len],
...@@ -2587,8 +2587,8 @@ pub const Managed = struct {...@@ -2587,8 +2587,8 @@ pub const Managed = struct {
2587 .allocator = allocator,2587 .allocator = allocator,
2588 .metadata = other.metadata,2588 .metadata = other.metadata,
2589 .limbs = block: {2589 .limbs = block: {
2590 var limbs = try allocator.alloc(Limb, other.len());2590 const limbs = try allocator.alloc(Limb, other.len());
2591 mem.copy(Limb, limbs[0..], other.limbs[0..other.len()]);2591 @memcpy(limbs, other.limbs[0..other.len()]);
2592 break :block limbs;2592 break :block limbs;
2593 },2593 },
2594 };2594 };
...@@ -2600,7 +2600,7 @@ pub const Managed = struct {...@@ -2600,7 +2600,7 @@ pub const Managed = struct {
2600 if (self.limbs.ptr == other.limbs.ptr) return;2600 if (self.limbs.ptr == other.limbs.ptr) return;
26012601
2602 try self.ensureCapacity(other.limbs.len);2602 try self.ensureCapacity(other.limbs.len);
2603 mem.copy(Limb, self.limbs[0..], other.limbs[0..other.limbs.len]);2603 @memcpy(self.limbs[0..other.limbs.len], other.limbs[0..other.limbs.len]);
2604 self.setMetadata(other.positive, other.limbs.len);2604 self.setMetadata(other.positive, other.limbs.len);
2605 }2605 }
26062606
...@@ -3302,7 +3302,7 @@ fn llmulaccKaratsuba(...@@ -3302,7 +3302,7 @@ fn llmulaccKaratsuba(
3302 // Note, we don't need to compute all of p2, just enough limbs to satisfy r.3302 // Note, we don't need to compute all of p2, just enough limbs to satisfy r.
3303 const p2_limbs = math.min(limbs_after_split, a1.len + b1.len);3303 const p2_limbs = math.min(limbs_after_split, a1.len + b1.len);
33043304
3305 mem.set(Limb, tmp[0..p2_limbs], 0);3305 @memset(tmp[0..p2_limbs], 0);
3306 llmulacc(.add, allocator, tmp[0..p2_limbs], a1[0..math.min(a1.len, p2_limbs)], b1[0..math.min(b1.len, p2_limbs)]);3306 llmulacc(.add, allocator, tmp[0..p2_limbs], a1[0..math.min(a1.len, p2_limbs)], b1[0..math.min(b1.len, p2_limbs)]);
3307 const p2 = tmp[0..llnormalize(tmp[0..p2_limbs])];3307 const p2 = tmp[0..llnormalize(tmp[0..p2_limbs])];
33083308
...@@ -3317,7 +3317,7 @@ fn llmulaccKaratsuba(...@@ -3317,7 +3317,7 @@ fn llmulaccKaratsuba(
3317 // Compute p0.3317 // Compute p0.
3318 // Since a0.len, b0.len <= split and r.len >= split * 2, the full width of p0 needs to be computed.3318 // Since a0.len, b0.len <= split and r.len >= split * 2, the full width of p0 needs to be computed.
3319 const p0_limbs = a0.len + b0.len;3319 const p0_limbs = a0.len + b0.len;
3320 mem.set(Limb, tmp[0..p0_limbs], 0);3320 @memset(tmp[0..p0_limbs], 0);
3321 llmulacc(.add, allocator, tmp[0..p0_limbs], a0, b0);3321 llmulacc(.add, allocator, tmp[0..p0_limbs], a0, b0);
3322 const p0 = tmp[0..llnormalize(tmp[0..p0_limbs])];3322 const p0 = tmp[0..llnormalize(tmp[0..p0_limbs])];
33233323
...@@ -3341,7 +3341,7 @@ fn llmulaccKaratsuba(...@@ -3341,7 +3341,7 @@ fn llmulaccKaratsuba(
3341 return;3341 return;
3342 }3342 }
33433343
3344 mem.set(Limb, tmp, 0);3344 @memset(tmp, 0);
33453345
3346 // p1 is nonzero, so compute the intermediary terms j0 = a0 - a1 and j1 = b1 - b0.3346 // p1 is nonzero, so compute the intermediary terms j0 = a0 - a1 and j1 = b1 - b0.
3347 // Note that in this case, we again need some storage for intermediary results3347 // Note that in this case, we again need some storage for intermediary results
...@@ -3666,7 +3666,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {...@@ -3666,7 +3666,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
3666 }3666 }
36673667
3668 r[limb_shift - 1] = carry;3668 r[limb_shift - 1] = carry;
3669 mem.set(Limb, r[0 .. limb_shift - 1], 0);3669 @memset(r[0 .. limb_shift - 1], 0);
3670}3670}
36713671
3672fn llshr(r: []Limb, a: []const Limb, shift: usize) void {3672fn llshr(r: []Limb, a: []const Limb, shift: usize) void {
...@@ -4061,8 +4061,8 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {...@@ -4061,8 +4061,8 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
4061 tmp2 = tmp_limbs;4061 tmp2 = tmp_limbs;
4062 }4062 }
40634063
4064 mem.copy(Limb, tmp1, a);4064 @memcpy(tmp1[0..a.len], a);
4065 mem.set(Limb, tmp1[a.len..], 0);4065 @memset(tmp1[a.len..], 0);
40664066
4067 // Scan the exponent as a binary number, from left to right, dropping the4067 // Scan the exponent as a binary number, from left to right, dropping the
4068 // most significant bit set.4068 // most significant bit set.
...@@ -4074,14 +4074,14 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {...@@ -4074,14 +4074,14 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
4074 var i: usize = 0;4074 var i: usize = 0;
4075 while (i < exp_bits) : (i += 1) {4075 while (i < exp_bits) : (i += 1) {
4076 // Square4076 // Square
4077 mem.set(Limb, tmp2, 0);4077 @memset(tmp2, 0);
4078 llsquareBasecase(tmp2, tmp1[0..llnormalize(tmp1)]);4078 llsquareBasecase(tmp2, tmp1[0..llnormalize(tmp1)]);
4079 mem.swap([]Limb, &tmp1, &tmp2);4079 mem.swap([]Limb, &tmp1, &tmp2);
4080 // Multiply by a4080 // Multiply by a
4081 const ov = @shlWithOverflow(exp, 1);4081 const ov = @shlWithOverflow(exp, 1);
4082 exp = ov[0];4082 exp = ov[0];
4083 if (ov[1] != 0) {4083 if (ov[1] != 0) {
4084 mem.set(Limb, tmp2, 0);4084 @memset(tmp2, 0);
4085 llmulacc(.add, null, tmp2, tmp1[0..llnormalize(tmp1)], a);4085 llmulacc(.add, null, tmp2, tmp1[0..llnormalize(tmp1)], a);
4086 mem.swap([]Limb, &tmp1, &tmp2);4086 mem.swap([]Limb, &tmp1, &tmp2);
4087 }4087 }
lib/std/mem.zig+6-4
...@@ -192,12 +192,14 @@ test "Allocator.resize" {...@@ -192,12 +192,14 @@ test "Allocator.resize" {
192 }192 }
193}193}
194194
195/// Deprecated: use `copyForwards`
196pub const copy = copyForwards;
197
195/// Copy all of source into dest at position 0.198/// Copy all of source into dest at position 0.
196/// dest.len must be >= source.len.199/// dest.len must be >= source.len.
197/// If the slices overlap, dest.ptr must be <= src.ptr.200/// If the slices overlap, dest.ptr must be <= src.ptr.
198pub fn copy(comptime T: type, dest: []T, source: []const T) void {201pub fn copyForwards(comptime T: type, dest: []T, source: []const T) void {
199 for (dest[0..source.len], source) |*d, s|202 for (dest[0..source.len], source) |*d, s| d.* = s;
200 d.* = s;
201}203}
202204
203/// Copy all of source into dest at position 0.205/// Copy all of source into dest at position 0.
...@@ -3124,7 +3126,7 @@ pub fn replace(comptime T: type, input: []const T, needle: []const T, replacemen...@@ -3124,7 +3126,7 @@ pub fn replace(comptime T: type, input: []const T, needle: []const T, replacemen
3124 var replacements: usize = 0;3126 var replacements: usize = 0;
3125 while (slide < input.len) {3127 while (slide < input.len) {
3126 if (mem.startsWith(T, input[slide..], needle)) {3128 if (mem.startsWith(T, input[slide..], needle)) {
3127 mem.copy(T, output[i .. i + replacement.len], replacement);3129 @memcpy(output[i..][0..replacement.len], replacement);
3128 i += replacement.len;3130 i += replacement.len;
3129 slide += needle.len;3131 slide += needle.len;
3130 replacements += 1;3132 replacements += 1;
lib/std/mem/Allocator.zig+2-2
...@@ -307,14 +307,14 @@ pub fn free(self: Allocator, memory: anytype) void {...@@ -307,14 +307,14 @@ pub fn free(self: Allocator, memory: anytype) void {
307/// Copies `m` to newly allocated memory. Caller owns the memory.307/// Copies `m` to newly allocated memory. Caller owns the memory.
308pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T {308pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T {
309 const new_buf = try allocator.alloc(T, m.len);309 const new_buf = try allocator.alloc(T, m.len);
310 mem.copy(T, new_buf, m);310 @memcpy(new_buf, m);
311 return new_buf;311 return new_buf;
312}312}
313313
314/// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.314/// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.
315pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T {315pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T {
316 const new_buf = try allocator.alloc(T, m.len + 1);316 const new_buf = try allocator.alloc(T, m.len + 1);
317 mem.copy(T, new_buf, m);317 @memcpy(new_buf[0..m.len], m);
318 new_buf[m.len] = 0;318 new_buf[m.len] = 0;
319 return new_buf[0..m.len :0];319 return new_buf[0..m.len :0];
320}320}
lib/std/multi_array_list.zig+3-3
...@@ -380,7 +380,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -380,7 +380,7 @@ pub fn MultiArrayList(comptime T: type) type {
380 inline for (fields, 0..) |field_info, i| {380 inline for (fields, 0..) |field_info, i| {
381 if (@sizeOf(field_info.type) != 0) {381 if (@sizeOf(field_info.type) != 0) {
382 const field = @intToEnum(Field, i);382 const field = @intToEnum(Field, i);
383 mem.copy(field_info.type, other_slice.items(field), self_slice.items(field));383 @memcpy(other_slice.items(field), self_slice.items(field));
384 }384 }
385 }385 }
386 gpa.free(self.allocatedBytes());386 gpa.free(self.allocatedBytes());
...@@ -441,7 +441,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -441,7 +441,7 @@ pub fn MultiArrayList(comptime T: type) type {
441 inline for (fields, 0..) |field_info, i| {441 inline for (fields, 0..) |field_info, i| {
442 if (@sizeOf(field_info.type) != 0) {442 if (@sizeOf(field_info.type) != 0) {
443 const field = @intToEnum(Field, i);443 const field = @intToEnum(Field, i);
444 mem.copy(field_info.type, other_slice.items(field), self_slice.items(field));444 @memcpy(other_slice.items(field), self_slice.items(field));
445 }445 }
446 }446 }
447 gpa.free(self.allocatedBytes());447 gpa.free(self.allocatedBytes());
...@@ -460,7 +460,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -460,7 +460,7 @@ pub fn MultiArrayList(comptime T: type) type {
460 inline for (fields, 0..) |field_info, i| {460 inline for (fields, 0..) |field_info, i| {
461 if (@sizeOf(field_info.type) != 0) {461 if (@sizeOf(field_info.type) != 0) {
462 const field = @intToEnum(Field, i);462 const field = @intToEnum(Field, i);
463 mem.copy(field_info.type, result_slice.items(field), self_slice.items(field));463 @memcpy(result_slice.items(field), self_slice.items(field));
464 }464 }
465 }465 }
466 return result;466 return result;
lib/std/net.zig+3-3
...@@ -106,7 +106,7 @@ pub const Address = extern union {...@@ -106,7 +106,7 @@ pub const Address = extern union {
106 // Add 1 to ensure a terminating 0 is present in the path array for maximum portability.106 // Add 1 to ensure a terminating 0 is present in the path array for maximum portability.
107 if (path.len + 1 > sock_addr.path.len) return error.NameTooLong;107 if (path.len + 1 > sock_addr.path.len) return error.NameTooLong;
108108
109 mem.set(u8, &sock_addr.path, 0);109 @memset(&sock_addr.path, 0);
110 mem.copy(u8, &sock_addr.path, path);110 mem.copy(u8, &sock_addr.path, path);
111111
112 return Address{ .un = sock_addr };112 return Address{ .un = sock_addr };
...@@ -346,7 +346,7 @@ pub const Ip6Address = extern struct {...@@ -346,7 +346,7 @@ pub const Ip6Address = extern struct {
346 if (!saw_any_digits) {346 if (!saw_any_digits) {
347 if (abbrv) return error.InvalidCharacter; // ':::'347 if (abbrv) return error.InvalidCharacter; // ':::'
348 if (i != 0) abbrv = true;348 if (i != 0) abbrv = true;
349 mem.set(u8, ip_slice[index..], 0);349 @memset(ip_slice[index..], 0);
350 ip_slice = tail[0..];350 ip_slice = tail[0..];
351 index = 0;351 index = 0;
352 continue;352 continue;
...@@ -465,7 +465,7 @@ pub const Ip6Address = extern struct {...@@ -465,7 +465,7 @@ pub const Ip6Address = extern struct {
465 if (!saw_any_digits) {465 if (!saw_any_digits) {
466 if (abbrv) return error.InvalidCharacter; // ':::'466 if (abbrv) return error.InvalidCharacter; // ':::'
467 if (i != 0) abbrv = true;467 if (i != 0) abbrv = true;
468 mem.set(u8, ip_slice[index..], 0);468 @memset(ip_slice[index..], 0);
469 ip_slice = tail[0..];469 ip_slice = tail[0..];
470 index = 0;470 index = 0;
471 continue;471 continue;
lib/std/os.zig+19-15
...@@ -1881,9 +1881,9 @@ pub fn execvpeZ_expandArg0(...@@ -1881,9 +1881,9 @@ pub fn execvpeZ_expandArg0(
1881 while (it.next()) |search_path| {1881 while (it.next()) |search_path| {
1882 const path_len = search_path.len + file_slice.len + 1;1882 const path_len = search_path.len + file_slice.len + 1;
1883 if (path_buf.len < path_len + 1) return error.NameTooLong;1883 if (path_buf.len < path_len + 1) return error.NameTooLong;
1884 mem.copy(u8, &path_buf, search_path);1884 @memcpy(path_buf[0..search_path.len], search_path);
1885 path_buf[search_path.len] = '/';1885 path_buf[search_path.len] = '/';
1886 mem.copy(u8, path_buf[search_path.len + 1 ..], file_slice);1886 @memcpy(path_buf[search_path.len + 1 ..][0..file_slice.len], file_slice);
1887 path_buf[path_len] = 0;1887 path_buf[path_len] = 0;
1888 const full_path = path_buf[0..path_len :0].ptr;1888 const full_path = path_buf[0..path_len :0].ptr;
1889 switch (arg0_expand) {1889 switch (arg0_expand) {
...@@ -1917,7 +1917,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {...@@ -1917,7 +1917,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {
1917 if (builtin.link_libc) {1917 if (builtin.link_libc) {
1918 var small_key_buf: [64]u8 = undefined;1918 var small_key_buf: [64]u8 = undefined;
1919 if (key.len < small_key_buf.len) {1919 if (key.len < small_key_buf.len) {
1920 mem.copy(u8, &small_key_buf, key);1920 @memcpy(small_key_buf[0..key.len], key);
1921 small_key_buf[key.len] = 0;1921 small_key_buf[key.len] = 0;
1922 const key0 = small_key_buf[0..key.len :0];1922 const key0 = small_key_buf[0..key.len :0];
1923 return getenvZ(key0);1923 return getenvZ(key0);
...@@ -2022,8 +2022,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {...@@ -2022,8 +2022,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
2022 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {2022 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {
2023 const path = ".";2023 const path = ".";
2024 if (out_buffer.len < path.len) return error.NameTooLong;2024 if (out_buffer.len < path.len) return error.NameTooLong;
2025 std.mem.copy(u8, out_buffer, path);2025 const result = out_buffer[0..path.len];
2026 return out_buffer[0..path.len];2026 @memcpy(result, path);
2027 return result;
2027 }2028 }
20282029
2029 const err = if (builtin.link_libc) blk: {2030 const err = if (builtin.link_libc) blk: {
...@@ -2673,7 +2674,7 @@ pub fn renameatW(...@@ -2673,7 +2674,7 @@ pub fn renameatW(
2673 .FileNameLength = @intCast(u32, new_path_w.len * 2), // already checked error.NameTooLong2674 .FileNameLength = @intCast(u32, new_path_w.len * 2), // already checked error.NameTooLong
2674 .FileName = undefined,2675 .FileName = undefined,
2675 };2676 };
2676 std.mem.copy(u16, @as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);2677 @memcpy(@as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);
26772678
2678 var io_status_block: windows.IO_STATUS_BLOCK = undefined;2679 var io_status_block: windows.IO_STATUS_BLOCK = undefined;
26792680
...@@ -5264,8 +5265,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {...@@ -5264,8 +5265,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
5264 }5265 }
5265 const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse MAX_PATH_BYTES;5266 const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse MAX_PATH_BYTES;
5266 if (len == 0) return error.NameTooLong;5267 if (len == 0) return error.NameTooLong;
5267 mem.copy(u8, out_buffer, kfile.path[0..len]);5268 const result = out_buffer[0..len];
5268 return out_buffer[0..len];5269 @memcpy(result, kfile.path[0..len]);
5270 return result;
5269 } else {5271 } else {
5270 // This fallback implementation reimplements libutil's `kinfo_getfile()`.5272 // This fallback implementation reimplements libutil's `kinfo_getfile()`.
5271 // The motivation is to avoid linking -lutil when building zig or general5273 // The motivation is to avoid linking -lutil when building zig or general
...@@ -5296,8 +5298,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {...@@ -5296,8 +5298,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
5296 if (kf.fd == fd) {5298 if (kf.fd == fd) {
5297 len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;5299 len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;
5298 if (len == 0) return error.NameTooLong;5300 if (len == 0) return error.NameTooLong;
5299 mem.copy(u8, out_buffer, kf.path[0..len]);5301 const result = out_buffer[0..len];
5300 return out_buffer[0..len];5302 @memcpy(result, kf.path[0..len]);
5303 return result;
5301 }5304 }
5302 i += @intCast(usize, kf.structsize);5305 i += @intCast(usize, kf.structsize);
5303 }5306 }
...@@ -5686,8 +5689,9 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {...@@ -5686,8 +5689,9 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
5686 if (builtin.os.tag == .linux) {5689 if (builtin.os.tag == .linux) {
5687 const uts = uname();5690 const uts = uname();
5688 const hostname = mem.sliceTo(&uts.nodename, 0);5691 const hostname = mem.sliceTo(&uts.nodename, 0);
5689 mem.copy(u8, name_buffer, hostname);5692 const result = name_buffer[0..hostname.len];
5690 return name_buffer[0..hostname.len];5693 @memcpy(result, hostname);
5694 return result;
5691 }5695 }
56925696
5693 @compileError("TODO implement gethostname for this OS");5697 @compileError("TODO implement gethostname for this OS");
...@@ -5725,7 +5729,7 @@ pub fn res_mkquery(...@@ -5725,7 +5729,7 @@ pub fn res_mkquery(
5725 @memset(q[0..n], 0);5729 @memset(q[0..n], 0);
5726 q[2] = @as(u8, op) * 8 + 1;5730 q[2] = @as(u8, op) * 8 + 1;
5727 q[5] = 1;5731 q[5] = 1;
5728 mem.copy(u8, q[13..], name);5732 @memcpy(q[13..][0..name.len], name);
5729 var i: usize = 13;5733 var i: usize = 13;
5730 var j: usize = undefined;5734 var j: usize = undefined;
5731 while (q[i] != 0) : (i = j + 1) {5735 while (q[i] != 0) : (i = j + 1) {
...@@ -5748,7 +5752,7 @@ pub fn res_mkquery(...@@ -5748,7 +5752,7 @@ pub fn res_mkquery(
5748 q[0] = @truncate(u8, id / 256);5752 q[0] = @truncate(u8, id / 256);
5749 q[1] = @truncate(u8, id);5753 q[1] = @truncate(u8, id);
57505754
5751 mem.copy(u8, buf, q[0..n]);5755 @memcpy(buf[0..n], q[0..n]);
5752 return n;5756 return n;
5753}5757}
57545758
...@@ -6755,7 +6759,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {...@@ -6755,7 +6759,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
6755 var path_with_null: [MFD_MAX_NAME_LEN:0]u8 = undefined;6759 var path_with_null: [MFD_MAX_NAME_LEN:0]u8 = undefined;
6756 // >= rather than > to make room for the null byte6760 // >= rather than > to make room for the null byte
6757 if (name.len >= MFD_MAX_NAME_LEN) return error.NameTooLong;6761 if (name.len >= MFD_MAX_NAME_LEN) return error.NameTooLong;
6758 mem.copy(u8, &path_with_null, name);6762 @memcpy(path_with_null[0..name.len], name);
6759 path_with_null[name.len] = 0;6763 path_with_null[name.len] = 0;
6760 return path_with_null;6764 return path_with_null;
6761}6765}
lib/std/os/linux/io_uring.zig+4-4
...@@ -1855,7 +1855,7 @@ test "write_fixed/read_fixed" {...@@ -1855,7 +1855,7 @@ test "write_fixed/read_fixed" {
18551855
1856 var raw_buffers: [2][11]u8 = undefined;1856 var raw_buffers: [2][11]u8 = undefined;
1857 // First buffer will be written to the file.1857 // First buffer will be written to the file.
1858 std.mem.set(u8, &raw_buffers[0], 'z');1858 @memset(&raw_buffers[0], 'z');
1859 std.mem.copy(u8, &raw_buffers[0], "foobar");1859 std.mem.copy(u8, &raw_buffers[0], "foobar");
18601860
1861 var buffers = [2]os.iovec{1861 var buffers = [2]os.iovec{
...@@ -2966,7 +2966,7 @@ test "provide_buffers: read" {...@@ -2966,7 +2966,7 @@ test "provide_buffers: read" {
2966 // Provide 1 buffer again2966 // Provide 1 buffer again
29672967
2968 // Deliberately put something we don't expect in the buffers2968 // Deliberately put something we don't expect in the buffers
2969 mem.set(u8, mem.sliceAsBytes(&buffers), 42);2969 @memset(mem.sliceAsBytes(&buffers), 42);
29702970
2971 const reprovided_buffer_id = 2;2971 const reprovided_buffer_id = 2;
29722972
...@@ -3155,7 +3155,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3155,7 +3155,7 @@ test "provide_buffers: accept/connect/send/recv" {
3155 // Do 4 recv which should consume all buffers3155 // Do 4 recv which should consume all buffers
31563156
3157 // Deliberately put something we don't expect in the buffers3157 // Deliberately put something we don't expect in the buffers
3158 mem.set(u8, mem.sliceAsBytes(&buffers), 1);3158 @memset(mem.sliceAsBytes(&buffers), 1);
31593159
3160 var i: usize = 0;3160 var i: usize = 0;
3161 while (i < buffers.len) : (i += 1) {3161 while (i < buffers.len) : (i += 1) {
...@@ -3235,7 +3235,7 @@ test "provide_buffers: accept/connect/send/recv" {...@@ -3235,7 +3235,7 @@ test "provide_buffers: accept/connect/send/recv" {
3235 // Final recv which should work3235 // Final recv which should work
32363236
3237 // Deliberately put something we don't expect in the buffers3237 // Deliberately put something we don't expect in the buffers
3238 mem.set(u8, mem.sliceAsBytes(&buffers), 1);3238 @memset(mem.sliceAsBytes(&buffers), 1);
32393239
3240 {3240 {
3241 var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);3241 var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);
lib/std/os/linux/tls.zig+1-1
...@@ -275,7 +275,7 @@ inline fn alignPtrCast(comptime T: type, ptr: [*]u8) *T {...@@ -275,7 +275,7 @@ inline fn alignPtrCast(comptime T: type, ptr: [*]u8) *T {
275/// architecture-specific value of the thread-pointer register275/// architecture-specific value of the thread-pointer register
276pub fn prepareTLS(area: []u8) usize {276pub fn prepareTLS(area: []u8) usize {
277 // Clear the area we're going to use, just to be safe277 // Clear the area we're going to use, just to be safe
278 mem.set(u8, area, 0);278 @memset(area, 0);
279 // Prepare the DTV279 // Prepare the DTV
280 const dtv = alignPtrCast(DTV, area.ptr + tls_image.dtv_offset);280 const dtv = alignPtrCast(DTV, area.ptr + tls_image.dtv_offset);
281 dtv.entries = 1;281 dtv.entries = 1;
lib/std/os/test.zig+1-1
...@@ -587,7 +587,7 @@ test "mmap" {...@@ -587,7 +587,7 @@ test "mmap" {
587 try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));587 try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
588588
589 // Make sure the memory is writeable as requested589 // Make sure the memory is writeable as requested
590 std.mem.set(u8, data, 0x55);590 @memset(data, 0x55);
591 try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));591 try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
592 }592 }
593593
lib/std/process.zig+1-1
...@@ -855,7 +855,7 @@ pub fn argsAlloc(allocator: Allocator) ![][:0]u8 {...@@ -855,7 +855,7 @@ pub fn argsAlloc(allocator: Allocator) ![][:0]u8 {
855855
856 const result_slice_list = mem.bytesAsSlice([:0]u8, buf[0..slice_list_bytes]);856 const result_slice_list = mem.bytesAsSlice([:0]u8, buf[0..slice_list_bytes]);
857 const result_contents = buf[slice_list_bytes..];857 const result_contents = buf[slice_list_bytes..];
858 mem.copy(u8, result_contents, contents_slice);858 @memcpy(result_contents[0..contents_slice.len], contents_slice);
859859
860 var contents_index: usize = 0;860 var contents_index: usize = 0;
861 for (slice_sizes, 0..) |len, i| {861 for (slice_sizes, 0..) |len, i| {
lib/std/rand/ChaCha.zig+7-6
...@@ -40,7 +40,8 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void {...@@ -40,7 +40,8 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void {
40 }40 }
41 if (i < bytes.len) {41 if (i < bytes.len) {
42 var k = [_]u8{0} ** Cipher.key_length;42 var k = [_]u8{0} ** Cipher.key_length;
43 mem.copy(u8, k[0..], bytes[i..]);43 const src = bytes[i..];
44 @memcpy(k[0..src.len], src);
44 Cipher.xor(45 Cipher.xor(
45 self.state[0..Cipher.key_length],46 self.state[0..Cipher.key_length],
46 self.state[0..Cipher.key_length],47 self.state[0..Cipher.key_length],
...@@ -72,8 +73,8 @@ pub fn fill(self: *Self, buf_: []u8) void {...@@ -72,8 +73,8 @@ pub fn fill(self: *Self, buf_: []u8) void {
72 if (avail > 0) {73 if (avail > 0) {
73 // Bytes from the current block74 // Bytes from the current block
74 const n = @min(avail, buf.len);75 const n = @min(avail, buf.len);
75 mem.copy(u8, buf[0..n], bytes[self.offset..][0..n]);76 @memcpy(buf[0..n], bytes[self.offset..][0..n]);
76 mem.set(u8, bytes[self.offset..][0..n], 0);77 @memset(bytes[self.offset..][0..n], 0);
77 buf = buf[n..];78 buf = buf[n..];
78 self.offset += n;79 self.offset += n;
79 }80 }
...@@ -83,15 +84,15 @@ pub fn fill(self: *Self, buf_: []u8) void {...@@ -83,15 +84,15 @@ pub fn fill(self: *Self, buf_: []u8) void {
8384
84 // Full blocks85 // Full blocks
85 while (buf.len >= bytes.len) {86 while (buf.len >= bytes.len) {
86 mem.copy(u8, buf[0..bytes.len], bytes);87 @memcpy(buf[0..bytes.len], bytes);
87 buf = buf[bytes.len..];88 buf = buf[bytes.len..];
88 self.refill();89 self.refill();
89 }90 }
9091
91 // Remaining bytes92 // Remaining bytes
92 if (buf.len > 0) {93 if (buf.len > 0) {
93 mem.copy(u8, buf, bytes[0..buf.len]);94 @memcpy(buf, bytes[0..buf.len]);
94 mem.set(u8, bytes[0..buf.len], 0);95 @memset(bytes[0..buf.len], 0);
95 self.offset = buf.len;96 self.offset = buf.len;
96 }97 }
97}98}
lib/std/rand/Isaac64.zig+2-2
...@@ -87,7 +87,7 @@ fn next(self: *Isaac64) u64 {...@@ -87,7 +87,7 @@ fn next(self: *Isaac64) u64 {
87fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {87fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
88 // We ignore the multi-pass requirement since we don't currently expose full access to88 // We ignore the multi-pass requirement since we don't currently expose full access to
89 // seeding the self.m array completely.89 // seeding the self.m array completely.
90 mem.set(u64, self.m[0..], 0);90 @memset(self.m[0..], 0);
91 self.m[0] = init_s;91 self.m[0] = init_s;
9292
93 // prescrambled golden ratio constants93 // prescrambled golden ratio constants
...@@ -143,7 +143,7 @@ fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {...@@ -143,7 +143,7 @@ fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
143 }143 }
144 }144 }
145145
146 mem.set(u64, self.r[0..], 0);146 @memset(self.r[0..], 0);
147 self.a = 0;147 self.a = 0;
148 self.b = 0;148 self.b = 0;
149 self.c = 0;149 self.c = 0;
lib/std/segmented_list.zig+10-13
...@@ -230,7 +230,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -230,7 +230,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
230 allocator.free(new_dynamic_segments);230 allocator.free(new_dynamic_segments);
231 } else {231 } else {
232 // Good thing we allocated that new memory slice.232 // Good thing we allocated that new memory slice.
233 mem.copy([*]T, new_dynamic_segments, self.dynamic_segments[0..new_cap_shelf_count]);233 @memcpy(new_dynamic_segments, self.dynamic_segments[0..new_cap_shelf_count]);
234 allocator.free(self.dynamic_segments);234 allocator.free(self.dynamic_segments);
235 self.dynamic_segments = new_dynamic_segments;235 self.dynamic_segments = new_dynamic_segments;
236 }236 }
...@@ -248,24 +248,21 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -248,24 +248,21 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
248248
249 var i = start;249 var i = start;
250 if (end <= prealloc_item_count) {250 if (end <= prealloc_item_count) {
251 mem.copy(T, dest[i - start ..], self.prealloc_segment[i..end]);251 const src = self.prealloc_segment[i..end];
252 @memcpy(dest[i - start ..][0..src.len], src);
252 return;253 return;
253 } else if (i < prealloc_item_count) {254 } else if (i < prealloc_item_count) {
254 mem.copy(T, dest[i - start ..], self.prealloc_segment[i..]);255 const src = self.prealloc_segment[i..];
256 @memcpy(dest[i - start ..][0..src.len], src);
255 i = prealloc_item_count;257 i = prealloc_item_count;
256 }258 }
257259
258 while (i < end) {260 while (i < end) {
259 const shelf_index = shelfIndex(i);261 const shelf_index = shelfIndex(i);
260 const copy_start = boxIndex(i, shelf_index);262 const copy_start = boxIndex(i, shelf_index);
261 const copy_end = std.math.min(shelfSize(shelf_index), copy_start + end - i);263 const copy_end = @min(shelfSize(shelf_index), copy_start + end - i);
262264 const src = self.dynamic_segments[shelf_index][copy_start..copy_end];
263 mem.copy(265 @memcpy(dest[i - start ..][0..src.len], src);
264 T,
265 dest[i - start ..],
266 self.dynamic_segments[shelf_index][copy_start..copy_end],
267 );
268
269 i += (copy_end - copy_start);266 i += (copy_end - copy_start);
270 }267 }
271 }268 }
...@@ -498,11 +495,11 @@ fn testSegmentedList(comptime prealloc: usize) !void {...@@ -498,11 +495,11 @@ fn testSegmentedList(comptime prealloc: usize) !void {
498 control[@intCast(usize, i)] = i + 1;495 control[@intCast(usize, i)] = i + 1;
499 }496 }
500497
501 mem.set(i32, dest[0..], 0);498 @memset(dest[0..], 0);
502 list.writeToSlice(dest[0..], 0);499 list.writeToSlice(dest[0..], 0);
503 try testing.expect(mem.eql(i32, control[0..], dest[0..]));500 try testing.expect(mem.eql(i32, control[0..], dest[0..]));
504501
505 mem.set(i32, dest[0..], 0);502 @memset(dest[0..], 0);
506 list.writeToSlice(dest[50..], 50);503 list.writeToSlice(dest[50..], 50);
507 try testing.expect(mem.eql(i32, control[50..], dest[50..]));504 try testing.expect(mem.eql(i32, control[50..], dest[50..]));
508 }505 }
lib/std/sort.zig+38-21
...@@ -361,8 +361,10 @@ pub fn sort(...@@ -361,8 +361,10 @@ pub fn sort(
361361
362 if (lessThan(context, items[B1.end - 1], items[A1.start])) {362 if (lessThan(context, items[B1.end - 1], items[A1.start])) {
363 // the two ranges are in reverse order, so copy them in reverse order into the cache363 // the two ranges are in reverse order, so copy them in reverse order into the cache
364 mem.copy(T, cache[B1.length()..], items[A1.start..A1.end]);364 const a1_items = items[A1.start..A1.end];
365 mem.copy(T, cache[0..], items[B1.start..B1.end]);365 @memcpy(cache[B1.length()..][0..a1_items.len], a1_items);
366 const b1_items = items[B1.start..B1.end];
367 @memcpy(cache[0..b1_items.len], b1_items);
366 } else if (lessThan(context, items[B1.start], items[A1.end - 1])) {368 } else if (lessThan(context, items[B1.start], items[A1.end - 1])) {
367 // these two ranges weren't already in order, so merge them into the cache369 // these two ranges weren't already in order, so merge them into the cache
368 mergeInto(T, items, A1, B1, context, lessThan, cache[0..]);370 mergeInto(T, items, A1, B1, context, lessThan, cache[0..]);
...@@ -371,23 +373,29 @@ pub fn sort(...@@ -371,23 +373,29 @@ pub fn sort(
371 if (!lessThan(context, items[B2.start], items[A2.end - 1]) and !lessThan(context, items[A2.start], items[B1.end - 1])) continue;373 if (!lessThan(context, items[B2.start], items[A2.end - 1]) and !lessThan(context, items[A2.start], items[B1.end - 1])) continue;
372374
373 // copy A1 and B1 into the cache in the same order375 // copy A1 and B1 into the cache in the same order
374 mem.copy(T, cache[0..], items[A1.start..A1.end]);376 const a1_items = items[A1.start..A1.end];
375 mem.copy(T, cache[A1.length()..], items[B1.start..B1.end]);377 @memcpy(cache[0..a1_items.len], a1_items);
378 const b1_items = items[B1.start..B1.end];
379 @memcpy(cache[A1.length()..][0..b1_items.len], b1_items);
376 }380 }
377 A1 = Range.init(A1.start, B1.end);381 A1 = Range.init(A1.start, B1.end);
378382
379 // merge A2 and B2 into the cache383 // merge A2 and B2 into the cache
380 if (lessThan(context, items[B2.end - 1], items[A2.start])) {384 if (lessThan(context, items[B2.end - 1], items[A2.start])) {
381 // the two ranges are in reverse order, so copy them in reverse order into the cache385 // the two ranges are in reverse order, so copy them in reverse order into the cache
382 mem.copy(T, cache[A1.length() + B2.length() ..], items[A2.start..A2.end]);386 const a2_items = items[A2.start..A2.end];
383 mem.copy(T, cache[A1.length()..], items[B2.start..B2.end]);387 @memcpy(cache[A1.length() + B2.length() ..][0..a2_items.len], a2_items);
388 const b2_items = items[B2.start..B2.end];
389 @memcpy(cache[A1.length()..][0..b2_items.len], b2_items);
384 } else if (lessThan(context, items[B2.start], items[A2.end - 1])) {390 } else if (lessThan(context, items[B2.start], items[A2.end - 1])) {
385 // these two ranges weren't already in order, so merge them into the cache391 // these two ranges weren't already in order, so merge them into the cache
386 mergeInto(T, items, A2, B2, context, lessThan, cache[A1.length()..]);392 mergeInto(T, items, A2, B2, context, lessThan, cache[A1.length()..]);
387 } else {393 } else {
388 // copy A2 and B2 into the cache in the same order394 // copy A2 and B2 into the cache in the same order
389 mem.copy(T, cache[A1.length()..], items[A2.start..A2.end]);395 const a2_items = items[A2.start..A2.end];
390 mem.copy(T, cache[A1.length() + A2.length() ..], items[B2.start..B2.end]);396 @memcpy(cache[A1.length()..][0..a2_items.len], a2_items);
397 const b2_items = items[B2.start..B2.end];
398 @memcpy(cache[A1.length() + A2.length() ..][0..b2_items.len], b2_items);
391 }399 }
392 A2 = Range.init(A2.start, B2.end);400 A2 = Range.init(A2.start, B2.end);
393401
...@@ -397,15 +405,19 @@ pub fn sort(...@@ -397,15 +405,19 @@ pub fn sort(
397405
398 if (lessThan(context, cache[B3.end - 1], cache[A3.start])) {406 if (lessThan(context, cache[B3.end - 1], cache[A3.start])) {
399 // the two ranges are in reverse order, so copy them in reverse order into the items407 // the two ranges are in reverse order, so copy them in reverse order into the items
400 mem.copy(T, items[A1.start + A2.length() ..], cache[A3.start..A3.end]);408 const a3_items = cache[A3.start..A3.end];
401 mem.copy(T, items[A1.start..], cache[B3.start..B3.end]);409 @memcpy(items[A1.start + A2.length() ..][0..a3_items.len], a3_items);
410 const b3_items = cache[B3.start..B3.end];
411 @memcpy(items[A1.start..][0..b3_items.len], b3_items);
402 } else if (lessThan(context, cache[B3.start], cache[A3.end - 1])) {412 } else if (lessThan(context, cache[B3.start], cache[A3.end - 1])) {
403 // these two ranges weren't already in order, so merge them back into the items413 // these two ranges weren't already in order, so merge them back into the items
404 mergeInto(T, cache[0..], A3, B3, context, lessThan, items[A1.start..]);414 mergeInto(T, cache[0..], A3, B3, context, lessThan, items[A1.start..]);
405 } else {415 } else {
406 // copy A3 and B3 into the items in the same order416 // copy A3 and B3 into the items in the same order
407 mem.copy(T, items[A1.start..], cache[A3.start..A3.end]);417 const a3_items = cache[A3.start..A3.end];
408 mem.copy(T, items[A1.start + A1.length() ..], cache[B3.start..B3.end]);418 @memcpy(items[A1.start..][0..a3_items.len], a3_items);
419 const b3_items = cache[B3.start..B3.end];
420 @memcpy(items[A1.start + A1.length() ..][0..b3_items.len], b3_items);
409 }421 }
410 }422 }
411423
...@@ -423,7 +435,8 @@ pub fn sort(...@@ -423,7 +435,8 @@ pub fn sort(
423 mem.rotate(T, items[A.start..B.end], A.length());435 mem.rotate(T, items[A.start..B.end], A.length());
424 } else if (lessThan(context, items[B.start], items[A.end - 1])) {436 } else if (lessThan(context, items[B.start], items[A.end - 1])) {
425 // these two ranges weren't already in order, so we'll need to merge them!437 // these two ranges weren't already in order, so we'll need to merge them!
426 mem.copy(T, cache[0..], items[A.start..A.end]);438 const a_items = items[A.start..A.end];
439 @memcpy(cache[0..a_items.len], a_items);
427 mergeExternal(T, items, A, B, context, lessThan, cache[0..]);440 mergeExternal(T, items, A, B, context, lessThan, cache[0..]);
428 }441 }
429 }442 }
...@@ -718,7 +731,8 @@ pub fn sort(...@@ -718,7 +731,8 @@ pub fn sort(
718 // if the first unevenly sized A block fits into the cache, copy it there for when we go to Merge it731 // if the first unevenly sized A block fits into the cache, copy it there for when we go to Merge it
719 // otherwise, if the second buffer is available, block swap the contents into that732 // otherwise, if the second buffer is available, block swap the contents into that
720 if (lastA.length() <= cache.len) {733 if (lastA.length() <= cache.len) {
721 mem.copy(T, cache[0..], items[lastA.start..lastA.end]);734 const last_a_items = items[lastA.start..lastA.end];
735 @memcpy(cache[0..last_a_items.len], last_a_items);
722 } else if (buffer2.length() > 0) {736 } else if (buffer2.length() > 0) {
723 blockSwap(T, items, lastA.start, buffer2.start, lastA.length());737 blockSwap(T, items, lastA.start, buffer2.start, lastA.length());
724 }738 }
...@@ -762,7 +776,7 @@ pub fn sort(...@@ -762,7 +776,7 @@ pub fn sort(
762 if (buffer2.length() > 0 or block_size <= cache.len) {776 if (buffer2.length() > 0 or block_size <= cache.len) {
763 // copy the previous A block into the cache or buffer2, since that's where we need it to be when we go to merge it anyway777 // copy the previous A block into the cache or buffer2, since that's where we need it to be when we go to merge it anyway
764 if (block_size <= cache.len) {778 if (block_size <= cache.len) {
765 mem.copy(T, cache[0..], items[blockA.start .. blockA.start + block_size]);779 @memcpy(cache[0..block_size], items[blockA.start..][0..block_size]);
766 } else {780 } else {
767 blockSwap(T, items, blockA.start, buffer2.start, block_size);781 blockSwap(T, items, blockA.start, buffer2.start, block_size);
768 }782 }
...@@ -1122,7 +1136,8 @@ fn mergeInto(...@@ -1122,7 +1136,8 @@ fn mergeInto(
1122 insert_index += 1;1136 insert_index += 1;
1123 if (A_index == A_last) {1137 if (A_index == A_last) {
1124 // copy the remainder of B into the final array1138 // copy the remainder of B into the final array
1125 mem.copy(T, into[insert_index..], from[B_index..B_last]);1139 const from_b = from[B_index..B_last];
1140 @memcpy(into[insert_index..][0..from_b.len], from_b);
1126 break;1141 break;
1127 }1142 }
1128 } else {1143 } else {
...@@ -1131,7 +1146,8 @@ fn mergeInto(...@@ -1131,7 +1146,8 @@ fn mergeInto(
1131 insert_index += 1;1146 insert_index += 1;
1132 if (B_index == B_last) {1147 if (B_index == B_last) {
1133 // copy the remainder of A into the final array1148 // copy the remainder of A into the final array
1134 mem.copy(T, into[insert_index..], from[A_index..A_last]);1149 const from_a = from[A_index..A_last];
1150 @memcpy(into[insert_index..][0..from_a.len], from_a);
1135 break;1151 break;
1136 }1152 }
1137 }1153 }
...@@ -1171,7 +1187,8 @@ fn mergeExternal(...@@ -1171,7 +1187,8 @@ fn mergeExternal(
1171 }1187 }
11721188
1173 // copy the remainder of A into the final array1189 // copy the remainder of A into the final array
1174 mem.copy(T, items[insert_index..], cache[A_index..A_last]);1190 const cache_a = cache[A_index..A_last];
1191 @memcpy(items[insert_index..][0..cache_a.len], cache_a);
1175}1192}
11761193
1177fn swap(1194fn swap(
...@@ -1305,7 +1322,7 @@ test "sort" {...@@ -1305,7 +1322,7 @@ test "sort" {
1305 for (u8cases) |case| {1322 for (u8cases) |case| {
1306 var buf: [8]u8 = undefined;1323 var buf: [8]u8 = undefined;
1307 const slice = buf[0..case[0].len];1324 const slice = buf[0..case[0].len];
1308 mem.copy(u8, slice, case[0]);1325 @memcpy(slice, case[0]);
1309 sort(u8, slice, {}, asc_u8);1326 sort(u8, slice, {}, asc_u8);
1310 try testing.expect(mem.eql(u8, slice, case[1]));1327 try testing.expect(mem.eql(u8, slice, case[1]));
1311 }1328 }
...@@ -1340,7 +1357,7 @@ test "sort" {...@@ -1340,7 +1357,7 @@ test "sort" {
1340 for (i32cases) |case| {1357 for (i32cases) |case| {
1341 var buf: [8]i32 = undefined;1358 var buf: [8]i32 = undefined;
1342 const slice = buf[0..case[0].len];1359 const slice = buf[0..case[0].len];
1343 mem.copy(i32, slice, case[0]);1360 @memcpy(slice, case[0]);
1344 sort(i32, slice, {}, asc_i32);1361 sort(i32, slice, {}, asc_i32);
1345 try testing.expect(mem.eql(i32, slice, case[1]));1362 try testing.expect(mem.eql(i32, slice, case[1]));
1346 }1363 }
...@@ -1377,7 +1394,7 @@ test "sort descending" {...@@ -1377,7 +1394,7 @@ test "sort descending" {
1377 for (rev_cases) |case| {1394 for (rev_cases) |case| {
1378 var buf: [8]i32 = undefined;1395 var buf: [8]i32 = undefined;
1379 const slice = buf[0..case[0].len];1396 const slice = buf[0..case[0].len];
1380 mem.copy(i32, slice, case[0]);1397 @memcpy(slice, case[0]);
1381 sort(i32, slice, {}, desc_i32);1398 sort(i32, slice, {}, desc_i32);
1382 try testing.expect(mem.eql(i32, slice, case[1]));1399 try testing.expect(mem.eql(i32, slice, case[1]));
1383 }1400 }
lib/std/target.zig+2-2
...@@ -1596,7 +1596,7 @@ pub const Target = struct {...@@ -1596,7 +1596,7 @@ pub const Target = struct {
1596 /// Asserts that the length is less than or equal to 255 bytes.1596 /// Asserts that the length is less than or equal to 255 bytes.
1597 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {1597 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {
1598 if (dl_or_null) |dl| {1598 if (dl_or_null) |dl| {
1599 mem.copy(u8, &self.buffer, dl);1599 @memcpy(self.buffer[0..dl.len], dl);
1600 self.max_byte = @intCast(u8, dl.len - 1);1600 self.max_byte = @intCast(u8, dl.len - 1);
1601 } else {1601 } else {
1602 self.max_byte = null;1602 self.max_byte = null;
...@@ -1612,7 +1612,7 @@ pub const Target = struct {...@@ -1612,7 +1612,7 @@ pub const Target = struct {
1612 return r.*;1612 return r.*;
1613 }1613 }
1614 fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {1614 fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {
1615 mem.copy(u8, &r.buffer, s);1615 @memcpy(r.buffer[0..s.len], s);
1616 r.max_byte = @intCast(u8, s.len - 1);1616 r.max_byte = @intCast(u8, s.len - 1);
1617 return r.*;1617 return r.*;
1618 }1618 }
lib/std/testing/failing_allocator.zig+1-1
...@@ -66,7 +66,7 @@ pub const FailingAllocator = struct {...@@ -66,7 +66,7 @@ pub const FailingAllocator = struct {
66 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));66 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));
67 if (self.index == self.fail_index) {67 if (self.index == self.fail_index) {
68 if (!self.has_induced_failure) {68 if (!self.has_induced_failure) {
69 mem.set(usize, &self.stack_addresses, 0);69 @memset(&self.stack_addresses, 0);
70 var stack_trace = std.builtin.StackTrace{70 var stack_trace = std.builtin.StackTrace{
71 .instruction_addresses = &self.stack_addresses,71 .instruction_addresses = &self.stack_addresses,
72 .index = 0,72 .index = 0,
lib/std/tz.zig+1-1
...@@ -137,7 +137,7 @@ pub const Tz = struct {...@@ -137,7 +137,7 @@ pub const Tz = struct {
137 const name = std.mem.sliceTo(designators[tt.name_data[0]..], 0);137 const name = std.mem.sliceTo(designators[tt.name_data[0]..], 0);
138 // We are mandating the "SHOULD" 6-character limit so we can pack the struct better, and to conform to POSIX.138 // We are mandating the "SHOULD" 6-character limit so we can pack the struct better, and to conform to POSIX.
139 if (name.len > 6) return error.Malformed; // rfc8536: Time zone designations SHOULD consist of at least three (3) and no more than six (6) ASCII characters.139 if (name.len > 6) return error.Malformed; // rfc8536: Time zone designations SHOULD consist of at least three (3) and no more than six (6) ASCII characters.
140 std.mem.copy(u8, tt.name_data[0..], name);140 @memcpy(tt.name_data[0..name.len], name);
141 tt.name_data[name.len] = 0;141 tt.name_data[name.len] = 0;
142 }142 }
143143
lib/std/zig/render.zig+2-2
...@@ -1889,11 +1889,11 @@ fn renderArrayInit(...@@ -1889,11 +1889,11 @@ fn renderArrayInit(
1889 // A place to store the width of each expression and its column's maximum1889 // A place to store the width of each expression and its column's maximum
1890 const widths = try gpa.alloc(usize, row_exprs.len + row_size);1890 const widths = try gpa.alloc(usize, row_exprs.len + row_size);
1891 defer gpa.free(widths);1891 defer gpa.free(widths);
1892 mem.set(usize, widths, 0);1892 @memset(widths, 0);
18931893
1894 const expr_newlines = try gpa.alloc(bool, row_exprs.len);1894 const expr_newlines = try gpa.alloc(bool, row_exprs.len);
1895 defer gpa.free(expr_newlines);1895 defer gpa.free(expr_newlines);
1896 mem.set(bool, expr_newlines, false);1896 @memset(expr_newlines, false);
18971897
1898 const expr_widths = widths[0..row_exprs.len];1898 const expr_widths = widths[0..row_exprs.len];
1899 const column_widths = widths[row_exprs.len..];1899 const column_widths = widths[row_exprs.len..];
lib/std/zig/system/NativeTargetInfo.zig+4-4
...@@ -877,17 +877,17 @@ pub fn abiAndDynamicLinkerFromFile(...@@ -877,17 +877,17 @@ pub fn abiAndDynamicLinkerFromFile(
877 const cpu_arch = @tagName(result.target.cpu.arch);877 const cpu_arch = @tagName(result.target.cpu.arch);
878 const os_tag = @tagName(result.target.os.tag);878 const os_tag = @tagName(result.target.os.tag);
879 const abi = @tagName(result.target.abi);879 const abi = @tagName(result.target.abi);
880 mem.copy(u8, path_buf[index..], prefix);880 @memcpy(path_buf[index..][0..prefix.len], prefix);
881 index += prefix.len;881 index += prefix.len;
882 mem.copy(u8, path_buf[index..], cpu_arch);882 @memcpy(path_buf[index..][0..cpu_arch.len], cpu_arch);
883 index += cpu_arch.len;883 index += cpu_arch.len;
884 path_buf[index] = '-';884 path_buf[index] = '-';
885 index += 1;885 index += 1;
886 mem.copy(u8, path_buf[index..], os_tag);886 @memcpy(path_buf[index..][0..os_tag.len], os_tag);
887 index += os_tag.len;887 index += os_tag.len;
888 path_buf[index] = '-';888 path_buf[index] = '-';
889 index += 1;889 index += 1;
890 mem.copy(u8, path_buf[index..], abi);890 @memcpy(path_buf[index..][0..abi.len], abi);
891 index += abi.len;891 index += abi.len;
892 const rpath = path_buf[0..index];892 const rpath = path_buf[0..index];
893 if (glibcVerFromRPath(rpath)) |ver| {893 if (glibcVerFromRPath(rpath)) |ver| {
lib/std/zig/system/windows.zig+2-2
...@@ -171,10 +171,10 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {...@@ -171,10 +171,10 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
171 const entry = @ptrCast([*]align(1) const u8, table[i + 1].EntryContext);171 const entry = @ptrCast([*]align(1) const u8, table[i + 1].EntryContext);
172 switch (@field(args, field.name).value_type) {172 switch (@field(args, field.name).value_type) {
173 REG.DWORD, REG.DWORD_BIG_ENDIAN => {173 REG.DWORD, REG.DWORD_BIG_ENDIAN => {
174 mem.copy(u8, @field(args, field.name).value_buf[0..4], entry[0..4]);174 @memcpy(@field(args, field.name).value_buf[0..4], entry[0..4]);
175 },175 },
176 REG.QWORD => {176 REG.QWORD => {
177 mem.copy(u8, @field(args, field.name).value_buf[0..8], entry[0..8]);177 @memcpy(@field(args, field.name).value_buf[0..8], entry[0..8]);
178 },178 },
179 else => unreachable,179 else => unreachable,
180 }180 }
src/Compilation.zig+3-3
...@@ -2165,7 +2165,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di...@@ -2165,7 +2165,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di
2165 const digest_start = 2; // "o/[digest]/[basename]"2165 const digest_start = 2; // "o/[digest]/[basename]"
21662166
2167 if (comp.whole_bin_sub_path) |sub_path| {2167 if (comp.whole_bin_sub_path) |sub_path| {
2168 mem.copy(u8, sub_path[digest_start..], digest);2168 @memcpy(sub_path[digest_start..][0..digest.len], digest);
21692169
2170 comp.bin_file.options.emit = .{2170 comp.bin_file.options.emit = .{
2171 .directory = comp.local_cache_directory,2171 .directory = comp.local_cache_directory,
...@@ -2174,7 +2174,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di...@@ -2174,7 +2174,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di
2174 }2174 }
21752175
2176 if (comp.whole_implib_sub_path) |sub_path| {2176 if (comp.whole_implib_sub_path) |sub_path| {
2177 mem.copy(u8, sub_path[digest_start..], digest);2177 @memcpy(sub_path[digest_start..][0..digest.len], digest);
21782178
2179 comp.bin_file.options.implib_emit = .{2179 comp.bin_file.options.implib_emit = .{
2180 .directory = comp.local_cache_directory,2180 .directory = comp.local_cache_directory,
...@@ -4432,7 +4432,7 @@ pub fn addCCArgs(...@@ -4432,7 +4432,7 @@ pub fn addCCArgs(
4432 assert(prefix.len == prefix_len);4432 assert(prefix.len == prefix_len);
4433 var march_buf: [prefix_len + letters.len + 1]u8 = undefined;4433 var march_buf: [prefix_len + letters.len + 1]u8 = undefined;
4434 var march_index: usize = prefix_len;4434 var march_index: usize = prefix_len;
4435 mem.copy(u8, &march_buf, prefix);4435 @memcpy(march_buf[0..prefix.len], prefix);
44364436
4437 if (std.Target.riscv.featureSetHas(target.cpu.features, .e)) {4437 if (std.Target.riscv.featureSetHas(target.cpu.features, .e)) {
4438 march_buf[march_index] = 'e';4438 march_buf[march_index] = 'e';
src/Liveness.zig+4-4
...@@ -156,7 +156,7 @@ pub fn analyze(gpa: Allocator, air: Air) Allocator.Error!Liveness {...@@ -156,7 +156,7 @@ pub fn analyze(gpa: Allocator, air: Air) Allocator.Error!Liveness {
156 errdefer a.special.deinit(gpa);156 errdefer a.special.deinit(gpa);
157 defer a.extra.deinit(gpa);157 defer a.extra.deinit(gpa);
158158
159 std.mem.set(usize, a.tomb_bits, 0);159 @memset(a.tomb_bits, 0);
160160
161 const main_body = air.getMainBody();161 const main_body = air.getMainBody();
162162
...@@ -1841,7 +1841,7 @@ fn analyzeInstSwitchBr(...@@ -1841,7 +1841,7 @@ fn analyzeInstSwitchBr(
1841 var case_infos = try gpa.alloc(ControlBranchInfo, ncases + 1); // +1 for else1841 var case_infos = try gpa.alloc(ControlBranchInfo, ncases + 1); // +1 for else
1842 defer gpa.free(case_infos);1842 defer gpa.free(case_infos);
18431843
1844 std.mem.set(ControlBranchInfo, case_infos, .{});1844 @memset(case_infos, .{});
1845 defer for (case_infos) |*info| {1845 defer for (case_infos) |*info| {
1846 info.branch_deaths.deinit(gpa);1846 info.branch_deaths.deinit(gpa);
1847 info.live_set.deinit(gpa);1847 info.live_set.deinit(gpa);
...@@ -1898,7 +1898,7 @@ fn analyzeInstSwitchBr(...@@ -1898,7 +1898,7 @@ fn analyzeInstSwitchBr(
1898 const mirrored_deaths = try gpa.alloc(DeathList, ncases + 1);1898 const mirrored_deaths = try gpa.alloc(DeathList, ncases + 1);
1899 defer gpa.free(mirrored_deaths);1899 defer gpa.free(mirrored_deaths);
19001900
1901 std.mem.set(DeathList, mirrored_deaths, .{});1901 @memset(mirrored_deaths, .{});
1902 defer for (mirrored_deaths) |*md| md.deinit(gpa);1902 defer for (mirrored_deaths) |*md| md.deinit(gpa);
19031903
1904 {1904 {
...@@ -1993,7 +1993,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {...@@ -1993,7 +1993,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
1993 };1993 };
1994 errdefer a.gpa.free(extra_tombs);1994 errdefer a.gpa.free(extra_tombs);
19951995
1996 std.mem.set(u32, extra_tombs, 0);1996 @memset(extra_tombs, 0);
19971997
1998 const will_die_immediately: bool = switch (pass) {1998 const will_die_immediately: bool = switch (pass) {
1999 .loop_analysis => false, // track everything, since we don't have full liveness information yet1999 .loop_analysis => false, // track everything, since we don't have full liveness information yet
src/Sema.zig+22-22
...@@ -206,9 +206,9 @@ pub const InstMap = struct {...@@ -206,9 +206,9 @@ pub const InstMap = struct {
206206
207 const start_diff = old_start - better_start;207 const start_diff = old_start - better_start;
208 const new_items = try allocator.alloc(Air.Inst.Ref, better_capacity);208 const new_items = try allocator.alloc(Air.Inst.Ref, better_capacity);
209 mem.set(Air.Inst.Ref, new_items[0..start_diff], .none);209 @memset(new_items[0..start_diff], .none);
210 mem.copy(Air.Inst.Ref, new_items[start_diff..], map.items);210 @memcpy(new_items[start_diff..][0..map.items.len], map.items);
211 mem.set(Air.Inst.Ref, new_items[start_diff + map.items.len ..], .none);211 @memset(new_items[start_diff + map.items.len ..], .none);
212212
213 allocator.free(map.items);213 allocator.free(map.items);
214 map.items = new_items;214 map.items = new_items;
...@@ -4307,7 +4307,7 @@ fn validateStructInit(...@@ -4307,7 +4307,7 @@ fn validateStructInit(
4307 // Maps field index to field_ptr index of where it was already initialized.4307 // Maps field index to field_ptr index of where it was already initialized.
4308 const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount());4308 const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount());
4309 defer gpa.free(found_fields);4309 defer gpa.free(found_fields);
4310 mem.set(Zir.Inst.Index, found_fields, 0);4310 @memset(found_fields, 0);
43114311
4312 var struct_ptr_zir_ref: Zir.Inst.Ref = undefined;4312 var struct_ptr_zir_ref: Zir.Inst.Ref = undefined;
43134313
...@@ -5113,7 +5113,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -5113,7 +5113,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
5113 const byte_count = int.len * @sizeOf(std.math.big.Limb);5113 const byte_count = int.len * @sizeOf(std.math.big.Limb);
5114 const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count];5114 const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count];
5115 const limbs = try arena.alloc(std.math.big.Limb, int.len);5115 const limbs = try arena.alloc(std.math.big.Limb, int.len);
5116 mem.copy(u8, mem.sliceAsBytes(limbs), limb_bytes);5116 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
51175117
5118 return sema.addConstant(5118 return sema.addConstant(
5119 Type.initTag(.comptime_int),5119 Type.initTag(.comptime_int),
...@@ -5967,7 +5967,7 @@ fn addDbgVar(...@@ -5967,7 +5967,7 @@ fn addDbgVar(
5967 const elements_used = name.len / 4 + 1;5967 const elements_used = name.len / 4 + 1;
5968 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);5968 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);
5969 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());5969 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
5970 mem.copy(u8, buffer, name);5970 @memcpy(buffer[0..name.len], name);
5971 buffer[name.len] = 0;5971 buffer[name.len] = 0;
5972 sema.air_extra.items.len += elements_used;5972 sema.air_extra.items.len += elements_used;
59735973
...@@ -10354,7 +10354,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10354,7 +10354,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10354 .Enum => {10354 .Enum => {
10355 seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount());10355 seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount());
10356 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum();10356 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum();
10357 mem.set(?Module.SwitchProngSrc, seen_enum_fields, null);10357 @memset(seen_enum_fields, null);
10358 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.10358 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.
1035910359
10360 var extra_index: usize = special.end;10360 var extra_index: usize = special.end;
...@@ -12809,8 +12809,8 @@ fn analyzeTupleMul(...@@ -12809,8 +12809,8 @@ fn analyzeTupleMul(
12809 }12809 }
12810 i = 0;12810 i = 0;
12811 while (i < factor) : (i += 1) {12811 while (i < factor) : (i += 1) {
12812 mem.copy(Type, types[tuple_len * i ..], types[0..tuple_len]);12812 mem.copyForwards(Type, types[tuple_len * i ..], types[0..tuple_len]);
12813 mem.copy(Value, values[tuple_len * i ..], values[0..tuple_len]);12813 mem.copyForwards(Value, values[tuple_len * i ..], values[0..tuple_len]);
12814 }12814 }
12815 break :rs runtime_src;12815 break :rs runtime_src;
12816 };12816 };
...@@ -12835,7 +12835,7 @@ fn analyzeTupleMul(...@@ -12835,7 +12835,7 @@ fn analyzeTupleMul(
12835 }12835 }
12836 i = 1;12836 i = 1;
12837 while (i < factor) : (i += 1) {12837 while (i < factor) : (i += 1) {
12838 mem.copy(Air.Inst.Ref, element_refs[tuple_len * i ..], element_refs[0..tuple_len]);12838 @memcpy(element_refs[tuple_len * i ..][0..tuple_len], element_refs[0..tuple_len]);
12839 }12839 }
1284012840
12841 return block.addAggregateInit(tuple_ty, element_refs);12841 return block.addAggregateInit(tuple_ty, element_refs);
...@@ -15057,29 +15057,29 @@ fn zirAsm(...@@ -15057,29 +15057,29 @@ fn zirAsm(
15057 sema.appendRefsAssumeCapacity(args);15057 sema.appendRefsAssumeCapacity(args);
15058 for (outputs) |o| {15058 for (outputs) |o| {
15059 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());15059 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15060 mem.copy(u8, buffer, o.c);15060 @memcpy(buffer[0..o.c.len], o.c);
15061 buffer[o.c.len] = 0;15061 buffer[o.c.len] = 0;
15062 mem.copy(u8, buffer[o.c.len + 1 ..], o.n);15062 @memcpy(buffer[o.c.len + 1 ..][0..o.n.len], o.n);
15063 buffer[o.c.len + 1 + o.n.len] = 0;15063 buffer[o.c.len + 1 + o.n.len] = 0;
15064 sema.air_extra.items.len += (o.c.len + o.n.len + (2 + 3)) / 4;15064 sema.air_extra.items.len += (o.c.len + o.n.len + (2 + 3)) / 4;
15065 }15065 }
15066 for (inputs) |input| {15066 for (inputs) |input| {
15067 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());15067 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15068 mem.copy(u8, buffer, input.c);15068 @memcpy(buffer[0..input.c.len], input.c);
15069 buffer[input.c.len] = 0;15069 buffer[input.c.len] = 0;
15070 mem.copy(u8, buffer[input.c.len + 1 ..], input.n);15070 @memcpy(buffer[input.c.len + 1 ..][0..input.n.len], input.n);
15071 buffer[input.c.len + 1 + input.n.len] = 0;15071 buffer[input.c.len + 1 + input.n.len] = 0;
15072 sema.air_extra.items.len += (input.c.len + input.n.len + (2 + 3)) / 4;15072 sema.air_extra.items.len += (input.c.len + input.n.len + (2 + 3)) / 4;
15073 }15073 }
15074 for (clobbers) |clobber| {15074 for (clobbers) |clobber| {
15075 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());15075 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15076 mem.copy(u8, buffer, clobber);15076 @memcpy(buffer[0..clobber.len], clobber);
15077 buffer[clobber.len] = 0;15077 buffer[clobber.len] = 0;
15078 sema.air_extra.items.len += clobber.len / 4 + 1;15078 sema.air_extra.items.len += clobber.len / 4 + 1;
15079 }15079 }
15080 {15080 {
15081 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());15081 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15082 mem.copy(u8, buffer, asm_source);15082 @memcpy(buffer[0..asm_source.len], asm_source);
15083 sema.air_extra.items.len += (asm_source.len + 3) / 4;15083 sema.air_extra.items.len += (asm_source.len + 3) / 4;
15084 }15084 }
15085 return asm_air;15085 return asm_air;
...@@ -17582,7 +17582,7 @@ fn structInitEmpty(...@@ -17582,7 +17582,7 @@ fn structInitEmpty(
17582 // The init values to use for the struct instance.17582 // The init values to use for the struct instance.
17583 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount());17583 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount());
17584 defer gpa.free(field_inits);17584 defer gpa.free(field_inits);
17585 mem.set(Air.Inst.Ref, field_inits, .none);17585 @memset(field_inits, .none);
1758617586
17587 return sema.finishStructInit(block, init_src, dest_src, field_inits, struct_ty, false);17587 return sema.finishStructInit(block, init_src, dest_src, field_inits, struct_ty, false);
17588}17588}
...@@ -17675,7 +17675,7 @@ fn zirStructInit(...@@ -17675,7 +17675,7 @@ fn zirStructInit(
17675 // The init values to use for the struct instance.17675 // The init values to use for the struct instance.
17676 const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount());17676 const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount());
17677 defer gpa.free(field_inits);17677 defer gpa.free(field_inits);
17678 mem.set(Air.Inst.Ref, field_inits, .none);17678 @memset(field_inits, .none);
1767917679
17680 var field_i: u32 = 0;17680 var field_i: u32 = 0;
17681 var extra_index = extra.end;17681 var extra_index = extra.end;
...@@ -27079,7 +27079,7 @@ fn beginComptimePtrMutation(...@@ -27079,7 +27079,7 @@ fn beginComptimePtrMutation(
27079 const array_len_including_sentinel =27079 const array_len_including_sentinel =
27080 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel());27080 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel());
27081 const elems = try arena.alloc(Value, array_len_including_sentinel);27081 const elems = try arena.alloc(Value, array_len_including_sentinel);
27082 mem.set(Value, elems, Value.undef);27082 @memset(elems, Value.undef);
2708327083
27084 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);27084 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
2708527085
...@@ -27277,7 +27277,7 @@ fn beginComptimePtrMutation(...@@ -27277,7 +27277,7 @@ fn beginComptimePtrMutation(
27277 switch (parent.ty.zigTypeTag()) {27277 switch (parent.ty.zigTypeTag()) {
27278 .Struct => {27278 .Struct => {
27279 const fields = try arena.alloc(Value, parent.ty.structFieldCount());27279 const fields = try arena.alloc(Value, parent.ty.structFieldCount());
27280 mem.set(Value, fields, Value.undef);27280 @memset(fields, Value.undef);
2728127281
27282 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);27282 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);
2728327283
...@@ -28425,7 +28425,7 @@ fn coerceTupleToStruct(...@@ -28425,7 +28425,7 @@ fn coerceTupleToStruct(
28425 const fields = struct_ty.structFields();28425 const fields = struct_ty.structFields();
28426 const field_vals = try sema.arena.alloc(Value, fields.count());28426 const field_vals = try sema.arena.alloc(Value, fields.count());
28427 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);28427 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
28428 mem.set(Air.Inst.Ref, field_refs, .none);28428 @memset(field_refs, .none);
2842928429
28430 const inst_ty = sema.typeOf(inst);28430 const inst_ty = sema.typeOf(inst);
28431 var runtime_src: ?LazySrcLoc = null;28431 var runtime_src: ?LazySrcLoc = null;
...@@ -28514,7 +28514,7 @@ fn coerceTupleToTuple(...@@ -28514,7 +28514,7 @@ fn coerceTupleToTuple(
28514 const dest_field_count = tuple_ty.structFieldCount();28514 const dest_field_count = tuple_ty.structFieldCount();
28515 const field_vals = try sema.arena.alloc(Value, dest_field_count);28515 const field_vals = try sema.arena.alloc(Value, dest_field_count);
28516 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);28516 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
28517 mem.set(Air.Inst.Ref, field_refs, .none);28517 @memset(field_refs, .none);
2851828518
28519 const inst_ty = sema.typeOf(inst);28519 const inst_ty = sema.typeOf(inst);
28520 const inst_field_count = inst_ty.structFieldCount();28520 const inst_field_count = inst_ty.structFieldCount();
src/arch/aarch64/CodeGen.zig+4-4
...@@ -1630,7 +1630,7 @@ fn allocRegs(...@@ -1630,7 +1630,7 @@ fn allocRegs(
1630 const read_locks = locks[0..read_args.len];1630 const read_locks = locks[0..read_args.len];
1631 const write_locks = locks[read_args.len..];1631 const write_locks = locks[read_args.len..];
16321632
1633 std.mem.set(?RegisterLock, locks, null);1633 @memset(locks, null);
1634 defer for (locks) |lock| {1634 defer for (locks) |lock| {
1635 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);1635 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
1636 };1636 };
...@@ -4395,7 +4395,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4395,7 +4395,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4395 if (args.len + 1 <= Liveness.bpi - 1) {4395 if (args.len + 1 <= Liveness.bpi - 1) {
4396 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);4396 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
4397 buf[0] = callee;4397 buf[0] = callee;
4398 std.mem.copy(Air.Inst.Ref, buf[1..], args);4398 @memcpy(buf[1..][0..args.len], args);
4399 return self.finishAir(inst, result, buf);4399 return self.finishAir(inst, result, buf);
4400 }4400 }
4401 var bt = try self.iterateBigTomb(inst, 1 + args.len);4401 var bt = try self.iterateBigTomb(inst, 1 + args.len);
...@@ -5348,7 +5348,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -5348,7 +5348,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
5348 buf_index += 1;5348 buf_index += 1;
5349 }5349 }
5350 if (buf_index + inputs.len > buf.len) break :simple;5350 if (buf_index + inputs.len > buf.len) break :simple;
5351 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);5351 @memcpy(buf[buf_index..][0..inputs.len], inputs);
5352 return self.finishAir(inst, result, buf);5352 return self.finishAir(inst, result, buf);
5353 }5353 }
5354 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);5354 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
...@@ -6055,7 +6055,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6055,7 +6055,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60556055
6056 if (elements.len <= Liveness.bpi - 1) {6056 if (elements.len <= Liveness.bpi - 1) {
6057 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);6057 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
6058 std.mem.copy(Air.Inst.Ref, &buf, elements);6058 @memcpy(buf[0..elements.len], elements);
6059 return self.finishAir(inst, result, buf);6059 return self.finishAir(inst, result, buf);
6060 }6060 }
6061 var bt = try self.iterateBigTomb(inst, elements.len);6061 var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/arm/CodeGen.zig+4-4
...@@ -3114,7 +3114,7 @@ fn allocRegs(...@@ -3114,7 +3114,7 @@ fn allocRegs(
3114 const read_locks = locks[0..read_args.len];3114 const read_locks = locks[0..read_args.len];
3115 const write_locks = locks[read_args.len..];3115 const write_locks = locks[read_args.len..];
31163116
3117 std.mem.set(?RegisterLock, locks, null);3117 @memset(locks, null);
3118 defer for (locks) |lock| {3118 defer for (locks) |lock| {
3119 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);3119 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
3120 };3120 };
...@@ -4341,7 +4341,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4341,7 +4341,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4341 if (args.len <= Liveness.bpi - 2) {4341 if (args.len <= Liveness.bpi - 2) {
4342 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);4342 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
4343 buf[0] = callee;4343 buf[0] = callee;
4344 std.mem.copy(Air.Inst.Ref, buf[1..], args);4344 @memcpy(buf[1..][0..args.len], args);
4345 return self.finishAir(inst, result, buf);4345 return self.finishAir(inst, result, buf);
4346 }4346 }
4347 var bt = try self.iterateBigTomb(inst, 1 + args.len);4347 var bt = try self.iterateBigTomb(inst, 1 + args.len);
...@@ -5263,7 +5263,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -5263,7 +5263,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
5263 buf_index += 1;5263 buf_index += 1;
5264 }5264 }
5265 if (buf_index + inputs.len > buf.len) break :simple;5265 if (buf_index + inputs.len > buf.len) break :simple;
5266 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);5266 @memcpy(buf[buf_index..][0..inputs.len], inputs);
5267 return self.finishAir(inst, result, buf);5267 return self.finishAir(inst, result, buf);
5268 }5268 }
5269 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);5269 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
...@@ -6000,7 +6000,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -6000,7 +6000,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60006000
6001 if (elements.len <= Liveness.bpi - 1) {6001 if (elements.len <= Liveness.bpi - 1) {
6002 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);6002 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
6003 std.mem.copy(Air.Inst.Ref, &buf, elements);6003 @memcpy(buf[0..elements.len], elements);
6004 return self.finishAir(inst, result, buf);6004 return self.finishAir(inst, result, buf);
6005 }6005 }
6006 var bt = try self.iterateBigTomb(inst, elements.len);6006 var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/riscv64/CodeGen.zig+3-3
...@@ -1784,7 +1784,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1784,7 +1784,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1784 if (args.len <= Liveness.bpi - 2) {1784 if (args.len <= Liveness.bpi - 2) {
1785 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);1785 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
1786 buf[0] = callee;1786 buf[0] = callee;
1787 std.mem.copy(Air.Inst.Ref, buf[1..], args);1787 @memcpy(buf[1..][0..args.len], args);
1788 return self.finishAir(inst, result, buf);1788 return self.finishAir(inst, result, buf);
1789 }1789 }
1790 var bt = try self.iterateBigTomb(inst, 1 + args.len);1790 var bt = try self.iterateBigTomb(inst, 1 + args.len);
...@@ -2225,7 +2225,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -2225,7 +2225,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
2225 buf_index += 1;2225 buf_index += 1;
2226 }2226 }
2227 if (buf_index + inputs.len > buf.len) break :simple;2227 if (buf_index + inputs.len > buf.len) break :simple;
2228 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);2228 @memcpy(buf[buf_index..][0..inputs.len], inputs);
2229 return self.finishAir(inst, result, buf);2229 return self.finishAir(inst, result, buf);
2230 }2230 }
2231 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);2231 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
...@@ -2500,7 +2500,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -2500,7 +2500,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
25002500
2501 if (elements.len <= Liveness.bpi - 1) {2501 if (elements.len <= Liveness.bpi - 1) {
2502 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);2502 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
2503 std.mem.copy(Air.Inst.Ref, &buf, elements);2503 @memcpy(buf[0..elements.len], elements);
2504 return self.finishAir(inst, result, buf);2504 return self.finishAir(inst, result, buf);
2505 }2505 }
2506 var bt = try self.iterateBigTomb(inst, elements.len);2506 var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/sparc64/CodeGen.zig+3-3
...@@ -843,7 +843,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -843,7 +843,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
843843
844 if (elements.len <= Liveness.bpi - 1) {844 if (elements.len <= Liveness.bpi - 1) {
845 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);845 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
846 std.mem.copy(Air.Inst.Ref, &buf, elements);846 @memcpy(buf[0..elements.len], elements);
847 return self.finishAir(inst, result, buf);847 return self.finishAir(inst, result, buf);
848 }848 }
849 var bt = try self.iterateBigTomb(inst, elements.len);849 var bt = try self.iterateBigTomb(inst, elements.len);
...@@ -987,7 +987,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -987,7 +987,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
987 buf_index += 1;987 buf_index += 1;
988 }988 }
989 if (buf_index + inputs.len > buf.len) break :simple;989 if (buf_index + inputs.len > buf.len) break :simple;
990 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);990 @memcpy(buf[buf_index..][0..inputs.len], inputs);
991 return self.finishAir(inst, result, buf);991 return self.finishAir(inst, result, buf);
992 }992 }
993993
...@@ -1314,7 +1314,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1314,7 +1314,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1314 if (args.len + 1 <= Liveness.bpi - 1) {1314 if (args.len + 1 <= Liveness.bpi - 1) {
1315 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);1315 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
1316 buf[0] = callee;1316 buf[0] = callee;
1317 std.mem.copy(Air.Inst.Ref, buf[1..], args);1317 @memcpy(buf[1..][0..args.len], args);
1318 return self.finishAir(inst, result, buf);1318 return self.finishAir(inst, result, buf);
1319 }1319 }
13201320
src/arch/x86_64/CodeGen.zig+2-2
...@@ -7117,7 +7117,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -7117,7 +7117,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
7117 buf_index += 1;7117 buf_index += 1;
7118 }7118 }
7119 if (buf_index + inputs.len > buf.len) break :simple;7119 if (buf_index + inputs.len > buf.len) break :simple;
7120 std.mem.copy(Air.Inst.Ref, buf[buf_index..], inputs);7120 @memcpy(buf[buf_index..][0..inputs.len], inputs);
7121 return self.finishAir(inst, result, buf);7121 return self.finishAir(inst, result, buf);
7122 }7122 }
7123 var bt = self.liveness.iterateBigTomb(inst);7123 var bt = self.liveness.iterateBigTomb(inst);
...@@ -8505,7 +8505,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -8505,7 +8505,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
85058505
8506 if (elements.len <= Liveness.bpi - 1) {8506 if (elements.len <= Liveness.bpi - 1) {
8507 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);8507 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
8508 std.mem.copy(Air.Inst.Ref, &buf, elements);8508 @memcpy(buf[0..elements.len], elements);
8509 return self.finishAir(inst, result, buf);8509 return self.finishAir(inst, result, buf);
8510 }8510 }
8511 var bt = self.liveness.iterateBigTomb(inst);8511 var bt = self.liveness.iterateBigTomb(inst);
src/arch/x86_64/Encoding.zig+1-1
...@@ -546,7 +546,7 @@ fn estimateInstructionLength(prefix: Prefix, encoding: Encoding, ops: []const Op...@@ -546,7 +546,7 @@ fn estimateInstructionLength(prefix: Prefix, encoding: Encoding, ops: []const Op
546 .encoding = encoding,546 .encoding = encoding,
547 .ops = [1]Operand{.none} ** 4,547 .ops = [1]Operand{.none} ** 4,
548 };548 };
549 std.mem.copy(Operand, &inst.ops, ops);549 @memcpy(inst.ops[0..ops.len], ops);
550550
551 var cwriter = std.io.countingWriter(std.io.null_writer);551 var cwriter = std.io.countingWriter(std.io.null_writer);
552 inst.encode(cwriter.writer(), .{ .allow_frame_loc = true }) catch unreachable; // Not allowed to fail here unless OOM.552 inst.encode(cwriter.writer(), .{ .allow_frame_loc = true }) catch unreachable; // Not allowed to fail here unless OOM.
src/arch/x86_64/abi.zig+1-1
...@@ -321,7 +321,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class {...@@ -321,7 +321,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class {
321 byte_i = 0;321 byte_i = 0;
322 result_i += 1;322 result_i += 1;
323 }323 }
324 std.mem.copy(Class, result[result_i..], field_class);324 @memcpy(result[result_i..][0..field_class.len], field_class);
325 result_i += field_class.len;325 result_i += field_class.len;
326 // If there are any bytes leftover, we have to try to combine326 // If there are any bytes leftover, we have to try to combine
327 // the next field with them.327 // the next field with them.
src/arch/x86_64/encoder.zig+2-2
...@@ -182,7 +182,7 @@ pub const Instruction = struct {...@@ -182,7 +182,7 @@ pub const Instruction = struct {
182 .encoding = encoding,182 .encoding = encoding,
183 .ops = [1]Operand{.none} ** 4,183 .ops = [1]Operand{.none} ** 4,
184 };184 };
185 std.mem.copy(Operand, &inst.ops, ops);185 @memcpy(inst.ops[0..ops.len], ops);
186 return inst;186 return inst;
187 }187 }
188188
...@@ -859,7 +859,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8, assembly: []co...@@ -859,7 +859,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8, assembly: []co
859 const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?;859 const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
860 var padding = try testing.allocator.alloc(u8, idx + 5);860 var padding = try testing.allocator.alloc(u8, idx + 5);
861 defer testing.allocator.free(padding);861 defer testing.allocator.free(padding);
862 std.mem.set(u8, padding, ' ');862 @memset(padding, ' ');
863 std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{863 std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{
864 assembly,864 assembly,
865 expected_fmt,865 expected_fmt,
src/codegen/c.zig+7-7
...@@ -2411,9 +2411,9 @@ pub fn genErrDecls(o: *Object) !void {...@@ -2411,9 +2411,9 @@ pub fn genErrDecls(o: *Object) !void {
2411 const name_buf = try o.dg.gpa.alloc(u8, name_prefix.len + max_name_len);2411 const name_buf = try o.dg.gpa.alloc(u8, name_prefix.len + max_name_len);
2412 defer o.dg.gpa.free(name_buf);2412 defer o.dg.gpa.free(name_buf);
24132413
2414 mem.copy(u8, name_buf, name_prefix);2414 @memcpy(name_buf[0..name_prefix.len], name_prefix);
2415 for (o.dg.module.error_name_list.items) |name| {2415 for (o.dg.module.error_name_list.items) |name| {
2416 mem.copy(u8, name_buf[name_prefix.len..], name);2416 @memcpy(name_buf[name_prefix.len..][0..name.len], name);
2417 const identifier = name_buf[0 .. name_prefix.len + name.len];2417 const identifier = name_buf[0 .. name_prefix.len + name.len];
24182418
2419 var name_ty_pl = Type.Payload.Len{ .base = .{ .tag = .array_u8_sentinel_0 }, .data = name.len };2419 var name_ty_pl = Type.Payload.Len{ .base = .{ .tag = .array_u8_sentinel_0 }, .data = name.len };
...@@ -4877,7 +4877,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4877,7 +4877,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
4877 const literal = mem.sliceTo(asm_source[src_i..], '%');4877 const literal = mem.sliceTo(asm_source[src_i..], '%');
4878 src_i += literal.len;4878 src_i += literal.len;
48794879
4880 mem.copy(u8, fixed_asm_source[dst_i..], literal);4880 @memcpy(fixed_asm_source[dst_i..][0..literal.len], literal);
4881 dst_i += literal.len;4881 dst_i += literal.len;
48824882
4883 if (src_i >= asm_source.len) break;4883 if (src_i >= asm_source.len) break;
...@@ -4902,9 +4902,9 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4902,9 +4902,9 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
4902 const name = desc[0..colon];4902 const name = desc[0..colon];
4903 const modifier = desc[colon + 1 ..];4903 const modifier = desc[colon + 1 ..];
49044904
4905 mem.copy(u8, fixed_asm_source[dst_i..], modifier);4905 @memcpy(fixed_asm_source[dst_i..][0..modifier.len], modifier);
4906 dst_i += modifier.len;4906 dst_i += modifier.len;
4907 mem.copy(u8, fixed_asm_source[dst_i..], name);4907 @memcpy(fixed_asm_source[dst_i..][0..name.len], name);
4908 dst_i += name.len;4908 dst_i += name.len;
49094909
4910 src_i += desc.len;4910 src_i += desc.len;
...@@ -7455,7 +7455,7 @@ fn formatIntLiteral(...@@ -7455,7 +7455,7 @@ fn formatIntLiteral(
7455 var int_buf: Value.BigIntSpace = undefined;7455 var int_buf: Value.BigIntSpace = undefined;
7456 const int = if (data.val.isUndefDeep()) blk: {7456 const int = if (data.val.isUndefDeep()) blk: {
7457 undef_limbs = try allocator.alloc(BigIntLimb, BigInt.calcTwosCompLimbCount(data.int_info.bits));7457 undef_limbs = try allocator.alloc(BigIntLimb, BigInt.calcTwosCompLimbCount(data.int_info.bits));
7458 mem.set(BigIntLimb, undef_limbs, undefPattern(BigIntLimb));7458 @memset(undef_limbs, undefPattern(BigIntLimb));
74597459
7460 var undef_int = BigInt.Mutable{7460 var undef_int = BigInt.Mutable{
7461 .limbs = undef_limbs,7461 .limbs = undef_limbs,
...@@ -7550,7 +7550,7 @@ fn formatIntLiteral(...@@ -7550,7 +7550,7 @@ fn formatIntLiteral(
7550 } else {7550 } else {
7551 try data.cty.renderLiteralPrefix(writer, data.kind);7551 try data.cty.renderLiteralPrefix(writer, data.kind);
7552 wrap.convertToTwosComplement(int, data.int_info.signedness, c_bits);7552 wrap.convertToTwosComplement(int, data.int_info.signedness, c_bits);
7553 mem.set(BigIntLimb, wrap.limbs[wrap.len..], 0);7553 @memset(wrap.limbs[wrap.len..], 0);
7554 wrap.len = wrap.limbs.len;7554 wrap.len = wrap.limbs.len;
7555 const limbs_per_c_limb = @divExact(wrap.len, c_limb_info.count);7555 const limbs_per_c_limb = @divExact(wrap.len, c_limb_info.count);
75567556
src/link/Coff.zig+5-5
...@@ -2367,12 +2367,12 @@ pub fn getAtomIndexForSymbol(self: *const Coff, sym_loc: SymbolWithLoc) ?Atom.In...@@ -2367,12 +2367,12 @@ pub fn getAtomIndexForSymbol(self: *const Coff, sym_loc: SymbolWithLoc) ?Atom.In
2367fn setSectionName(self: *Coff, header: *coff.SectionHeader, name: []const u8) !void {2367fn setSectionName(self: *Coff, header: *coff.SectionHeader, name: []const u8) !void {
2368 if (name.len <= 8) {2368 if (name.len <= 8) {
2369 mem.copy(u8, &header.name, name);2369 mem.copy(u8, &header.name, name);
2370 mem.set(u8, header.name[name.len..], 0);2370 @memset(header.name[name.len..], 0);
2371 return;2371 return;
2372 }2372 }
2373 const offset = try self.strtab.insert(self.base.allocator, name);2373 const offset = try self.strtab.insert(self.base.allocator, name);
2374 const name_offset = fmt.bufPrint(&header.name, "/{d}", .{offset}) catch unreachable;2374 const name_offset = fmt.bufPrint(&header.name, "/{d}", .{offset}) catch unreachable;
2375 mem.set(u8, header.name[name_offset.len..], 0);2375 @memset(header.name[name_offset.len..], 0);
2376}2376}
23772377
2378fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const u8 {2378fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const u8 {
...@@ -2386,16 +2386,16 @@ fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const...@@ -2386,16 +2386,16 @@ fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const
2386fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void {2386fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void {
2387 if (name.len <= 8) {2387 if (name.len <= 8) {
2388 mem.copy(u8, &symbol.name, name);2388 mem.copy(u8, &symbol.name, name);
2389 mem.set(u8, symbol.name[name.len..], 0);2389 @memset(symbol.name[name.len..], 0);
2390 return;2390 return;
2391 }2391 }
2392 const offset = try self.strtab.insert(self.base.allocator, name);2392 const offset = try self.strtab.insert(self.base.allocator, name);
2393 mem.set(u8, symbol.name[0..4], 0);2393 @memset(symbol.name[0..4], 0);
2394 mem.writeIntLittle(u32, symbol.name[4..8], offset);2394 mem.writeIntLittle(u32, symbol.name[4..8], offset);
2395}2395}
23962396
2397fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 {2397fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 {
2398 mem.set(u8, buf[0..4], '_');2398 @memset(buf[0..4], '_');
2399 switch (sym.section_number) {2399 switch (sym.section_number) {
2400 .UNDEFINED => {2400 .UNDEFINED => {
2401 buf[3] = 'u';2401 buf[3] = 'u';
src/link/Dwarf.zig+4-4
...@@ -1189,7 +1189,7 @@ pub fn commitDeclState(...@@ -1189,7 +1189,7 @@ pub fn commitDeclState(
1189 if (needed_size > segment_size) {1189 if (needed_size > segment_size) {
1190 log.debug(" allocating {d} bytes for 'debug line' information", .{needed_size - segment_size});1190 log.debug(" allocating {d} bytes for 'debug line' information", .{needed_size - segment_size});
1191 try debug_line.resize(self.allocator, needed_size);1191 try debug_line.resize(self.allocator, needed_size);
1192 mem.set(u8, debug_line.items[segment_size..], 0);1192 @memset(debug_line.items[segment_size..], 0);
1193 }1193 }
1194 debug_line.items.len = needed_size;1194 debug_line.items.len = needed_size;
1195 }1195 }
...@@ -1458,7 +1458,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons...@@ -1458,7 +1458,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons
1458 if (needed_size > segment_size) {1458 if (needed_size > segment_size) {
1459 log.debug(" allocating {d} bytes for 'debug info' information", .{needed_size - segment_size});1459 log.debug(" allocating {d} bytes for 'debug info' information", .{needed_size - segment_size});
1460 try debug_info.resize(self.allocator, needed_size);1460 try debug_info.resize(self.allocator, needed_size);
1461 mem.set(u8, debug_info.items[segment_size..], 0);1461 @memset(debug_info.items[segment_size..], 0);
1462 }1462 }
1463 debug_info.items.len = needed_size;1463 debug_info.items.len = needed_size;
1464 }1464 }
...@@ -2076,9 +2076,9 @@ fn writeDbgInfoNopsToArrayList(...@@ -2076,9 +2076,9 @@ fn writeDbgInfoNopsToArrayList(
2076 buffer.items.len,2076 buffer.items.len,
2077 offset + content.len + next_padding_size + 1,2077 offset + content.len + next_padding_size + 1,
2078 ));2078 ));
2079 mem.set(u8, buffer.items[offset - prev_padding_size .. offset], @enumToInt(AbbrevKind.pad1));2079 @memset(buffer.items[offset - prev_padding_size .. offset], @enumToInt(AbbrevKind.pad1));
2080 mem.copy(u8, buffer.items[offset..], content);2080 mem.copy(u8, buffer.items[offset..], content);
2081 mem.set(u8, buffer.items[offset + content.len ..][0..next_padding_size], @enumToInt(AbbrevKind.pad1));2081 @memset(buffer.items[offset + content.len ..][0..next_padding_size], @enumToInt(AbbrevKind.pad1));
20822082
2083 if (trailing_zero) {2083 if (trailing_zero) {
2084 buffer.items[offset + content.len + next_padding_size] = 0;2084 buffer.items[offset + content.len + next_padding_size] = 0;
src/link/Elf.zig+1-1
...@@ -1997,7 +1997,7 @@ fn writeElfHeader(self: *Elf) !void {...@@ -1997,7 +1997,7 @@ fn writeElfHeader(self: *Elf) !void {
1997 // OS ABI, often set to 0 regardless of target platform1997 // OS ABI, often set to 0 regardless of target platform
1998 // ABI Version, possibly used by glibc but not by static executables1998 // ABI Version, possibly used by glibc but not by static executables
1999 // padding1999 // padding
2000 mem.set(u8, hdr_buf[index..][0..9], 0);2000 @memset(hdr_buf[index..][0..9], 0);
2001 index += 9;2001 index += 9;
20022002
2003 assert(index == 16);2003 assert(index == 16);
src/link/MachO.zig+5-5
...@@ -1454,7 +1454,7 @@ fn createThreadLocalDescriptorAtom(self: *MachO, sym_name: []const u8, target: S...@@ -1454,7 +1454,7 @@ fn createThreadLocalDescriptorAtom(self: *MachO, sym_name: []const u8, target: S
1454 });1454 });
14551455
1456 var code: [size]u8 = undefined;1456 var code: [size]u8 = undefined;
1457 mem.set(u8, &code, 0);1457 @memset(&code, 0);
1458 try self.writeAtom(atom_index, &code);1458 try self.writeAtom(atom_index, &code);
14591459
1460 return atom_index;1460 return atom_index;
...@@ -3234,7 +3234,7 @@ fn writeDyldInfoData(self: *MachO) !void {...@@ -3234,7 +3234,7 @@ fn writeDyldInfoData(self: *MachO) !void {
32343234
3235 var buffer = try gpa.alloc(u8, needed_size);3235 var buffer = try gpa.alloc(u8, needed_size);
3236 defer gpa.free(buffer);3236 defer gpa.free(buffer);
3237 mem.set(u8, buffer, 0);3237 @memset(buffer, 0);
32383238
3239 var stream = std.io.fixedBufferStream(buffer);3239 var stream = std.io.fixedBufferStream(buffer);
3240 const writer = stream.writer();3240 const writer = stream.writer();
...@@ -3389,7 +3389,7 @@ fn writeStrtab(self: *MachO) !void {...@@ -3389,7 +3389,7 @@ fn writeStrtab(self: *MachO) !void {
33893389
3390 const buffer = try gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);3390 const buffer = try gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
3391 defer gpa.free(buffer);3391 defer gpa.free(buffer);
3392 mem.set(u8, buffer, 0);3392 @memset(buffer, 0);
3393 mem.copy(u8, buffer, self.strtab.buffer.items);3393 mem.copy(u8, buffer, self.strtab.buffer.items);
33943394
3395 try self.base.file.?.pwriteAll(buffer, offset);3395 try self.base.file.?.pwriteAll(buffer, offset);
...@@ -4096,8 +4096,8 @@ pub fn logSections(self: *MachO) void {...@@ -4096,8 +4096,8 @@ pub fn logSections(self: *MachO) void {
4096}4096}
40974097
4098fn logSymAttributes(sym: macho.nlist_64, buf: *[4]u8) []const u8 {4098fn logSymAttributes(sym: macho.nlist_64, buf: *[4]u8) []const u8 {
4099 mem.set(u8, buf[0..4], '_');4099 @memset(buf[0..4], '_');
4100 mem.set(u8, buf[4..], ' ');4100 @memset(buf[4..], ' ');
4101 if (sym.sect()) {4101 if (sym.sect()) {
4102 buf[0] = 's';4102 buf[0] = 's';
4103 }4103 }
src/link/MachO/Object.zig+6-6
...@@ -156,7 +156,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)...@@ -156,7 +156,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
156156
157 // Prepopulate relocations per section lookup table.157 // Prepopulate relocations per section lookup table.
158 try self.section_relocs_lookup.resize(allocator, nsects);158 try self.section_relocs_lookup.resize(allocator, nsects);
159 mem.set(u32, self.section_relocs_lookup.items, 0);159 @memset(self.section_relocs_lookup.items, 0);
160160
161 // Parse symtab.161 // Parse symtab.
162 const symtab = while (it.next()) |cmd| switch (cmd.cmd()) {162 const symtab = while (it.next()) |cmd| switch (cmd.cmd()) {
...@@ -189,10 +189,10 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)...@@ -189,10 +189,10 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
189 };189 };
190 }190 }
191191
192 mem.set(i64, self.globals_lookup, -1);192 @memset(self.globals_lookup, -1);
193 mem.set(AtomIndex, self.atom_by_index_table, 0);193 @memset(self.atom_by_index_table, 0);
194 mem.set(Entry, self.source_section_index_lookup, .{});194 @memset(self.source_section_index_lookup, .{});
195 mem.set(Entry, self.relocs_lookup, .{});195 @memset(self.relocs_lookup, .{});
196196
197 // You would expect that the symbol table is at least pre-sorted based on symbol's type:197 // You would expect that the symbol table is at least pre-sorted based on symbol's type:
198 // local < extern defined < undefined. Unfortunately, this is not guaranteed! For instance,198 // local < extern defined < undefined. Unfortunately, this is not guaranteed! For instance,
...@@ -252,7 +252,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)...@@ -252,7 +252,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
252 self.unwind_info_sect_id = self.getSourceSectionIndexByName("__LD", "__compact_unwind");252 self.unwind_info_sect_id = self.getSourceSectionIndexByName("__LD", "__compact_unwind");
253 if (self.hasUnwindRecords()) {253 if (self.hasUnwindRecords()) {
254 self.unwind_relocs_lookup = try allocator.alloc(Record, self.getUnwindRecords().len);254 self.unwind_relocs_lookup = try allocator.alloc(Record, self.getUnwindRecords().len);
255 mem.set(Record, self.unwind_relocs_lookup, .{ .dead = true, .reloc = .{} });255 @memset(self.unwind_relocs_lookup, .{ .dead = true, .reloc = .{} });
256 }256 }
257}257}
258258
src/link/MachO/Trie.zig+1-1
...@@ -499,7 +499,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void {...@@ -499,7 +499,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void {
499 const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?;499 const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
500 var padding = try testing.allocator.alloc(u8, idx + 5);500 var padding = try testing.allocator.alloc(u8, idx + 5);
501 defer testing.allocator.free(padding);501 defer testing.allocator.free(padding);
502 mem.set(u8, padding, ' ');502 @memset(padding, ' ');
503 std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding });503 std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding });
504 return error.TestFailed;504 return error.TestFailed;
505}505}
src/link/MachO/UnwindInfo.zig+1-1
...@@ -659,7 +659,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {...@@ -659,7 +659,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
659 const padding = buffer.items.len - cwriter.bytes_written;659 const padding = buffer.items.len - cwriter.bytes_written;
660 if (padding > 0) {660 if (padding > 0) {
661 const offset = math.cast(usize, cwriter.bytes_written) orelse return error.Overflow;661 const offset = math.cast(usize, cwriter.bytes_written) orelse return error.Overflow;
662 mem.set(u8, buffer.items[offset..], 0);662 @memset(buffer.items[offset..], 0);
663 }663 }
664664
665 try zld.file.pwriteAll(buffer.items, sect.offset);665 try zld.file.pwriteAll(buffer.items, sect.offset);
src/link/MachO/zld.zig+5-5
...@@ -2140,7 +2140,7 @@ pub const Zld = struct {...@@ -2140,7 +2140,7 @@ pub const Zld = struct {
21402140
2141 var buffer = try gpa.alloc(u8, needed_size);2141 var buffer = try gpa.alloc(u8, needed_size);
2142 defer gpa.free(buffer);2142 defer gpa.free(buffer);
2143 mem.set(u8, buffer, 0);2143 @memset(buffer, 0);
21442144
2145 var stream = std.io.fixedBufferStream(buffer);2145 var stream = std.io.fixedBufferStream(buffer);
2146 const writer = stream.writer();2146 const writer = stream.writer();
...@@ -2352,7 +2352,7 @@ pub const Zld = struct {...@@ -2352,7 +2352,7 @@ pub const Zld = struct {
23522352
2353 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);2353 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
2354 defer self.gpa.free(buffer);2354 defer self.gpa.free(buffer);
2355 mem.set(u8, buffer, 0);2355 @memset(buffer, 0);
2356 mem.copy(u8, buffer, mem.sliceAsBytes(out_dice.items));2356 mem.copy(u8, buffer, mem.sliceAsBytes(out_dice.items));
23572357
2358 log.debug("writing data-in-code from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned });2358 log.debug("writing data-in-code from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned });
...@@ -2484,7 +2484,7 @@ pub const Zld = struct {...@@ -2484,7 +2484,7 @@ pub const Zld = struct {
24842484
2485 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);2485 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
2486 defer self.gpa.free(buffer);2486 defer self.gpa.free(buffer);
2487 mem.set(u8, buffer, 0);2487 @memset(buffer, 0);
2488 mem.copy(u8, buffer, self.strtab.buffer.items);2488 mem.copy(u8, buffer, self.strtab.buffer.items);
24892489
2490 try self.file.pwriteAll(buffer, offset);2490 try self.file.pwriteAll(buffer, offset);
...@@ -3199,7 +3199,7 @@ pub const Zld = struct {...@@ -3199,7 +3199,7 @@ pub const Zld = struct {
3199 scoped_log.debug(" object({d}): {s}", .{ id, object.name });3199 scoped_log.debug(" object({d}): {s}", .{ id, object.name });
3200 if (object.in_symtab == null) continue;3200 if (object.in_symtab == null) continue;
3201 for (object.symtab, 0..) |sym, sym_id| {3201 for (object.symtab, 0..) |sym, sym_id| {
3202 mem.set(u8, &buf, '_');3202 @memset(&buf, '_');
3203 scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{3203 scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{
3204 sym_id,3204 sym_id,
3205 object.getSymbolName(@intCast(u32, sym_id)),3205 object.getSymbolName(@intCast(u32, sym_id)),
...@@ -4007,7 +4007,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr...@@ -4007,7 +4007,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
4007 log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start });4007 log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start });
4008 var padding = try zld.gpa.alloc(u8, size);4008 var padding = try zld.gpa.alloc(u8, size);
4009 defer zld.gpa.free(padding);4009 defer zld.gpa.free(padding);
4010 mem.set(u8, padding, 0);4010 @memset(padding, 0);
4011 try zld.file.pwriteAll(padding, start);4011 try zld.file.pwriteAll(padding, start);
4012 }4012 }
4013 }4013 }
src/link/Wasm.zig+1-1
...@@ -1976,7 +1976,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {...@@ -1976,7 +1976,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
1976 // We do not have to do this when exporting the memory (the default) because the runtime1976 // We do not have to do this when exporting the memory (the default) because the runtime
1977 // will do it for us, and we do not emit the bss segment at all.1977 // will do it for us, and we do not emit the bss segment at all.
1978 if ((wasm.base.options.output_mode == .Obj or wasm.base.options.import_memory) and kind.data == .uninitialized) {1978 if ((wasm.base.options.output_mode == .Obj or wasm.base.options.import_memory) and kind.data == .uninitialized) {
1979 std.mem.set(u8, atom.code.items, 0);1979 @memset(atom.code.items, 0);
1980 }1980 }
19811981
1982 const should_merge = wasm.base.options.output_mode != .Obj;1982 const should_merge = wasm.base.options.output_mode != .Obj;
src/objcopy.zig+1-1
...@@ -1088,7 +1088,7 @@ fn ElfFile(comptime is_64: bool) type {...@@ -1088,7 +1088,7 @@ fn ElfFile(comptime is_64: bool) type {
1088 const crc_offset = std.mem.alignForward(link.name.len + 1, 4);1088 const crc_offset = std.mem.alignForward(link.name.len + 1, 4);
1089 const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4);1089 const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4);
1090 std.mem.copy(u8, buf[0..link.name.len], link.name);1090 std.mem.copy(u8, buf[0..link.name.len], link.name);
1091 std.mem.set(u8, buf[link.name.len..crc_offset], 0);1091 @memset(buf[link.name.len..crc_offset], 0);
1092 std.mem.copy(u8, buf[crc_offset..], std.mem.asBytes(&link.crc32));1092 std.mem.copy(u8, buf[crc_offset..], std.mem.asBytes(&link.crc32));
1093 break :payload buf;1093 break :payload buf;
1094 };1094 };
src/print_air.zig+1-1
...@@ -846,7 +846,7 @@ const Writer = struct {...@@ -846,7 +846,7 @@ const Writer = struct {
846 else blk: {846 else blk: {
847 const slice = w.gpa.alloc([]const Air.Inst.Index, switch_br.data.cases_len + 1) catch847 const slice = w.gpa.alloc([]const Air.Inst.Index, switch_br.data.cases_len + 1) catch
848 @panic("out of memory");848 @panic("out of memory");
849 std.mem.set([]const Air.Inst.Index, slice, &.{});849 @memset(slice, &.{});
850 break :blk Liveness.SwitchBrTable{ .deaths = slice };850 break :blk Liveness.SwitchBrTable{ .deaths = slice };
851 };851 };
852 defer w.gpa.free(liveness.deaths);852 defer w.gpa.free(liveness.deaths);
src/print_zir.zig+1-1
...@@ -682,7 +682,7 @@ const Writer = struct {...@@ -682,7 +682,7 @@ const Writer = struct {
682 const limbs = try self.gpa.alloc(std.math.big.Limb, inst_data.len);682 const limbs = try self.gpa.alloc(std.math.big.Limb, inst_data.len);
683 defer self.gpa.free(limbs);683 defer self.gpa.free(limbs);
684684
685 mem.copy(u8, mem.sliceAsBytes(limbs), limb_bytes);685 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
686 const big_int: std.math.big.int.Const = .{686 const big_int: std.math.big.int.Const = .{
687 .limbs = limbs,687 .limbs = limbs,
688 .positive = true,688 .positive = true,
src/value.zig+2-2
...@@ -875,7 +875,7 @@ pub const Value = extern union {...@@ -875,7 +875,7 @@ pub const Value = extern union {
875 .repeated => {875 .repeated => {
876 const byte = @intCast(u8, val.castTag(.repeated).?.data.toUnsignedInt(target));876 const byte = @intCast(u8, val.castTag(.repeated).?.data.toUnsignedInt(target));
877 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen()));877 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen()));
878 std.mem.set(u8, result, byte);878 @memset(result, byte);
879 return result;879 return result;
880 },880 },
881 .decl_ref => {881 .decl_ref => {
...@@ -1287,7 +1287,7 @@ pub const Value = extern union {...@@ -1287,7 +1287,7 @@ pub const Value = extern union {
1287 const endian = target.cpu.arch.endian();1287 const endian = target.cpu.arch.endian();
1288 if (val.isUndef()) {1288 if (val.isUndef()) {
1289 const size = @intCast(usize, ty.abiSize(target));1289 const size = @intCast(usize, ty.abiSize(target));
1290 std.mem.set(u8, buffer[0..size], 0xaa);1290 @memset(buffer[0..size], 0xaa);
1291 return;1291 return;
1292 }1292 }
1293 switch (ty.zigTypeTag()) {1293 switch (ty.zigTypeTag()) {