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
16931693 u8,
16941694 name.len + if (value) |value_slice| value_slice.len + 1 else 0,
16951695 ) 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);
16971697 if (value) |value_slice| {
16981698 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);
17001700 }
17011701 return macro;
17021702}
lib/std/Build/Cache.zig+1-1
......@@ -388,7 +388,7 @@ pub const Manifest = struct {
388388 self.hash.hasher = hasher_init;
389389 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);
392392 manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*;
393393
394394 if (self.files.items.len == 0) {
lib/std/Build/CompileStep.zig+1-1
......@@ -1139,7 +1139,7 @@ fn appendModuleArgs(
11391139 // We'll use this buffer to store the name we decide on
11401140 var buf = try b.allocator.alloc(u8, dep.name.len + 32);
11411141 // First, try just the exposed dependency name
1142 std.mem.copy(u8, buf, dep.name);
1142 @memcpy(buf[0..dep.name.len], dep.name);
11431143 var name = buf[0..dep.name.len];
11441144 var n: usize = 0;
11451145 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
374374 self.columns_written += self.output_buffer.len - end.*;
375375 end.* = self.output_buffer.len;
376376 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);
378378 },
379379 }
380380}
lib/std/Thread.zig+1-1
......@@ -56,7 +56,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
5656
5757 const name_with_terminator = blk: {
5858 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);
6060 name_buf[name.len] = 0;
6161 break :blk name_buf[0..name.len :0];
6262 };
lib/std/array_hash_map.zig+3-3
......@@ -578,9 +578,9 @@ pub fn ArrayHashMapUnmanaged(
578578 self.entries.len = 0;
579579 if (self.index_header) |header| {
580580 switch (header.capacityIndexType()) {
581 .u8 => mem.set(Index(u8), header.indexes(u8), Index(u8).empty),
582 .u16 => mem.set(Index(u16), header.indexes(u16), Index(u16).empty),
583 .u32 => mem.set(Index(u32), header.indexes(u32), Index(u32).empty),
581 .u8 => @memset(header.indexes(u8), Index(u8).empty),
582 .u16 => @memset(header.indexes(u16), Index(u16).empty),
583 .u32 => @memset(header.indexes(u32), Index(u32).empty),
584584 }
585585 }
586586 }
lib/std/array_list.zig+12-12
......@@ -120,7 +120,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
120120 }
121121
122122 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);
124124 @memset(self.items, undefined);
125125 self.clearAndFree();
126126 return new_memory;
......@@ -170,7 +170,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
170170 self.items.len += items.len;
171171
172172 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);
174174 }
175175
176176 /// 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 {
182182 const range = self.items[start..after_range];
183183
184184 if (range.len == new_items.len)
185 mem.copy(T, range, new_items)
185 @memcpy(range[0..new_items.len], new_items)
186186 else if (range.len < new_items.len) {
187187 const first = new_items[0..range.len];
188188 const rest = new_items[range.len..];
189189
190 mem.copy(T, range, first);
190 @memcpy(range[0..first.len], first);
191191 try self.insertSlice(after_range, rest);
192192 } else {
193 mem.copy(T, range, new_items);
193 @memcpy(range[0..new_items.len], new_items);
194194 const after_subrange = start + new_items.len;
195195
196196 for (self.items[after_range..], 0..) |item, i| {
......@@ -260,7 +260,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
260260 const new_len = old_len + items.len;
261261 assert(new_len <= self.capacity);
262262 self.items.len = new_len;
263 mem.copy(T, self.items[old_len..], items);
263 @memcpy(self.items[old_len..][0..items.len], items);
264264 }
265265
266266 /// 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 {
401401 self.capacity = new_capacity;
402402 } else {
403403 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);
405405 self.allocator.free(old_memory);
406406 self.items.ptr = new_memory.ptr;
407407 self.capacity = new_memory.len;
......@@ -600,7 +600,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
600600 }
601601
602602 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);
604604 @memset(self.items, undefined);
605605 self.clearAndFree(allocator);
606606 return new_memory;
......@@ -651,7 +651,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
651651 self.items.len += items.len;
652652
653653 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);
655655 }
656656
657657 /// 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
720720 const new_len = old_len + items.len;
721721 assert(new_len <= self.capacity);
722722 self.items.len = new_len;
723 mem.copy(T, self.items[old_len..], items);
723 @memcpy(self.items[old_len..][0..items.len], items);
724724 }
725725
726726 /// Append the slice of items to the list. Allocates more
......@@ -823,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
823823 },
824824 };
825825
826 mem.copy(T, new_memory, self.items[0..new_len]);
826 @memcpy(new_memory, self.items[0..new_len]);
827827 allocator.free(old_memory);
828828 self.items = new_memory;
829829 self.capacity = new_memory.len;
......@@ -885,7 +885,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
885885 self.capacity = new_capacity;
886886 } else {
887887 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);
889889 allocator.free(old_memory);
890890 self.items.ptr = new_memory.ptr;
891891 self.capacity = new_memory.len;
lib/std/base64.zig+2-2
......@@ -309,11 +309,11 @@ test "base64 padding dest overflow" {
309309 const input = "foo";
310310
311311 var expect: [128]u8 = undefined;
312 std.mem.set(u8, &expect, 0);
312 @memset(&expect, 0);
313313 _ = url_safe.Encoder.encode(expect[0..url_safe.Encoder.calcSize(input.len)], input);
314314
315315 var got: [128]u8 = undefined;
316 std.mem.set(u8, &got, 0);
316 @memset(&got, 0);
317317 _ = url_safe.Encoder.encode(&got, input);
318318
319319 try std.testing.expectEqualSlices(u8, &expect, &got);
lib/std/bit_set.zig+1-1
......@@ -738,7 +738,7 @@ pub const DynamicBitSetUnmanaged = struct {
738738 // fill in any new masks
739739 if (new_masks > old_masks) {
740740 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);
742742 }
743743 }
744744
lib/std/bounded_array.zig+10-10
......@@ -73,7 +73,7 @@ pub fn BoundedArrayAligned(
7373 /// Copy the content of an existing slice.
7474 pub fn fromSlice(m: []const T) error{Overflow}!Self {
7575 var list = try init(m.len);
76 std.mem.copy(T, list.slice(), m);
76 @memcpy(list.slice(), m);
7777 return list;
7878 }
7979
......@@ -165,7 +165,7 @@ pub fn BoundedArrayAligned(
165165 try self.ensureUnusedCapacity(items.len);
166166 self.len += items.len;
167167 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);
169169 }
170170
171171 /// Replace range of elements `slice[start..start+len]` with `new_items`.
......@@ -181,14 +181,14 @@ pub fn BoundedArrayAligned(
181181 var range = self.slice()[start..after_range];
182182
183183 if (range.len == new_items.len) {
184 mem.copy(T, range, new_items);
184 @memcpy(range[0..new_items.len], new_items);
185185 } else if (range.len < new_items.len) {
186186 const first = new_items[0..range.len];
187187 const rest = new_items[range.len..];
188 mem.copy(T, range, first);
188 @memcpy(range[0..first.len], first);
189189 try self.insertSlice(after_range, rest);
190190 } else {
191 mem.copy(T, range, new_items);
191 @memcpy(range[0..new_items.len], new_items);
192192 const after_subrange = start + new_items.len;
193193 for (self.constSlice()[after_range..], 0..) |item, i| {
194194 self.slice()[after_subrange..][i] = item;
......@@ -243,9 +243,9 @@ pub fn BoundedArrayAligned(
243243 /// Append the slice of items to the slice, asserting the capacity is already
244244 /// enough to store the new items.
245245 pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {
246 const oldlen = self.len;
246 const old_len = self.len;
247247 self.len += items.len;
248 mem.copy(T, self.slice()[oldlen..], items);
248 @memcpy(self.slice()[old_len..][0..items.len], items);
249249 }
250250
251251 /// Append a value to the slice `n` times.
......@@ -253,7 +253,7 @@ pub fn BoundedArrayAligned(
253253 pub fn appendNTimes(self: *Self, value: T, n: usize) error{Overflow}!void {
254254 const old_len = self.len;
255255 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);
257257 }
258258
259259 /// Append a value to the slice `n` times.
......@@ -262,7 +262,7 @@ pub fn BoundedArrayAligned(
262262 const old_len = self.len;
263263 self.len += n;
264264 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);
266266 }
267267
268268 pub const Writer = if (T != u8)
......@@ -329,7 +329,7 @@ test "BoundedArray" {
329329 try testing.expectEqual(a.popOrNull(), 0);
330330 try testing.expectEqual(a.popOrNull(), null);
331331 var unused = a.unusedCapacitySlice();
332 mem.set(u8, unused[0..8], 2);
332 @memset(unused[0..8], 2);
333333 unused[8] = 3;
334334 unused[9] = 4;
335335 try testing.expectEqual(unused.len, a.capacity());
lib/std/buf_set.zig+1-1
......@@ -97,7 +97,7 @@ pub const BufSet = struct {
9797
9898 fn copy(self: *const BufSet, value: []const u8) ![]const u8 {
9999 const result = try self.hash_map.allocator.alloc(u8, value.len);
100 mem.copy(u8, result, value);
100 @memcpy(result, value);
101101 return result;
102102 }
103103};
lib/std/child_process.zig+3-3
......@@ -259,7 +259,7 @@ pub const ChildProcess = struct {
259259
260260 fn fifoToOwnedArrayList(fifo: *std.io.PollFifo) std.ArrayList(u8) {
261261 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]);
263263 }
264264 const result = std.ArrayList(u8){
265265 .items = fifo.buf[0..fifo.count],
......@@ -1436,9 +1436,9 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) !
14361436 var i: usize = 0;
14371437 while (it.next()) |pair| : (i += 1) {
14381438 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.*);
14401440 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.*);
14421442 envp_buf[i] = env_buf.ptr;
14431443 }
14441444 assert(i == envp_count);
lib/std/compress/deflate/compressor.zig+6-6
......@@ -543,7 +543,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
543543 self.hash_offset = 1;
544544 self.tokens = try self.allocator.alloc(token.Token, max_flate_block_tokens);
545545 self.tokens_count = 0;
546 mem.set(token.Token, self.tokens, 0);
546 @memset(self.tokens, 0);
547547 self.length = min_match_length - 1;
548548 self.offset = 0;
549549 self.byte_available = false;
......@@ -841,9 +841,9 @@ pub fn Compressor(comptime WriterType: anytype) type {
841841 s.hash_head = try allocator.alloc(u32, hash_size);
842842 s.hash_prev = try allocator.alloc(u32, window_size);
843843 s.hash_match = try allocator.alloc(u32, max_match_length - 1);
844 mem.set(u32, s.hash_head, 0);
845 mem.set(u32, s.hash_prev, 0);
846 mem.set(u32, s.hash_match, 0);
844 @memset(s.hash_head, 0);
845 @memset(s.hash_prev, 0);
846 @memset(s.hash_match, 0);
847847
848848 switch (options.level) {
849849 .no_compression => {
......@@ -936,8 +936,8 @@ pub fn Compressor(comptime WriterType: anytype) type {
936936 .best_compression,
937937 => {
938938 self.chain_head = 0;
939 mem.set(u32, self.hash_head, 0);
940 mem.set(u32, self.hash_prev, 0);
939 @memset(self.hash_head, 0);
940 @memset(self.hash_prev, 0);
941941 self.hash_offset = 1;
942942 self.index = 0;
943943 self.window_end = 0;
lib/std/compress/deflate/decompressor.zig+1-1
......@@ -159,7 +159,7 @@ const HuffmanDecoder = struct {
159159 if (sanity) {
160160 // initialize to a known invalid chunk code (0) to see if we overwrite
161161 // this value later on
162 mem.set(u16, self.links[off], 0);
162 @memset(self.links[off], 0);
163163 }
164164 try self.sub_chunks.append(off);
165165 }
lib/std/compress/deflate/deflate_fast.zig+2-2
......@@ -566,11 +566,11 @@ test "best speed match 2/2" {
566566 for (cases) |c| {
567567 var previous = try testing.allocator.alloc(u8, c.previous);
568568 defer testing.allocator.free(previous);
569 mem.set(u8, previous, 0);
569 @memset(previous, 0);
570570
571571 var current = try testing.allocator.alloc(u8, c.current);
572572 defer testing.allocator.free(current);
573 mem.set(u8, current, 0);
573 @memset(current, 0);
574574
575575 var e = DeflateFast{
576576 .prev = previous,
lib/std/compress/lzma.zig+3-3
......@@ -75,9 +75,9 @@ pub fn Decompress(comptime ReaderType: type) type {
7575 }
7676 }
7777 const input = self.to_read.items;
78 const n = math.min(input.len, output.len);
79 mem.copy(u8, output[0..n], input[0..n]);
80 mem.copy(u8, input, input[n..]);
78 const n = @min(input.len, output.len);
79 @memcpy(output[0..n], input[0..n]);
80 @memcpy(input[0 .. input.len - n], input[n..]);
8181 self.to_read.shrinkRetainingCapacity(input.len - n);
8282 return n;
8383 }
lib/std/compress/lzma/decode/rangecoder.zig+1-1
......@@ -143,7 +143,7 @@ pub fn BitTree(comptime num_bits: usize) type {
143143 }
144144
145145 pub fn reset(self: *Self) void {
146 mem.set(u16, &self.probs, 0x400);
146 @memset(&self.probs, 0x400);
147147 }
148148 };
149149}
lib/std/compress/lzma/vec2d.zig+2-2
......@@ -13,7 +13,7 @@ pub fn Vec2D(comptime T: type) type {
1313 pub fn init(allocator: Allocator, value: T, size: struct { usize, usize }) !Self {
1414 const len = try math.mul(usize, size[0], size[1]);
1515 const data = try allocator.alloc(T, len);
16 mem.set(T, data, value);
16 @memset(data, value);
1717 return Self{
1818 .data = data,
1919 .cols = size[1],
......@@ -26,7 +26,7 @@ pub fn Vec2D(comptime T: type) type {
2626 }
2727
2828 pub fn fill(self: *Self, value: T) void {
29 mem.set(T, self.data, value);
29 @memset(self.data, value);
3030 }
3131
3232 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 {
293293
294294 try self.decodeLiteralsSlice(dest[write_pos..], sequence.literal_length);
295295 const copy_start = write_pos + sequence.literal_length - sequence.offset;
296 const copy_end = copy_start + sequence.match_length;
297 // NOTE: we ignore the usage message for std.mem.copy and copy with dest.ptr >= src.ptr
298 // to allow repeats
299 std.mem.copy(u8, dest[write_pos + sequence.literal_length ..], dest[copy_start..copy_end]);
296 for (
297 dest[write_pos + sequence.literal_length ..][0..sequence.match_length],
298 dest[copy_start..][0..sequence.match_length],
299 ) |*d, s| d.* = s;
300300 self.written_count += sequence.match_length;
301301 }
302302
......@@ -311,7 +311,6 @@ pub const DecodeState = struct {
311311 try self.decodeLiteralsRingBuffer(dest, sequence.literal_length);
312312 const copy_start = dest.write_index + dest.data.len - sequence.offset;
313313 const copy_slice = dest.sliceAt(copy_start, sequence.match_length);
314 // TODO: would std.mem.copy and figuring out dest slice be better/faster?
315314 for (copy_slice.first) |b| dest.writeAssumeCapacity(b);
316315 for (copy_slice.second) |b| dest.writeAssumeCapacity(b);
317316 self.written_count += sequence.match_length;
......@@ -444,9 +443,8 @@ pub const DecodeState = struct {
444443
445444 switch (self.literal_header.block_type) {
446445 .raw => {
447 const literals_end = self.literal_written_count + len;
448 const literal_data = self.literal_streams.one[self.literal_written_count..literals_end];
449 std.mem.copy(u8, dest, literal_data);
446 const literal_data = self.literal_streams.one[self.literal_written_count..][0..len];
447 @memcpy(dest[0..len], literal_data);
450448 self.literal_written_count += len;
451449 self.written_count += len;
452450 },
......@@ -615,8 +613,7 @@ pub fn decodeBlock(
615613 .raw => {
616614 if (src.len < block_size) return error.MalformedBlockSize;
617615 if (dest[written_count..].len < block_size) return error.DestTooSmall;
618 const data = src[0..block_size];
619 std.mem.copy(u8, dest[written_count..], data);
616 @memcpy(dest[written_count..][0..block_size], src[0..block_size]);
620617 consumed_count.* += block_size;
621618 decode_state.written_count += block_size;
622619 return block_size;
lib/std/crypto/25519/ed25519.zig+9-9
......@@ -79,8 +79,8 @@ pub const Ed25519 = struct {
7979 const r_bytes = r.toBytes();
8080
8181 var t: [64]u8 = undefined;
82 mem.copy(u8, t[0..32], &r_bytes);
83 mem.copy(u8, t[32..], &public_key.bytes);
82 t[0..32].* = r_bytes;
83 t[32..].* = public_key.bytes;
8484 var h = Sha512.init(.{});
8585 h.update(&t);
8686
......@@ -200,8 +200,8 @@ pub const Ed25519 = struct {
200200 /// Return the raw signature (r, s) in little-endian format.
201201 pub fn toBytes(self: Signature) [encoded_length]u8 {
202202 var bytes: [encoded_length]u8 = undefined;
203 mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);
204 mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);
203 bytes[0 .. encoded_length / 2].* = self.r;
204 bytes[encoded_length / 2 ..].* = self.s;
205205 return bytes;
206206 }
207207
......@@ -260,8 +260,8 @@ pub const Ed25519 = struct {
260260 const pk_p = Curve.basePoint.clampedMul(az[0..32].*) catch return error.IdentityElement;
261261 const pk_bytes = pk_p.toBytes();
262262 var sk_bytes: [SecretKey.encoded_length]u8 = undefined;
263 mem.copy(u8, &sk_bytes, &ss);
264 mem.copy(u8, sk_bytes[seed_length..], &pk_bytes);
263 sk_bytes[0..ss.len].* = ss;
264 sk_bytes[seed_length..].* = pk_bytes;
265265 return KeyPair{
266266 .public_key = PublicKey.fromBytes(pk_bytes) catch unreachable,
267267 .secret_key = try SecretKey.fromBytes(sk_bytes),
......@@ -373,7 +373,7 @@ pub const Ed25519 = struct {
373373 var z_batch: [count]Curve.scalar.CompressedScalar = undefined;
374374 for (&z_batch) |*z| {
375375 crypto.random.bytes(z[0..16]);
376 mem.set(u8, z[16..], 0);
376 @memset(z[16..], 0);
377377 }
378378
379379 var zs_sum = Curve.scalar.zero;
......@@ -444,8 +444,8 @@ pub const Ed25519 = struct {
444444 };
445445
446446 var prefix: [64]u8 = undefined;
447 mem.copy(u8, prefix[0..32], h[32..64]);
448 mem.copy(u8, prefix[32..64], blind_h[32..64]);
447 prefix[0..32].* = h[32..64].*;
448 prefix[32..64].* = blind_h[32..64].*;
449449
450450 const blind_secret_key = BlindSecretKey{
451451 .prefix = prefix,
lib/std/crypto/25519/edwards25519.zig+4-4
......@@ -306,7 +306,7 @@ pub const Edwards25519 = struct {
306306 var pcs: [count][9]Edwards25519 = undefined;
307307
308308 var bpc: [9]Edwards25519 = undefined;
309 mem.copy(Edwards25519, bpc[0..], basePointPc[0..bpc.len]);
309 @memcpy(&bpc, basePointPc[0..bpc.len]);
310310
311311 for (ps, 0..) |p, i| {
312312 if (p.is_base) {
......@@ -439,7 +439,7 @@ pub const Edwards25519 = struct {
439439 var u: [n * H.digest_length]u8 = undefined;
440440 var i: usize = 0;
441441 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;
443443 var j: usize = 0;
444444 while (i > 0 and j < H.digest_length) : (j += 1) {
445445 u[i + j] ^= u[i + j - H.digest_length];
......@@ -455,8 +455,8 @@ pub const Edwards25519 = struct {
455455 var px: [n]Edwards25519 = undefined;
456456 i = 0;
457457 while (i < n) : (i += 1) {
458 mem.set(u8, 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]);
458 @memset(u_0[0 .. H.digest_length - h_l], 0);
459 u_0[H.digest_length - h_l ..][0..h_l].* = u[i * h_l ..][0..h_l].*;
460460 px[i] = fromHash(u_0);
461461 }
462462 return px;
lib/std/crypto/25519/scalar.zig+3-3
......@@ -83,8 +83,8 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar {
8383pub fn neg(s: CompressedScalar) CompressedScalar {
8484 const fs: [64]u8 = field_order_s ++ [_]u8{0} ** 32;
8585 var sx: [64]u8 = undefined;
86 mem.copy(u8, sx[0..32], s[0..]);
87 mem.set(u8, sx[32..], 0);
86 sx[0..32].* = s;
87 @memset(sx[32..], 0);
8888 var carry: u32 = 0;
8989 var i: usize = 0;
9090 while (i < 64) : (i += 1) {
......@@ -593,7 +593,7 @@ const ScalarDouble = struct {
593593 limbs[i] = mem.readIntLittle(u64, bytes[i * 7 ..][0..8]) & 0xffffffffffffff;
594594 }
595595 limbs[i] = @as(u64, mem.readIntLittle(u32, bytes[i * 7 ..][0..4]));
596 mem.set(u64, limbs[5..], 0);
596 @memset(limbs[5..], 0);
597597 return ScalarDouble{ .limbs = limbs };
598598 }
599599
lib/std/crypto/25519/x25519.zig+7-7
......@@ -37,7 +37,7 @@ pub const X25519 = struct {
3737 break :sk random_seed;
3838 };
3939 var kp: KeyPair = undefined;
40 mem.copy(u8, &kp.secret_key, sk[0..]);
40 kp.secret_key = sk;
4141 kp.public_key = try X25519.recoverPublicKey(sk);
4242 return kp;
4343 }
......@@ -120,8 +120,8 @@ test "x25519 rfc7748 one iteration" {
120120 var i: usize = 0;
121121 while (i < 1) : (i += 1) {
122122 const output = try X25519.scalarmult(k, u);
123 mem.copy(u8, u[0..], k[0..]);
124 mem.copy(u8, k[0..], output[0..]);
123 u = k;
124 k = output;
125125 }
126126
127127 try std.testing.expectEqual(k, expected_output);
......@@ -142,8 +142,8 @@ test "x25519 rfc7748 1,000 iterations" {
142142 var i: usize = 0;
143143 while (i < 1000) : (i += 1) {
144144 const output = try X25519.scalarmult(&k, &u);
145 mem.copy(u8, u[0..], k[0..]);
146 mem.copy(u8, k[0..], output[0..]);
145 u = k;
146 k = output;
147147 }
148148
149149 try std.testing.expectEqual(k, expected_output);
......@@ -163,8 +163,8 @@ test "x25519 rfc7748 1,000,000 iterations" {
163163 var i: usize = 0;
164164 while (i < 1000000) : (i += 1) {
165165 const output = try X25519.scalarmult(&k, &u);
166 mem.copy(u8, u[0..], k[0..]);
167 mem.copy(u8, k[0..], output[0..]);
166 u = k;
167 k = output;
168168 }
169169
170170 try std.testing.expectEqual(k[0..], expected_output);
lib/std/crypto/Certificate.zig+7-7
......@@ -928,7 +928,7 @@ pub const rsa = struct {
928928 pub const PSSSignature = struct {
929929 pub fn fromBytes(comptime modulus_len: usize, msg: []const u8) [modulus_len]u8 {
930930 var result = [1]u8{0} ** modulus_len;
931 std.mem.copy(u8, &result, msg);
931 std.mem.copyForwards(u8, &result, msg);
932932 return result;
933933 }
934934
......@@ -1025,9 +1025,9 @@ pub const rsa = struct {
10251025 // initial zero octets.
10261026 var m_p = try allocator.alloc(u8, 8 + Hash.digest_length + sLen);
10271027 defer allocator.free(m_p);
1028 std.mem.copy(u8, m_p, &([_]u8{0} ** 8));
1029 std.mem.copy(u8, m_p[8..], &mHash);
1030 std.mem.copy(u8, m_p[(8 + Hash.digest_length)..], salt);
1028 std.mem.copyForwards(u8, m_p, &([_]u8{0} ** 8));
1029 std.mem.copyForwards(u8, m_p[8..], &mHash);
1030 std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt);
10311031
10321032 // 13. Let H' = Hash(M'), an octet string of length hLen.
10331033 var h_p: [Hash.digest_length]u8 = undefined;
......@@ -1047,7 +1047,7 @@ pub const rsa = struct {
10471047
10481048 var hash = try allocator.alloc(u8, seed.len + c.len);
10491049 defer allocator.free(hash);
1050 std.mem.copy(u8, hash, seed);
1050 std.mem.copyForwards(u8, hash, seed);
10511051 var hashed: [Hash.digest_length]u8 = undefined;
10521052
10531053 while (idx < len) {
......@@ -1056,10 +1056,10 @@ pub const rsa = struct {
10561056 c[2] = @intCast(u8, (counter >> 8) & 0xFF);
10571057 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);
10601060 Hash.hash(hash, &hashed, .{});
10611061
1062 std.mem.copy(u8, out[idx..], &hashed);
1062 std.mem.copyForwards(u8, out[idx..], &hashed);
10631063 idx += hashed.len;
10641064
10651065 counter += 1;
lib/std/crypto/aegis.zig+25-25
......@@ -152,8 +152,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
152152 state.absorb(ad[i..][0..32]);
153153 }
154154 if (ad.len % 32 != 0) {
155 mem.set(u8, src[0..], 0);
156 mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);
155 @memset(src[0..], 0);
156 @memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
157157 state.absorb(&src);
158158 }
159159 i = 0;
......@@ -161,10 +161,10 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
161161 state.enc(c[i..][0..32], m[i..][0..32]);
162162 }
163163 if (m.len % 32 != 0) {
164 mem.set(u8, src[0..], 0);
165 mem.copy(u8, src[0 .. m.len % 32], m[i .. i + m.len % 32]);
164 @memset(src[0..], 0);
165 @memcpy(src[0 .. m.len % 32], m[i..][0 .. m.len % 32]);
166166 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]);
168168 }
169169 tag.* = state.mac(tag_bits, ad.len, m.len);
170170 }
......@@ -185,8 +185,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
185185 state.absorb(ad[i..][0..32]);
186186 }
187187 if (ad.len % 32 != 0) {
188 mem.set(u8, src[0..], 0);
189 mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);
188 @memset(src[0..], 0);
189 @memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
190190 state.absorb(&src);
191191 }
192192 i = 0;
......@@ -194,11 +194,11 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
194194 state.dec(m[i..][0..32], c[i..][0..32]);
195195 }
196196 if (m.len % 32 != 0) {
197 mem.set(u8, src[0..], 0);
198 mem.copy(u8, src[0 .. m.len % 32], c[i .. i + m.len % 32]);
197 @memset(src[0..], 0);
198 @memcpy(src[0 .. m.len % 32], c[i..][0 .. m.len % 32]);
199199 state.dec(&dst, &src);
200 mem.copy(u8, m[i .. i + m.len % 32], dst[0 .. m.len % 32]);
201 mem.set(u8, dst[0 .. m.len % 32], 0);
200 @memcpy(m[i..][0 .. m.len % 32], dst[0 .. m.len % 32]);
201 @memset(dst[0 .. m.len % 32], 0);
202202 const blocks = &state.blocks;
203203 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(dst[0..16]));
204204 blocks[4] = blocks[4].xorBlocks(AesBlock.fromBytes(dst[16..32]));
......@@ -334,8 +334,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
334334 state.enc(&dst, ad[i..][0..16]);
335335 }
336336 if (ad.len % 16 != 0) {
337 mem.set(u8, src[0..], 0);
338 mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);
337 @memset(src[0..], 0);
338 @memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
339339 state.enc(&dst, &src);
340340 }
341341 i = 0;
......@@ -343,10 +343,10 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
343343 state.enc(c[i..][0..16], m[i..][0..16]);
344344 }
345345 if (m.len % 16 != 0) {
346 mem.set(u8, src[0..], 0);
347 mem.copy(u8, src[0 .. m.len % 16], m[i .. i + m.len % 16]);
346 @memset(src[0..], 0);
347 @memcpy(src[0 .. m.len % 16], m[i..][0 .. m.len % 16]);
348348 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]);
350350 }
351351 tag.* = state.mac(tag_bits, ad.len, m.len);
352352 }
......@@ -367,8 +367,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
367367 state.enc(&dst, ad[i..][0..16]);
368368 }
369369 if (ad.len % 16 != 0) {
370 mem.set(u8, src[0..], 0);
371 mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);
370 @memset(src[0..], 0);
371 @memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
372372 state.enc(&dst, &src);
373373 }
374374 i = 0;
......@@ -376,11 +376,11 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
376376 state.dec(m[i..][0..16], c[i..][0..16]);
377377 }
378378 if (m.len % 16 != 0) {
379 mem.set(u8, src[0..], 0);
380 mem.copy(u8, src[0 .. m.len % 16], c[i .. i + m.len % 16]);
379 @memset(src[0..], 0);
380 @memcpy(src[0 .. m.len % 16], c[i..][0 .. m.len % 16]);
381381 state.dec(&dst, &src);
382 mem.copy(u8, m[i .. i + m.len % 16], dst[0 .. m.len % 16]);
383 mem.set(u8, dst[0 .. m.len % 16], 0);
382 @memcpy(m[i..][0 .. m.len % 16], dst[0 .. m.len % 16]);
383 @memset(dst[0 .. m.len % 16], 0);
384384 const blocks = &state.blocks;
385385 blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(&dst));
386386 }
......@@ -457,7 +457,7 @@ fn AegisMac(comptime T: type) type {
457457 self.msg_len += b.len;
458458
459459 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]);
461461 self.off += len_partial;
462462 if (self.off < block_length) {
463463 return;
......@@ -470,7 +470,7 @@ fn AegisMac(comptime T: type) type {
470470 self.state.absorb(b[i..][0..block_length]);
471471 }
472472 if (i != b.len) {
473 mem.copy(u8, self.buf[0..], b[i..]);
473 @memcpy(self.buf[0..], b[i..]);
474474 self.off = b.len - i;
475475 }
476476 }
......@@ -479,7 +479,7 @@ fn AegisMac(comptime T: type) type {
479479 pub fn final(self: *Self, out: *[mac_length]u8) void {
480480 if (self.off > 0) {
481481 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]);
483483 self.state.absorb(&pad);
484484 }
485485 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 {
3131
3232 var t: [16]u8 = undefined;
3333 var j: [16]u8 = undefined;
34 mem.copy(u8, j[0..nonce_length], npub[0..]);
34 j[0..nonce_length].* = npub;
3535 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
3636 aes.encrypt(&t, &j);
3737
......@@ -64,7 +64,7 @@ fn AesGcm(comptime Aes: anytype) type {
6464
6565 var t: [16]u8 = undefined;
6666 var j: [16]u8 = undefined;
67 mem.copy(u8, j[0..nonce_length], npub[0..]);
67 j[0..nonce_length].* = npub;
6868 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
6969 aes.encrypt(&t, &j);
7070
lib/std/crypto/aes_ocb.zig+10-10
......@@ -75,7 +75,7 @@ fn AesOcb(comptime Aes: anytype) type {
7575 if (leftover > 0) {
7676 xorWith(&offset, lx.star);
7777 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]);
7979 padded[leftover] = 1;
8080 var e = xorBlocks(offset, padded);
8181 aes_enc_ctx.encrypt(&e, &e);
......@@ -88,7 +88,7 @@ fn AesOcb(comptime Aes: anytype) type {
8888 var nx = [_]u8{0} ** 16;
8989 nx[0] = @intCast(u8, @truncate(u7, tag_length * 8) << 1);
9090 nx[16 - nonce_length - 1] = 1;
91 mem.copy(u8, nx[16 - nonce_length ..], &npub);
91 nx[nx.len - nonce_length ..].* = npub;
9292
9393 const bottom = @truncate(u6, nx[15]);
9494 nx[15] &= 0xc0;
......@@ -132,14 +132,14 @@ fn AesOcb(comptime Aes: anytype) type {
132132 xorWith(&offset, lt[@ctz(i + 1 + j)]);
133133 offsets[j] = offset;
134134 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]);
136136 xorWith(&sum, p);
137137 }
138138 aes_enc_ctx.encryptWide(wb, &es, &es);
139139 j = 0;
140140 while (j < wb) : (j += 1) {
141141 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]);
143143 }
144144 }
145145 while (i < full_blocks) : (i += 1) {
......@@ -147,7 +147,7 @@ fn AesOcb(comptime Aes: anytype) type {
147147 const p = m[i * 16 ..][0..16].*;
148148 var e = xorBlocks(p, offset);
149149 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);
151151 xorWith(&sum, p);
152152 }
153153 const leftover = m.len % 16;
......@@ -159,7 +159,7 @@ fn AesOcb(comptime Aes: anytype) type {
159159 c[i * 16 + j] = pad[j] ^ x;
160160 }
161161 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]);
163163 e[leftover] = 0x80;
164164 xorWith(&sum, e);
165165 }
......@@ -196,13 +196,13 @@ fn AesOcb(comptime Aes: anytype) type {
196196 xorWith(&offset, lt[@ctz(i + 1 + j)]);
197197 offsets[j] = offset;
198198 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]);
200200 }
201201 aes_dec_ctx.decryptWide(wb, &es, &es);
202202 j = 0;
203203 while (j < wb) : (j += 1) {
204204 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;
206206 xorWith(&sum, p);
207207 }
208208 }
......@@ -212,7 +212,7 @@ fn AesOcb(comptime Aes: anytype) type {
212212 var e = xorBlocks(q, offset);
213213 aes_dec_ctx.decrypt(&e, &e);
214214 const p = xorBlocks(e, offset);
215 mem.copy(u8, m[i * 16 ..][0..16], &p);
215 m[i * 16 ..][0..16].* = p;
216216 xorWith(&sum, p);
217217 }
218218 const leftover = m.len % 16;
......@@ -224,7 +224,7 @@ fn AesOcb(comptime Aes: anytype) type {
224224 m[i * 16 + j] = pad[j] ^ x;
225225 }
226226 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]);
228228 e[leftover] = 0x80;
229229 xorWith(&sum, e);
230230 }
lib/std/crypto/argon2.zig+2-2
......@@ -494,7 +494,7 @@ pub fn kdf(
494494 if (params.t < 1 or params.p < 1) return KdfError.WeakParameters;
495495
496496 var h0 = initHash(password, salt, params, derived_key.len, mode);
497 const memory = math.max(
497 const memory = @max(
498498 params.m / (sync_points * params.p) * (sync_points * params.p),
499499 2 * sync_points * params.p,
500500 );
......@@ -877,7 +877,7 @@ test "kdf" {
877877 .hash = "1640b932f4b60e272f5d2207b9a9c626ffa1bd88d2349016",
878878 },
879879 };
880 inline for (test_vectors) |v| {
880 for (test_vectors) |v| {
881881 var want: [24]u8 = undefined;
882882 _ = 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 {
3434 /// Initialize the state from a slice of bytes.
3535 pub fn init(initial_state: [block_bytes]u8) Self {
3636 var state = Self{ .st = undefined };
37 mem.copy(u8, state.asBytes(), &initial_state);
37 @memcpy(state.asBytes(), &initial_state);
3838 state.endianSwap();
3939 return state;
4040 }
......@@ -87,7 +87,7 @@ pub fn State(comptime endian: builtin.Endian) type {
8787 }
8888 if (i < bytes.len) {
8989 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..]);
9191 self.st[i / 8] = mem.readInt(u64, padded[0..], endian);
9292 }
9393 }
......@@ -109,7 +109,7 @@ pub fn State(comptime endian: builtin.Endian) type {
109109 }
110110 if (i < bytes.len) {
111111 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..]);
113113 self.st[i / 8] ^= mem.readInt(u64, padded[0..], endian);
114114 }
115115 }
......@@ -123,7 +123,7 @@ pub fn State(comptime endian: builtin.Endian) type {
123123 if (i < out.len) {
124124 var padded = [_]u8{0} ** 8;
125125 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]);
127127 }
128128 }
129129
......@@ -138,16 +138,16 @@ pub fn State(comptime endian: builtin.Endian) type {
138138 }
139139 if (i < in.len) {
140140 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..]);
142142 const x = mem.readIntNative(u64, &padded) ^ mem.nativeTo(u64, self.st[i / 8], endian);
143143 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]);
145145 }
146146 }
147147
148148 /// Set the words storing the bytes of a given range to zero.
149149 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);
151151 }
152152
153153 /// Clear the entire state, disabling compiler optimizations.
lib/std/crypto/bcrypt.zig+3-3
......@@ -416,8 +416,8 @@ pub fn bcrypt(
416416) [dk_length]u8 {
417417 var state = State{};
418418 var password_buf: [73]u8 = undefined;
419 const trimmed_len = math.min(password.len, password_buf.len - 1);
420 mem.copy(u8, password_buf[0..], password[0..trimmed_len]);
419 const trimmed_len = @min(password.len, password_buf.len - 1);
420 @memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]);
421421 password_buf[trimmed_len] = 0;
422422 var passwordZ = password_buf[0 .. trimmed_len + 1];
423423 state.expand(salt[0..], passwordZ);
......@@ -626,7 +626,7 @@ const CryptFormatHasher = struct {
626626 crypto.random.bytes(&salt);
627627
628628 const hash = crypt_format.strHashInternal(password, salt, params);
629 mem.copy(u8, buf, &hash);
629 @memcpy(buf[0..hash.len], &hash);
630630
631631 return buf[0..pwhash_str_length];
632632 }
lib/std/crypto/benchmark.zig+2-2
......@@ -113,8 +113,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c
113113 var i: usize = 0;
114114 while (i < exchange_count) : (i += 1) {
115115 const out = try DhKeyExchange.scalarmult(secret, public);
116 mem.copy(u8, secret[0..16], out[0..16]);
117 mem.copy(u8, public[0..16], out[16..32]);
116 secret[0..16].* = out[0..16].*;
117 public[0..16].* = out[16..32].*;
118118 mem.doNotOptimizeAway(&out);
119119 }
120120 }
lib/std/crypto/blake2.zig+16-14
......@@ -76,7 +76,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
7676 comptime debug.assert(8 <= out_bits and out_bits <= 256);
7777
7878 var d: Self = undefined;
79 mem.copy(u32, d.h[0..], iv[0..]);
79 d.h = iv;
8080
8181 const key_len = if (options.key) |key| key.len else 0;
8282 // default parameters
......@@ -93,7 +93,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
9393 d.h[7] ^= mem.readIntLittle(u32, context[4..8]);
9494 }
9595 if (key_len > 0) {
96 mem.set(u8, d.buf[key_len..], 0);
96 @memset(d.buf[key_len..], 0);
9797 d.update(options.key.?);
9898 d.buf_len = 64;
9999 }
......@@ -112,7 +112,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
112112 // Partial buffer exists from previous update. Copy into buffer then hash.
113113 if (d.buf_len != 0 and d.buf_len + b.len > 64) {
114114 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]);
116116 d.t += 64;
117117 d.round(d.buf[0..], false);
118118 d.buf_len = 0;
......@@ -125,16 +125,17 @@ pub fn Blake2s(comptime out_bits: usize) type {
125125 }
126126
127127 // Copy any remainder for next pass.
128 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
129 d.buf_len += @intCast(u8, b[off..].len);
128 const b_slice = b[off..];
129 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
130 d.buf_len += @intCast(u8, b_slice.len);
130131 }
131132
132133 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);
134135 d.t += d.buf_len;
135136 d.round(d.buf[0..], true);
136137 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).*;
138139 }
139140
140141 fn round(d: *Self, b: *const [64]u8, last: bool) void {
......@@ -511,7 +512,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
511512 comptime debug.assert(8 <= out_bits and out_bits <= 512);
512513
513514 var d: Self = undefined;
514 mem.copy(u64, d.h[0..], iv[0..]);
515 d.h = iv;
515516
516517 const key_len = if (options.key) |key| key.len else 0;
517518 // default parameters
......@@ -528,7 +529,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
528529 d.h[7] ^= mem.readIntLittle(u64, context[8..16]);
529530 }
530531 if (key_len > 0) {
531 mem.set(u8, d.buf[key_len..], 0);
532 @memset(d.buf[key_len..], 0);
532533 d.update(options.key.?);
533534 d.buf_len = 128;
534535 }
......@@ -547,7 +548,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
547548 // Partial buffer exists from previous update. Copy into buffer then hash.
548549 if (d.buf_len != 0 and d.buf_len + b.len > 128) {
549550 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]);
551552 d.t += 128;
552553 d.round(d.buf[0..], false);
553554 d.buf_len = 0;
......@@ -560,16 +561,17 @@ pub fn Blake2b(comptime out_bits: usize) type {
560561 }
561562
562563 // Copy any remainder for next pass.
563 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
564 d.buf_len += @intCast(u8, b[off..].len);
564 const b_slice = b[off..];
565 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
566 d.buf_len += @intCast(u8, b_slice.len);
565567 }
566568
567569 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);
569571 d.t += d.buf_len;
570572 d.round(d.buf[0..], true);
571573 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).*;
573575 }
574576
575577 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 {
253253 while (out_word_it.next()) |out_word| {
254254 var word_bytes: [4]u8 = undefined;
255255 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]);
257257 word_counter += 1;
258258 }
259259 output_block_counter += 1;
......@@ -284,7 +284,7 @@ const ChunkState = struct {
284284 fn fillBlockBuf(self: *ChunkState, input: []const u8) []const u8 {
285285 const want = BLOCK_LEN - self.block_len;
286286 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]);
288288 self.block_len += @truncate(u8, take);
289289 return input[take..];
290290 }
......@@ -336,8 +336,8 @@ fn parentOutput(
336336 flags: u8,
337337) Output {
338338 var block_words: [16]u32 align(16) = undefined;
339 mem.copy(u32, block_words[0..8], left_child_cv[0..]);
340 mem.copy(u32, block_words[8..], right_child_cv[0..]);
339 block_words[0..8].* = left_child_cv;
340 block_words[8..].* = right_child_cv;
341341 return Output{
342342 .input_chaining_value = key,
343343 .block_words = block_words,
lib/std/crypto/chacha20.zig+4-4
......@@ -211,7 +211,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type {
211211
212212 var buf: [64]u8 = undefined;
213213 hashToBytes(buf[0..], x);
214 mem.copy(u8, out[i..], buf[0 .. out.len - i]);
214 @memcpy(out[i..], buf[0 .. out.len - i]);
215215 }
216216 }
217217
......@@ -372,7 +372,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
372372
373373 var buf: [64]u8 = undefined;
374374 hashToBytes(buf[0..], x);
375 mem.copy(u8, out[i..], buf[0 .. out.len - i]);
375 @memcpy(out[i..], buf[0 .. out.len - i]);
376376 }
377377 }
378378
......@@ -413,8 +413,8 @@ fn keyToWords(key: [32]u8) [8]u32 {
413413
414414fn extend(key: [32]u8, nonce: [24]u8, comptime rounds_nb: usize) struct { key: [32]u8, nonce: [12]u8 } {
415415 var subnonce: [12]u8 = undefined;
416 mem.set(u8, subnonce[0..4], 0);
417 mem.copy(u8, subnonce[4..], nonce[16..24]);
416 @memset(subnonce[0..4], 0);
417 subnonce[4..].* = nonce[16..24].*;
418418 return .{
419419 .key = ChaChaImpl(rounds_nb).hchacha20(nonce[0..16].*, key),
420420 .nonce = subnonce,
lib/std/crypto/ecdsa.zig+9-11
......@@ -102,8 +102,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
102102 /// Return the raw signature (r, s) in big-endian format.
103103 pub fn toBytes(self: Signature) [encoded_length]u8 {
104104 var bytes: [encoded_length]u8 = undefined;
105 mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);
106 mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);
105 @memcpy(bytes[0 .. encoded_length / 2], &self.r);
106 @memcpy(bytes[encoded_length / 2 ..], &self.s);
107107 return bytes;
108108 }
109109
......@@ -325,11 +325,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
325325 fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar {
326326 if (unreduced_len >= 48) {
327327 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..]);
329329 return Curve.scalar.Scalar.fromBytes64(xs, .Big);
330330 }
331331 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..]);
333333 return Curve.scalar.Scalar.fromBytes48(xs, .Big);
334334 }
335335
......@@ -345,14 +345,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
345345 const m_x = m[m_v.len + 1 + noise_length ..][0..secret_key.len];
346346 const m_h = m[m.len - h.len ..];
347347
348 mem.set(u8, m_v, 0x01);
348 @memset(m_v, 0x01);
349349 m_i.* = 0x00;
350 if (noise) |n| mem.copy(u8, m_z, &n);
351 mem.copy(u8, m_x, &secret_key);
352 mem.copy(u8, m_h, &h);
350 if (noise) |n| @memcpy(m_z, &n);
351 @memcpy(m_x, &secret_key);
352 @memcpy(m_h, &h);
353353 Hmac.create(&k, &m, &k);
354354 Hmac.create(m_v, m_v, &k);
355 mem.copy(u8, m_v, m_v);
356355 m_i.* = 0x01;
357356 Hmac.create(&k, &m, &k);
358357 Hmac.create(m_v, m_v, &k);
......@@ -361,10 +360,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
361360 while (t_off < t.len) : (t_off += m_v.len) {
362361 const t_end = @min(t_off + m_v.len, t.len);
363362 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]);
365364 }
366365 if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {}
367 mem.copy(u8, m_v, m_v);
368366 m_i.* = 0x00;
369367 Hmac.create(&k, m[0 .. m_v.len + 1], &k);
370368 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 {
6363 st.update(&counter);
6464 var tmp: [prk_length]u8 = undefined;
6565 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]);
6767 }
6868 }
6969 };
lib/std/crypto/hmac.zig+4-4
......@@ -38,12 +38,12 @@ pub fn Hmac(comptime Hash: type) type {
3838 // Normalize key length to block size of hash
3939 if (key.len > Hash.block_length) {
4040 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);
4242 } else if (key.len < Hash.block_length) {
43 mem.copy(u8, scratch[0..key.len], key);
44 mem.set(u8, scratch[key.len..Hash.block_length], 0);
43 @memcpy(scratch[0..key.len], key);
44 @memset(scratch[key.len..Hash.block_length], 0);
4545 } else {
46 mem.copy(u8, scratch[0..], key);
46 @memcpy(&scratch, key);
4747 }
4848
4949 for (&ctx.o_key_pad, 0..) |*b, i| {
lib/std/crypto/isap.zig+1-1
......@@ -43,7 +43,7 @@ pub const IsapA128A = struct {
4343 }
4444 } else {
4545 var padded = [_]u8{0} ** 8;
46 mem.copy(u8, padded[0..left], m[i..]);
46 @memcpy(padded[0..left], m[i..]);
4747 padded[left] = 0x80;
4848 isap.st.addBytes(&padded);
4949 isap.st.permute();
lib/std/crypto/keccak_p.zig+8-8
......@@ -68,7 +68,7 @@ pub fn KeccakF(comptime f: u11) type {
6868 }
6969 if (i < bytes.len) {
7070 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..]);
7272 self.st[i / @sizeOf(T)] = mem.readIntLittle(T, padded[0..]);
7373 }
7474 }
......@@ -87,7 +87,7 @@ pub fn KeccakF(comptime f: u11) type {
8787 }
8888 if (i < bytes.len) {
8989 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..]);
9191 self.st[i / @sizeOf(T)] ^= mem.readIntLittle(T, padded[0..]);
9292 }
9393 }
......@@ -101,7 +101,7 @@ pub fn KeccakF(comptime f: u11) type {
101101 if (i < out.len) {
102102 var padded = [_]u8{0} ** @sizeOf(T);
103103 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]);
105105 }
106106 }
107107
......@@ -116,16 +116,16 @@ pub fn KeccakF(comptime f: u11) type {
116116 }
117117 if (i < in.len) {
118118 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..]);
120120 const x = mem.readIntNative(T, &padded) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
121121 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]);
123123 }
124124 }
125125
126126 /// Set the words storing the bytes of a given range to zero.
127127 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);
129129 }
130130
131131 /// Clear the entire state, disabling compiler optimizations.
......@@ -215,7 +215,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
215215 var bytes = bytes_;
216216 if (self.offset > 0) {
217217 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]);
219219 self.offset += left;
220220 if (self.offset == rate) {
221221 self.offset = 0;
......@@ -231,7 +231,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
231231 bytes = bytes[rate..];
232232 }
233233 if (bytes.len > 0) {
234 mem.copy(u8, &self.buf, bytes);
234 @memcpy(self.buf[0..bytes.len], bytes);
235235 self.offset = bytes.len;
236236 }
237237 }
lib/std/crypto/kyber_d00.zig+1-1
......@@ -1479,7 +1479,7 @@ test "MulHat" {
14791479 const p2 = a.ntt().mulHat(b.ntt()).barrettReduce().invNTT().normalize();
14801480 var p: Poly = undefined;
14811481
1482 mem.set(i16, &p.cs, 0);
1482 @memset(&p.cs, 0);
14831483
14841484 for (0..N) |i| {
14851485 for (0..N) |j| {
lib/std/crypto/md5.zig+6-5
......@@ -66,7 +66,7 @@ pub const Md5 = struct {
6666 // Partial buffer exists from previous update. Copy into buffer then hash.
6767 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
6868 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
7171 d.round(&d.buf);
7272 d.buf_len = 0;
......@@ -78,8 +78,9 @@ pub const Md5 = struct {
7878 }
7979
8080 // Copy any remainder for next pass.
81 mem.copy(u8, d.buf[d.buf_len..], b[off..]);
82 d.buf_len += @intCast(u8, b[off..].len);
81 const b_slice = b[off..];
82 @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
83 d.buf_len += @intCast(u8, b_slice.len);
8384
8485 // Md5 uses the bottom 64-bits for length padding
8586 d.total_len +%= b.len;
......@@ -87,7 +88,7 @@ pub const Md5 = struct {
8788
8889 pub fn final(d: *Self, out: *[digest_length]u8) void {
8990 // 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
9293 // Append padding bits.
9394 d.buf[d.buf_len] = 0x80;
......@@ -96,7 +97,7 @@ pub const Md5 = struct {
9697 // > 448 mod 512 so need to add an extra round to wrap around.
9798 if (64 - d.buf_len < 8) {
9899 d.round(d.buf[0..]);
99 mem.set(u8, d.buf[0..], 0);
100 @memset(d.buf[0..], 0);
100101 }
101102
102103 // 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,
3838 if (i < src.len) {
3939 mem.writeInt(u128, &counter, counterInt, endian);
4040 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);
4243 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);
4446 }
4547}
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
129129 const offset = block * h_len;
130130 const block_len = if (block != blocks_count - 1) h_len else r;
131131 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
134134 var i: u32 = 1;
135135 while (i < rounds) : (i += 1) {
136136 // U_c = PRF (P, U_{c-1})
137137 Prf.create(&new_block, prev_block[0..], password);
138 mem.copy(u8, prev_block[0..], new_block[0..]);
138 prev_block = new_block;
139139
140140 // F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c
141141 for (dk_block, 0..) |_, j| {
lib/std/crypto/pcurves/common.zig+2-2
......@@ -228,8 +228,8 @@ pub fn Field(comptime params: FieldParams) type {
228228 }
229229 if (iterations % 2 != 0) {
230230 fiat.divstep(&out1, &out2, &out3, &out4, &out5, d, f, g, v, r);
231 mem.copy(Word, &v, &out4);
232 mem.copy(Word, &f, &out2);
231 v = out4;
232 f = out2;
233233 }
234234 var v_opp: Limbs = undefined;
235235 fiat.opp(&v_opp, v);
lib/std/crypto/pcurves/p256.zig+3-3
......@@ -105,7 +105,7 @@ pub const P256 = struct {
105105 var out: [33]u8 = undefined;
106106 const xy = p.affineCoordinates();
107107 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);
109109 return out;
110110 }
111111
......@@ -114,8 +114,8 @@ pub const P256 = struct {
114114 var out: [65]u8 = undefined;
115115 out[0] = 4;
116116 const xy = p.affineCoordinates();
117 mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));
118 mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));
117 out[1..33].* = xy.x.toBytes(.Big);
118 out[33..65].* = xy.y.toBytes(.Big);
119119 return out;
120120 }
121121
lib/std/crypto/pcurves/p256/scalar.zig+5-5
......@@ -192,20 +192,20 @@ const ScalarDouble = struct {
192192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
193193 {
194194 var b = [_]u8{0} ** encoded_length;
195 const len = math.min(s.len, 24);
196 mem.copy(u8, b[0..len], s[0..len]);
195 const len = @min(s.len, 24);
196 b[0..len].* = s[0..len].*;
197197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
198198 }
199199 if (s_.len >= 24) {
200200 var b = [_]u8{0} ** encoded_length;
201 const len = math.min(s.len - 24, 24);
202 mem.copy(u8, b[0..len], s[24..][0..len]);
201 const len = @min(s.len - 24, 24);
202 b[0..len].* = s[24..][0..len].*;
203203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
204204 }
205205 if (s_.len >= 48) {
206206 var b = [_]u8{0} ** encoded_length;
207207 const len = s.len - 48;
208 mem.copy(u8, b[0..len], s[48..][0..len]);
208 b[0..len].* = s[48..][0..len].*;
209209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
210210 }
211211 return t;
lib/std/crypto/pcurves/p384.zig+3-3
......@@ -105,7 +105,7 @@ pub const P384 = struct {
105105 var out: [49]u8 = undefined;
106106 const xy = p.affineCoordinates();
107107 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);
109109 return out;
110110 }
111111
......@@ -114,8 +114,8 @@ pub const P384 = struct {
114114 var out: [97]u8 = undefined;
115115 out[0] = 4;
116116 const xy = p.affineCoordinates();
117 mem.copy(u8, out[1..49], &xy.x.toBytes(.Big));
118 mem.copy(u8, out[49..97], &xy.y.toBytes(.Big));
117 out[1..49].* = xy.x.toBytes(.Big);
118 out[49..97].* = xy.y.toBytes(.Big);
119119 return out;
120120 }
121121
lib/std/crypto/pcurves/p384/scalar.zig+4-4
......@@ -180,14 +180,14 @@ const ScalarDouble = struct {
180180 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };
181181 {
182182 var b = [_]u8{0} ** encoded_length;
183 const len = math.min(s.len, 32);
184 mem.copy(u8, b[0..len], s[0..len]);
183 const len = @min(s.len, 32);
184 b[0..len].* = s[0..len].*;
185185 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
186186 }
187187 if (s_.len >= 32) {
188188 var b = [_]u8{0} ** encoded_length;
189 const len = math.min(s.len - 32, 32);
190 mem.copy(u8, b[0..len], s[32..][0..len]);
189 const len = @min(s.len - 32, 32);
190 b[0..len].* = s[32..][0..len].*;
191191 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
192192 }
193193 return t;
lib/std/crypto/pcurves/secp256k1.zig+3-3
......@@ -158,7 +158,7 @@ pub const Secp256k1 = struct {
158158 var out: [33]u8 = undefined;
159159 const xy = p.affineCoordinates();
160160 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);
162162 return out;
163163 }
164164
......@@ -167,8 +167,8 @@ pub const Secp256k1 = struct {
167167 var out: [65]u8 = undefined;
168168 out[0] = 4;
169169 const xy = p.affineCoordinates();
170 mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));
171 mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));
170 out[1..33].* = xy.x.toBytes(.Big);
171 out[33..65].* = xy.y.toBytes(.Big);
172172 return out;
173173 }
174174
lib/std/crypto/pcurves/secp256k1/scalar.zig+5-5
......@@ -192,20 +192,20 @@ const ScalarDouble = struct {
192192 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
193193 {
194194 var b = [_]u8{0} ** encoded_length;
195 const len = math.min(s.len, 24);
196 mem.copy(u8, b[0..len], s[0..len]);
195 const len = @min(s.len, 24);
196 b[0..len].* = s[0..len].*;
197197 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
198198 }
199199 if (s_.len >= 24) {
200200 var b = [_]u8{0} ** encoded_length;
201 const len = math.min(s.len - 24, 24);
202 mem.copy(u8, b[0..len], s[24..][0..len]);
201 const len = @min(s.len - 24, 24);
202 b[0..len].* = s[24..][0..len].*;
203203 t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
204204 }
205205 if (s_.len >= 48) {
206206 var b = [_]u8{0} ** encoded_length;
207207 const len = s.len - 48;
208 mem.copy(u8, b[0..len], s[48..][0..len]);
208 b[0..len].* = s[48..][0..len].*;
209209 t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
210210 }
211211 return t;
lib/std/crypto/phc_encoding.zig+1-1
......@@ -35,7 +35,7 @@ pub fn BinValue(comptime max_len: usize) type {
3535 pub fn fromSlice(slice: []const u8) Error!Self {
3636 if (slice.len > capacity) return Error.NoSpaceLeft;
3737 var bin_value: Self = undefined;
38 mem.copy(u8, &bin_value.buf, slice);
38 @memcpy(bin_value.buf[0..slice.len], slice);
3939 bin_value.len = slice.len;
4040 return bin_value;
4141 }
lib/std/crypto/salsa20.zig+6-6
......@@ -383,10 +383,10 @@ pub const XSalsa20Poly1305 = struct {
383383 debug.assert(c.len == m.len);
384384 const extended = extend(rounds, k, npub);
385385 var block0 = [_]u8{0} ** 64;
386 const mlen0 = math.min(32, m.len);
387 mem.copy(u8, block0[32..][0..mlen0], m[0..mlen0]);
386 const mlen0 = @min(32, m.len);
387 @memcpy(block0[32..][0..mlen0], m[0..mlen0]);
388388 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]);
390390 Salsa20.xor(c[mlen0..], m[mlen0..], 1, extended.key, extended.nonce);
391391 var mac = Poly1305.init(block0[0..32]);
392392 mac.update(ad);
......@@ -405,7 +405,7 @@ pub const XSalsa20Poly1305 = struct {
405405 const extended = extend(rounds, k, npub);
406406 var block0 = [_]u8{0} ** 64;
407407 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]);
409409 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
410410 var mac = Poly1305.init(block0[0..32]);
411411 mac.update(ad);
......@@ -420,7 +420,7 @@ pub const XSalsa20Poly1305 = struct {
420420 utils.secureZero(u8, &computedTag);
421421 return error.AuthenticationFailed;
422422 }
423 mem.copy(u8, m[0..mlen0], block0[32..][0..mlen0]);
423 @memcpy(m[0..mlen0], block0[32..][0..mlen0]);
424424 Salsa20.xor(m[mlen0..], c[mlen0..], 1, extended.key, extended.nonce);
425425 }
426426};
......@@ -533,7 +533,7 @@ pub const SealedBox = struct {
533533 debug.assert(c.len == m.len + seal_length);
534534 var ekp = try KeyPair.create(null);
535535 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;
537537 try Box.seal(c[Box.public_length..], m, nonce, public_key, ekp.secret_key);
538538 utils.secureZero(u8, ekp.secret_key[0..]);
539539 }
lib/std/crypto/sha1.zig+4-4
......@@ -62,7 +62,7 @@ pub const Sha1 = struct {
6262 // Partial buffer exists from previous update. Copy into buffer then hash.
6363 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
6464 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
6767 d.round(d.buf[0..]);
6868 d.buf_len = 0;
......@@ -74,7 +74,7 @@ pub const Sha1 = struct {
7474 }
7575
7676 // 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..]);
7878 d.buf_len += @intCast(u8, b[off..].len);
7979
8080 d.total_len += b.len;
......@@ -82,7 +82,7 @@ pub const Sha1 = struct {
8282
8383 pub fn final(d: *Self, out: *[digest_length]u8) void {
8484 // 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
8787 // Append padding bits.
8888 d.buf[d.buf_len] = 0x80;
......@@ -91,7 +91,7 @@ pub const Sha1 = struct {
9191 // > 448 mod 512 so need to add an extra round to wrap around.
9292 if (64 - d.buf_len < 8) {
9393 d.round(d.buf[0..]);
94 mem.set(u8, d.buf[0..], 0);
94 @memset(d.buf[0..], 0);
9595 }
9696
9797 // Append message length.
lib/std/crypto/sha2.zig+10-8
......@@ -118,7 +118,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
118118 // Partial buffer exists from previous update. Copy into buffer then hash.
119119 if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
120120 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
123123 d.round(&d.buf);
124124 d.buf_len = 0;
......@@ -130,7 +130,8 @@ fn Sha2x32(comptime params: Sha2Params32) type {
130130 }
131131
132132 // 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);
134135 d.buf_len += @intCast(u8, b[off..].len);
135136
136137 d.total_len += b.len;
......@@ -143,7 +144,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
143144
144145 pub fn final(d: *Self, out: *[digest_length]u8) void {
145146 // 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
148149 // Append padding bits.
149150 d.buf[d.buf_len] = 0x80;
......@@ -152,7 +153,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
152153 // > 448 mod 512 so need to add an extra round to wrap around.
153154 if (64 - d.buf_len < 8) {
154155 d.round(&d.buf);
155 mem.set(u8, d.buf[0..], 0);
156 @memset(d.buf[0..], 0);
156157 }
157158
158159 // Append message length.
......@@ -609,7 +610,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
609610 // Partial buffer exists from previous update. Copy into buffer then hash.
610611 if (d.buf_len != 0 and d.buf_len + b.len >= 128) {
611612 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
614615 d.round(&d.buf);
615616 d.buf_len = 0;
......@@ -621,7 +622,8 @@ fn Sha2x64(comptime params: Sha2Params64) type {
621622 }
622623
623624 // 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);
625627 d.buf_len += @intCast(u8, b[off..].len);
626628
627629 d.total_len += b.len;
......@@ -634,7 +636,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
634636
635637 pub fn final(d: *Self, out: *[digest_length]u8) void {
636638 // 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
639641 // Append padding bits.
640642 d.buf[d.buf_len] = 0x80;
......@@ -643,7 +645,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
643645 // > 896 mod 1024 so need to add an extra round to wrap around.
644646 if (128 - d.buf_len < 16) {
645647 d.round(d.buf[0..]);
646 mem.set(u8, d.buf[0..], 0);
648 @memset(d.buf[0..], 0);
647649 }
648650
649651 // 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:
149149 const left = self.buf.len - self.offset;
150150 if (left > 0) {
151151 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]);
153153 out = out[n..];
154154 self.offset += n;
155155 if (out.len == 0) {
......@@ -164,7 +164,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
164164 }
165165 if (out.len > 0) {
166166 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]);
168168 self.offset = out.len;
169169 }
170170 }
lib/std/crypto/siphash.zig+5-4
......@@ -98,7 +98,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
9898 self.msg_len +%= @truncate(u8, b.len);
9999
100100 var buf = [_]u8{0} ** 8;
101 mem.copy(u8, buf[0..], b[0..]);
101 @memcpy(buf[0..b.len], b);
102102 buf[7] = self.msg_len;
103103 self.round(buf);
104104
......@@ -203,7 +203,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
203203
204204 if (self.buf_len != 0 and self.buf_len + b.len >= 8) {
205205 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]);
207207 self.state.update(self.buf[0..]);
208208 self.buf_len = 0;
209209 }
......@@ -212,8 +212,9 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
212212 const aligned_len = remain_len - (remain_len % 8);
213213 self.state.update(b[off .. off + aligned_len]);
214214
215 mem.copy(u8, self.buf[self.buf_len..], b[off + aligned_len ..]);
216 self.buf_len += @intCast(u8, b[off + aligned_len ..].len);
215 const b_slice = b[off + aligned_len ..];
216 @memcpy(self.buf[self.buf_len..][0..b_slice.len], b_slice);
217 self.buf_len += @intCast(u8, b_slice.len);
217218 }
218219
219220 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
685685 .application_cipher = app_cipher,
686686 .partially_read_buffer = undefined,
687687 };
688 mem.copy(u8, &client.partially_read_buffer, leftover);
688 @memcpy(client.partially_read_buffer[0..leftover.len], leftover);
689689 return client;
690690 },
691691 else => {
......@@ -809,7 +809,7 @@ fn prepareCiphertextRecord(
809809 .overhead_len = overhead_len,
810810 };
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]);
813813 cleartext_buf[encrypted_content_len] = @enumToInt(inner_content_type);
814814 bytes_i += encrypted_content_len;
815815 const ciphertext_len = encrypted_content_len + 1;
......@@ -1029,8 +1029,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
10291029 if (frag1.len < second_len)
10301030 return finishRead2(c, first, frag1, vp.total);
10311031
1032 mem.copy(u8, frag[0..in], first);
1033 mem.copy(u8, frag[first.len..], frag1[0..second_len]);
1032 @memcpy(frag[0..in], first);
1033 @memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
10341034 frag = frag[0..full_record_len];
10351035 frag1 = frag1[second_len..];
10361036 in = 0;
......@@ -1059,8 +1059,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
10591059 if (frag1.len < second_len)
10601060 return finishRead2(c, first, frag1, vp.total);
10611061
1062 mem.copy(u8, frag[0..in], first);
1063 mem.copy(u8, frag[first.len..], frag1[0..second_len]);
1062 @memcpy(frag[0..in], first);
1063 @memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
10641064 frag = frag[0..full_record_len];
10651065 frag1 = frag1[second_len..];
10661066 in = 0;
......@@ -1177,7 +1177,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
11771177 // We have already run out of room in iovecs. Continue
11781178 // appending to `partially_read_buffer`.
11791179 const dest = c.partially_read_buffer[c.partial_ciphertext_idx..];
1180 mem.copy(u8, dest, msg);
1180 @memcpy(dest[0..msg.len], msg);
11811181 c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), c.partial_ciphertext_idx + msg.len);
11821182 } else {
11831183 const amt = vp.put(msg);
......@@ -1185,7 +1185,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
11851185 const rest = msg[amt..];
11861186 c.partial_cleartext_idx = 0;
11871187 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);
11891189 }
11901190 }
11911191 } else {
......@@ -1213,12 +1213,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {
12131213 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
12141214 // There is cleartext at the beginning already which we need to preserve.
12151215 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);
12171217 } else {
12181218 c.partial_cleartext_idx = 0;
12191219 c.partial_ciphertext_idx = 0;
12201220 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);
12221222 }
12231223 return out;
12241224}
......@@ -1227,14 +1227,14 @@ fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usi
12271227 if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
12281228 // There is cleartext at the beginning already which we need to preserve.
12291229 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);
1231 mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..], frag1);
1230 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..first.len], first);
1231 @memcpy(c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..][0..frag1.len], frag1);
12321232 } else {
12331233 c.partial_cleartext_idx = 0;
12341234 c.partial_ciphertext_idx = 0;
12351235 c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), first.len + frag1.len);
1236 mem.copy(u8, &c.partially_read_buffer, first);
1237 mem.copy(u8, c.partially_read_buffer[first.len..], frag1);
1236 @memcpy(c.partially_read_buffer[0..first.len], first);
1237 @memcpy(c.partially_read_buffer[first.len..][0..frag1.len], frag1);
12381238 }
12391239 return out;
12401240}
......@@ -1282,7 +1282,7 @@ const VecPut = struct {
12821282 const v = vp.iovecs[vp.idx];
12831283 const dest = v.iov_base[vp.off..v.iov_len];
12841284 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);
12861286 bytes_i += src.len;
12871287 vp.off += src.len;
12881288 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,
134134
135135/// Sets a slice to zeroes.
136136/// Prevents the store from being optimized out.
137pub fn secureZero(comptime T: type, s: []T) void {
138 // TODO: implement `@memset` for non-byte-sized element type in the llvm backend
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);
137pub inline fn secureZero(comptime T: type, s: []T) void {
138 @memset(@as([]volatile T, s), 0);
143139}
144140
145141test "crypto.utils.timingSafeEql" {
......@@ -148,7 +144,7 @@ test "crypto.utils.timingSafeEql" {
148144 random.bytes(a[0..]);
149145 random.bytes(b[0..]);
150146 try testing.expect(!timingSafeEql([100]u8, a, b));
151 mem.copy(u8, a[0..], b[0..]);
147 a = b;
152148 try testing.expect(timingSafeEql([100]u8, a, b));
153149}
154150
......@@ -201,7 +197,7 @@ test "crypto.utils.secureZero" {
201197 var a = [_]u8{0xfe} ** 8;
202198 var b = [_]u8{0xfe} ** 8;
203199
204 mem.set(u8, a[0..], 0);
200 @memset(a[0..], 0);
205201 secureZero(u8, b[0..]);
206202
207203 try testing.expectEqualSlices(u8, a[0..], b[0..]);
lib/std/cstr.zig+2-2
......@@ -34,7 +34,7 @@ fn testCStrFnsImpl() !void {
3434/// Caller owns the returned memory.
3535pub fn addNullByte(allocator: mem.Allocator, slice: []const u8) ![:0]u8 {
3636 const result = try allocator.alloc(u8, slice.len + 1);
37 mem.copy(u8, result, slice);
37 @memcpy(result[0..slice.len], slice);
3838 result[slice.len] = 0;
3939 return result[0..slice.len :0];
4040}
......@@ -78,7 +78,7 @@ pub const NullTerminated2DArray = struct {
7878 for (slice) |inner| {
7979 index_buf[i] = buf.ptr + write_index;
8080 i += 1;
81 mem.copy(u8, buf[write_index..], inner);
81 @memcpy(buf[write_index..][0..inner.len], inner);
8282 write_index += inner.len;
8383 buf[write_index] = 0;
8484 write_index += 1;
lib/std/dynamic_library.zig+1-1
......@@ -210,7 +210,7 @@ pub const ElfDynLib = struct {
210210 -1,
211211 0,
212212 );
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]);
214214 }
215215 },
216216 else => {},
lib/std/enums.zig+2-2
......@@ -275,7 +275,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
275275 .bits = Self.BitSet.initFull(),
276276 .values = undefined,
277277 };
278 std.mem.set(V, &result.values, value);
278 @memset(&result.values, value);
279279 return result;
280280 }
281281 /// Initializes a full mapping with supplied values.
......@@ -1175,7 +1175,7 @@ pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type)
11751175
11761176 pub fn initFill(v: Value) Self {
11771177 var self: Self = undefined;
1178 std.mem.set(Value, &self.values, v);
1178 @memset(&self.values, v);
11791179 return self;
11801180 }
11811181
lib/std/fifo.zig+12-14
......@@ -86,19 +86,17 @@ pub fn LinearFifo(
8686
8787 pub fn realign(self: *Self) void {
8888 if (self.buf.len - self.head >= self.count) {
89 // this copy overlaps
90 mem.copy(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
89 mem.copyForwards(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
9190 self.head = 0;
9291 } else {
9392 var tmp: [mem.page_size / 2 / @sizeOf(T)]T = undefined;
9493
9594 while (self.head != 0) {
96 const n = math.min(self.head, tmp.len);
95 const n = @min(self.head, tmp.len);
9796 const m = self.buf.len - n;
98 mem.copy(T, tmp[0..n], self.buf[0..n]);
99 // this middle copy overlaps; the others here don't
100 mem.copy(T, self.buf[0..m], self.buf[n..][0..m]);
101 mem.copy(T, self.buf[m..], tmp[0..n]);
97 @memcpy(tmp[0..n], self.buf[0..n]);
98 mem.copyForwards(T, self.buf[0..m], self.buf[n..][0..m]);
99 @memcpy(self.buf[m..][0..n], tmp[0..n]);
102100 self.head -= n;
103101 }
104102 }
......@@ -223,8 +221,8 @@ pub fn LinearFifo(
223221 while (dst_left.len > 0) {
224222 const slice = self.readableSlice(0);
225223 if (slice.len == 0) break;
226 const n = math.min(slice.len, dst_left.len);
227 mem.copy(T, dst_left, slice[0..n]);
224 const n = @min(slice.len, dst_left.len);
225 @memcpy(dst_left[0..n], slice[0..n]);
228226 self.discard(n);
229227 dst_left = dst_left[n..];
230228 }
......@@ -289,8 +287,8 @@ pub fn LinearFifo(
289287 while (src_left.len > 0) {
290288 const writable_slice = self.writableSlice(0);
291289 assert(writable_slice.len != 0);
292 const n = math.min(writable_slice.len, src_left.len);
293 mem.copy(T, writable_slice, src_left[0..n]);
290 const n = @min(writable_slice.len, src_left.len);
291 @memcpy(writable_slice[0..n], src_left[0..n]);
294292 self.update(n);
295293 src_left = src_left[n..];
296294 }
......@@ -354,11 +352,11 @@ pub fn LinearFifo(
354352
355353 const slice = self.readableSliceMut(0);
356354 if (src.len < slice.len) {
357 mem.copy(T, slice, src);
355 @memcpy(slice[0..src.len], src);
358356 } else {
359 mem.copy(T, slice, src[0..slice.len]);
357 @memcpy(slice, src[0..slice.len]);
360358 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..]);
362360 }
363361 }
364362
lib/std/fmt/errol.zig+2-2
......@@ -84,8 +84,8 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
8484 const i = tableLowerBound(bits);
8585 if (i < enum3.len and enum3[i] == bits) {
8686 const data = enum3_data[i];
87 const digits = buffer[1 .. data.str.len + 1];
88 mem.copy(u8, digits, data.str);
87 const digits = buffer[1..][0..data.str.len];
88 @memcpy(digits, data.str);
8989 return FloatDecimal{
9090 .digits = digits,
9191 .exp = data.exp,
lib/std/fs/path.zig+6-6
......@@ -79,7 +79,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
7979 const buf = try allocator.alloc(u8, total_len);
8080 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]);
8383 var buf_index: usize = paths[first_path_index].len;
8484 var prev_path = paths[first_path_index];
8585 assert(prev_path.len > 0);
......@@ -94,7 +94,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
9494 buf_index += 1;
9595 }
9696 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);
9898 buf_index += adjusted_path.len;
9999 prev_path = this_path;
100100 }
......@@ -631,7 +631,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
631631 real_result[i..][0..3].* = "..\\".*;
632632 i += 3;
633633 }
634 mem.copy(u8, real_result[i..], result.items);
634 @memcpy(real_result[i..][0..result.items.len], result.items);
635635 return real_result;
636636 }
637637}
......@@ -710,7 +710,7 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E
710710 real_result[i..][0..3].* = "../".*;
711711 i += 3;
712712 }
713 mem.copy(u8, real_result[i..], result.items);
713 @memcpy(real_result[i..][0..result.items.len], result.items);
714714 return real_result;
715715 }
716716}
......@@ -1106,7 +1106,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
11061106 while (rest_it.next()) |to_component| {
11071107 result[result_index] = '\\';
11081108 result_index += 1;
1109 mem.copy(u8, result[result_index..], to_component);
1109 @memcpy(result[result_index..][0..to_component.len], to_component);
11101110 result_index += to_component.len;
11111111 }
11121112
......@@ -1151,7 +1151,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
11511151 return allocator.realloc(result, result_index - 1);
11521152 }
11531153
1154 mem.copy(u8, result[result_index..], to_rest);
1154 @memcpy(result[result_index..][0..to_rest.len], to_rest);
11551155 return result;
11561156 }
11571157
lib/std/hash/cityhash.zig+2-2
......@@ -348,8 +348,8 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
348348 var key: [256]u8 = undefined;
349349 var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;
350350
351 std.mem.set(u8, &key, 0);
352 std.mem.set(u8, &hashes_bytes, 0);
351 @memset(&key, 0);
352 @memset(&hashes_bytes, 0);
353353
354354 var i: u32 = 0;
355355 while (i < 256) : (i += 1) {
lib/std/hash/wyhash.zig+3-2
......@@ -147,7 +147,7 @@ pub const Wyhash = struct {
147147
148148 if (self.buf_len != 0 and self.buf_len + b.len >= 32) {
149149 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]);
151151 self.state.update(self.buf[0..]);
152152 self.buf_len = 0;
153153 }
......@@ -156,7 +156,8 @@ pub const Wyhash = struct {
156156 const aligned_len = remain_len - (remain_len % 32);
157157 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);
160161 self.buf_len += @intCast(u8, b[off + aligned_len ..].len);
161162 }
162163
lib/std/hash/xxhash.zig+6-6
......@@ -36,7 +36,7 @@ pub const XxHash64 = struct {
3636
3737 pub fn update(self: *XxHash64, input: []const u8) void {
3838 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);
4040 self.buf_len += input.len;
4141 return;
4242 }
......@@ -45,7 +45,7 @@ pub const XxHash64 = struct {
4545
4646 if (self.buf_len > 0) {
4747 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]);
4949 self.processStripe(&self.buf);
5050 self.buf_len = 0;
5151 }
......@@ -55,7 +55,7 @@ pub const XxHash64 = struct {
5555 }
5656
5757 const remaining_bytes = input[i..];
58 mem.copy(u8, &self.buf, remaining_bytes);
58 @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
5959 self.buf_len = remaining_bytes.len;
6060 }
6161
......@@ -165,7 +165,7 @@ pub const XxHash32 = struct {
165165
166166 pub fn update(self: *XxHash32, input: []const u8) void {
167167 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);
169169 self.buf_len += input.len;
170170 return;
171171 }
......@@ -174,7 +174,7 @@ pub const XxHash32 = struct {
174174
175175 if (self.buf_len > 0) {
176176 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]);
178178 self.processStripe(&self.buf);
179179 self.buf_len = 0;
180180 }
......@@ -184,7 +184,7 @@ pub const XxHash32 = struct {
184184 }
185185
186186 const remaining_bytes = input[i..];
187 mem.copy(u8, &self.buf, remaining_bytes);
187 @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
188188 self.buf_len = remaining_bytes.len;
189189 }
190190
lib/std/heap/WasmAllocator.zig+1-1
......@@ -230,7 +230,7 @@ test "shrink" {
230230 var slice = try test_ally.alloc(u8, 20);
231231 defer test_ally.free(slice);
232232
233 mem.set(u8, slice, 0x11);
233 @memset(slice, 0x11);
234234
235235 try std.testing.expect(test_ally.resize(slice, 17));
236236 slice = slice[0..17];
lib/std/heap/WasmPageAllocator.zig+1-1
......@@ -153,7 +153,7 @@ fn freePages(start: usize, end: usize) void {
153153
154154 extended.data = @intToPtr([*]u128, new_end * mem.page_size)[0 .. mem.page_size / @sizeOf(u128)];
155155 // 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);
157157 }
158158 const clamped_start = @max(extendedOffset(), start);
159159 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 {
448448
449449 fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {
450450 if (stack_n == 0) return;
451 mem.set(usize, addresses, 0);
451 @memset(addresses, 0);
452452 var stack_trace = StackTrace{
453453 .instruction_addresses = addresses,
454454 .index = 0,
......@@ -1113,7 +1113,7 @@ test "shrink" {
11131113 var slice = try allocator.alloc(u8, 20);
11141114 defer allocator.free(slice);
11151115
1116 mem.set(u8, slice, 0x11);
1116 @memset(slice, 0x11);
11171117
11181118 try std.testing.expect(allocator.resize(slice, 17));
11191119 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
2020 var dest_index: usize = 0;
2121
2222 while (dest_index < dest.len) {
23 const written = std.math.min(dest.len - dest_index, self.end - self.start);
24 std.mem.copy(u8, dest[dest_index..], self.buf[self.start .. self.start + written]);
23 const written = @min(dest.len - dest_index, self.end - self.start);
24 @memcpy(dest[dest_index..][0..written], self.buf[self.start..][0..written]);
2525 if (written == 0) {
2626 // buf empty, fill it
2727 const n = try self.unbuffered_reader.read(self.buf[0..]);
......@@ -115,11 +115,8 @@ test "io.BufferedReader Block" {
115115 }
116116
117117 fn read(self: *Self, dest: []u8) Error!usize {
118 if (self.curr_read >= self.reads_allowed) {
119 return 0;
120 }
121 std.debug.assert(dest.len >= self.block.len);
122 std.mem.copy(u8, dest, self.block);
118 if (self.curr_read >= self.reads_allowed) return 0;
119 @memcpy(dest[0..self.block.len], self.block);
123120
124121 self.curr_read += 1;
125122 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
3030 return self.unbuffered_writer.write(bytes);
3131 }
3232
33 mem.copy(u8, self.buf[self.end..], bytes);
34 self.end += bytes.len;
33 const new_end = self.end + bytes.len;
34 @memcpy(self.buf[self.end..new_end], bytes);
35 self.end = new_end;
3536 return bytes.len;
3637 }
3738 };
lib/std/io/fixed_buffer_stream.zig+3-3
......@@ -45,10 +45,10 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
4545 }
4646
4747 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);
4949 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]);
5252 self.pos = end;
5353
5454 return size;
......@@ -67,7 +67,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
6767 else
6868 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]);
7171 self.pos += n;
7272
7373 if (n == 0) return error.NoSpaceLeft;
lib/std/io/writer.zig+1-1
......@@ -35,7 +35,7 @@ pub fn Writer(
3535
3636 pub fn writeByteNTimes(self: Self, byte: u8, n: usize) Error!void {
3737 var bytes: [256]u8 = undefined;
38 mem.set(u8, bytes[0..], byte);
38 @memset(bytes[0..], byte);
3939
4040 var remaining: usize = n;
4141 while (remaining > 0) {
lib/std/json.zig+2-2
......@@ -1667,7 +1667,7 @@ fn parseInternal(
16671667 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
16681668 if (r.len != stringToken.decodedLength()) return error.LengthMismatch;
16691669 switch (stringToken.escapes) {
1670 .None => mem.copy(u8, &r, source_slice),
1670 .None => @memcpy(r[0..source_slice.len], source_slice),
16711671 .Some => try unescapeValidString(&r, source_slice),
16721672 }
16731673 return r;
......@@ -1733,7 +1733,7 @@ fn parseInternal(
17331733 try allocator.alloc(u8, len);
17341734 errdefer allocator.free(output);
17351735 switch (stringToken.escapes) {
1736 .None => mem.copy(u8, output, source_slice),
1736 .None => @memcpy(output[0..source_slice.len], source_slice),
17371737 .Some => try unescapeValidString(output, source_slice),
17381738 }
17391739
lib/std/json/test.zig+1-1
......@@ -2811,7 +2811,7 @@ test "json.serialize issue #5959" {
28112811 // StreamingParser has multiple internal fields set to undefined. This causes issues when using
28122812 // expectEqual so these are zeroed. We are testing for equality here only because this is a
28132813 // 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);
28152815 try std.testing.expectEqual(parser, parser);
28162816}
28172817
lib/std/math/big/int.zig+32-32
......@@ -176,7 +176,7 @@ pub const Mutable = struct {
176176 /// Asserts the value fits in the limbs buffer.
177177 pub fn copy(self: *Mutable, other: Const) void {
178178 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]);
180180 }
181181 self.positive = other.positive;
182182 self.len = other.limbs.len;
......@@ -199,7 +199,7 @@ pub const Mutable = struct {
199199 /// can be modified separately from the original.
200200 /// Asserts that limbs is big enough to store the value.
201201 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]);
203203 return .{
204204 .limbs = limbs,
205205 .len = other.len,
......@@ -344,7 +344,7 @@ pub const Mutable = struct {
344344 .min => {
345345 // Negative bound, signed = -0x80.
346346 r.len = req_limbs;
347 mem.set(Limb, r.limbs[0 .. r.len - 1], 0);
347 @memset(r.limbs[0 .. r.len - 1], 0);
348348 r.limbs[r.len - 1] = signmask;
349349 r.positive = false;
350350 },
......@@ -363,7 +363,7 @@ pub const Mutable = struct {
363363 const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.
364364
365365 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));
367367 r.limbs[r.len - 1] = new_mask;
368368 }
369369 },
......@@ -376,7 +376,7 @@ pub const Mutable = struct {
376376 .max => {
377377 // Max bound, unsigned = 0xFF
378378 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));
380380 r.limbs[r.len - 1] = mask;
381381 },
382382 },
......@@ -489,7 +489,7 @@ pub const Mutable = struct {
489489 if (msl < req_limbs) {
490490 r.limbs[msl] = 1;
491491 r.len = req_limbs;
492 mem.set(Limb, r.limbs[msl + 1 .. req_limbs], 0);
492 @memset(r.limbs[msl + 1 .. req_limbs], 0);
493493 } else {
494494 carry_truncated = true;
495495 }
......@@ -637,14 +637,14 @@ pub const Mutable = struct {
637637
638638 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
639639 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);
641641 buf_index += a.limbs.len;
642642 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
643643 } else a;
644644
645645 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
646646 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);
648648 buf_index += b.limbs.len;
649649 break :blk b.toMutable(limbs_buffer[start..buf_index]).toConst();
650650 } else b;
......@@ -676,7 +676,7 @@ pub const Mutable = struct {
676676 }
677677 }
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
681681 llmulacc(.add, allocator, rma.limbs, a.limbs, b.limbs);
682682
......@@ -708,7 +708,7 @@ pub const Mutable = struct {
708708 const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
709709 const start = buf_index;
710710 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]);
712712 buf_index += a_len;
713713 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
714714 } else a;
......@@ -716,7 +716,7 @@ pub const Mutable = struct {
716716 const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
717717 const start = buf_index;
718718 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]);
720720 buf_index += b_len;
721721 break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
722722 } else b;
......@@ -751,7 +751,7 @@ pub const Mutable = struct {
751751 const a_limbs = a.limbs[0..math.min(req_limbs, a.limbs.len)];
752752 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
756756 llmulacc(.add, allocator, rma.limbs, a_limbs, b_limbs);
757757 rma.normalize(math.min(req_limbs, a.limbs.len + b.limbs.len));
......@@ -919,7 +919,7 @@ pub const Mutable = struct {
919919 _ = opt_allocator;
920920 assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing
921921
922 mem.set(Limb, rma.limbs, 0);
922 @memset(rma.limbs, 0);
923923
924924 llsquareBasecase(rma.limbs, a.limbs);
925925
......@@ -1522,7 +1522,7 @@ pub const Mutable = struct {
15221522 if (xy_trailing != 0) {
15231523 // Manually shift here since we know its limb aligned.
15241524 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);
15261526 r.len += xy_trailing;
15271527 }
15281528 }
......@@ -1556,7 +1556,7 @@ pub const Mutable = struct {
15561556 // for 0 <= j <= n - t, set q[j] to 0
15571557 q.len = shift + 1;
15581558 q.positive = true;
1559 mem.set(Limb, q.limbs[0..q.len], 0);
1559 @memset(q.limbs[0..q.len], 0);
15601560
15611561 // 2.
15621562 // while x >= y * b^(n - t):
......@@ -1691,7 +1691,7 @@ pub const Mutable = struct {
16911691
16921692 r.addScalar(a.abs(), -1);
16931693 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);
16951695 }
16961696
16971697 assert(r.limbs.len >= req_limbs);
......@@ -1730,7 +1730,7 @@ pub const Mutable = struct {
17301730
17311731 // Zero-extend the result
17321732 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);
17341734 }
17351735
17361736 // Truncate to required number of limbs.
......@@ -1921,8 +1921,8 @@ pub const Const = struct {
19211921
19221922 /// The result is an independent resource which is managed by the caller.
19231923 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));
1925 mem.copy(Limb, limbs, self.limbs);
1924 const limbs = try allocator.alloc(Limb, @max(Managed.default_capacity, self.limbs.len));
1925 @memcpy(limbs[0..self.limbs.len], self.limbs);
19261926 return Managed{
19271927 .allocator = allocator,
19281928 .limbs = limbs,
......@@ -1935,7 +1935,7 @@ pub const Const = struct {
19351935
19361936 /// Asserts `limbs` is big enough to store the value.
19371937 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]);
19391939 return .{
19401940 .limbs = limbs,
19411941 .positive = self.positive,
......@@ -2253,7 +2253,7 @@ pub const Const = struct {
22532253 .positive = true, // Make absolute by ignoring self.positive.
22542254 .len = self.limbs.len,
22552255 };
2256 mem.copy(Limb, q.limbs, self.limbs);
2256 @memcpy(q.limbs[0..self.limbs.len], self.limbs);
22572257
22582258 var r: Mutable = .{
22592259 .limbs = limbs_buffer[q.limbs.len..][0..self.limbs.len],
......@@ -2587,8 +2587,8 @@ pub const Managed = struct {
25872587 .allocator = allocator,
25882588 .metadata = other.metadata,
25892589 .limbs = block: {
2590 var limbs = try allocator.alloc(Limb, other.len());
2591 mem.copy(Limb, limbs[0..], other.limbs[0..other.len()]);
2590 const limbs = try allocator.alloc(Limb, other.len());
2591 @memcpy(limbs, other.limbs[0..other.len()]);
25922592 break :block limbs;
25932593 },
25942594 };
......@@ -2600,7 +2600,7 @@ pub const Managed = struct {
26002600 if (self.limbs.ptr == other.limbs.ptr) return;
26012601
26022602 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]);
26042604 self.setMetadata(other.positive, other.limbs.len);
26052605 }
26062606
......@@ -3302,7 +3302,7 @@ fn llmulaccKaratsuba(
33023302 // Note, we don't need to compute all of p2, just enough limbs to satisfy r.
33033303 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);
33063306 llmulacc(.add, allocator, tmp[0..p2_limbs], a1[0..math.min(a1.len, p2_limbs)], b1[0..math.min(b1.len, p2_limbs)]);
33073307 const p2 = tmp[0..llnormalize(tmp[0..p2_limbs])];
33083308
......@@ -3317,7 +3317,7 @@ fn llmulaccKaratsuba(
33173317 // Compute p0.
33183318 // Since a0.len, b0.len <= split and r.len >= split * 2, the full width of p0 needs to be computed.
33193319 const p0_limbs = a0.len + b0.len;
3320 mem.set(Limb, tmp[0..p0_limbs], 0);
3320 @memset(tmp[0..p0_limbs], 0);
33213321 llmulacc(.add, allocator, tmp[0..p0_limbs], a0, b0);
33223322 const p0 = tmp[0..llnormalize(tmp[0..p0_limbs])];
33233323
......@@ -3341,7 +3341,7 @@ fn llmulaccKaratsuba(
33413341 return;
33423342 }
33433343
3344 mem.set(Limb, tmp, 0);
3344 @memset(tmp, 0);
33453345
33463346 // p1 is nonzero, so compute the intermediary terms j0 = a0 - a1 and j1 = b1 - b0.
33473347 // 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 {
36663666 }
36673667
36683668 r[limb_shift - 1] = carry;
3669 mem.set(Limb, r[0 .. limb_shift - 1], 0);
3669 @memset(r[0 .. limb_shift - 1], 0);
36703670}
36713671
36723672fn 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 {
40614061 tmp2 = tmp_limbs;
40624062 }
40634063
4064 mem.copy(Limb, tmp1, a);
4065 mem.set(Limb, tmp1[a.len..], 0);
4064 @memcpy(tmp1[0..a.len], a);
4065 @memset(tmp1[a.len..], 0);
40664066
40674067 // Scan the exponent as a binary number, from left to right, dropping the
40684068 // most significant bit set.
......@@ -4074,14 +4074,14 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
40744074 var i: usize = 0;
40754075 while (i < exp_bits) : (i += 1) {
40764076 // Square
4077 mem.set(Limb, tmp2, 0);
4077 @memset(tmp2, 0);
40784078 llsquareBasecase(tmp2, tmp1[0..llnormalize(tmp1)]);
40794079 mem.swap([]Limb, &tmp1, &tmp2);
40804080 // Multiply by a
40814081 const ov = @shlWithOverflow(exp, 1);
40824082 exp = ov[0];
40834083 if (ov[1] != 0) {
4084 mem.set(Limb, tmp2, 0);
4084 @memset(tmp2, 0);
40854085 llmulacc(.add, null, tmp2, tmp1[0..llnormalize(tmp1)], a);
40864086 mem.swap([]Limb, &tmp1, &tmp2);
40874087 }
lib/std/mem.zig+6-4
......@@ -192,12 +192,14 @@ test "Allocator.resize" {
192192 }
193193}
194194
195/// Deprecated: use `copyForwards`
196pub const copy = copyForwards;
197
195198/// Copy all of source into dest at position 0.
196199/// dest.len must be >= source.len.
197200/// If the slices overlap, dest.ptr must be <= src.ptr.
198pub fn copy(comptime T: type, dest: []T, source: []const T) void {
199 for (dest[0..source.len], source) |*d, s|
200 d.* = s;
201pub fn copyForwards(comptime T: type, dest: []T, source: []const T) void {
202 for (dest[0..source.len], source) |*d, s| d.* = s;
201203}
202204
203205/// 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
31243126 var replacements: usize = 0;
31253127 while (slide < input.len) {
31263128 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);
31283130 i += replacement.len;
31293131 slide += needle.len;
31303132 replacements += 1;
lib/std/mem/Allocator.zig+2-2
......@@ -307,14 +307,14 @@ pub fn free(self: Allocator, memory: anytype) void {
307307/// Copies `m` to newly allocated memory. Caller owns the memory.
308308pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T {
309309 const new_buf = try allocator.alloc(T, m.len);
310 mem.copy(T, new_buf, m);
310 @memcpy(new_buf, m);
311311 return new_buf;
312312}
313313
314314/// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.
315315pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T {
316316 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);
318318 new_buf[m.len] = 0;
319319 return new_buf[0..m.len :0];
320320}
lib/std/multi_array_list.zig+3-3
......@@ -380,7 +380,7 @@ pub fn MultiArrayList(comptime T: type) type {
380380 inline for (fields, 0..) |field_info, i| {
381381 if (@sizeOf(field_info.type) != 0) {
382382 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));
384384 }
385385 }
386386 gpa.free(self.allocatedBytes());
......@@ -441,7 +441,7 @@ pub fn MultiArrayList(comptime T: type) type {
441441 inline for (fields, 0..) |field_info, i| {
442442 if (@sizeOf(field_info.type) != 0) {
443443 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));
445445 }
446446 }
447447 gpa.free(self.allocatedBytes());
......@@ -460,7 +460,7 @@ pub fn MultiArrayList(comptime T: type) type {
460460 inline for (fields, 0..) |field_info, i| {
461461 if (@sizeOf(field_info.type) != 0) {
462462 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));
464464 }
465465 }
466466 return result;
lib/std/net.zig+3-3
......@@ -106,7 +106,7 @@ pub const Address = extern union {
106106 // Add 1 to ensure a terminating 0 is present in the path array for maximum portability.
107107 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);
110110 mem.copy(u8, &sock_addr.path, path);
111111
112112 return Address{ .un = sock_addr };
......@@ -346,7 +346,7 @@ pub const Ip6Address = extern struct {
346346 if (!saw_any_digits) {
347347 if (abbrv) return error.InvalidCharacter; // ':::'
348348 if (i != 0) abbrv = true;
349 mem.set(u8, ip_slice[index..], 0);
349 @memset(ip_slice[index..], 0);
350350 ip_slice = tail[0..];
351351 index = 0;
352352 continue;
......@@ -465,7 +465,7 @@ pub const Ip6Address = extern struct {
465465 if (!saw_any_digits) {
466466 if (abbrv) return error.InvalidCharacter; // ':::'
467467 if (i != 0) abbrv = true;
468 mem.set(u8, ip_slice[index..], 0);
468 @memset(ip_slice[index..], 0);
469469 ip_slice = tail[0..];
470470 index = 0;
471471 continue;
lib/std/os.zig+19-15
......@@ -1881,9 +1881,9 @@ pub fn execvpeZ_expandArg0(
18811881 while (it.next()) |search_path| {
18821882 const path_len = search_path.len + file_slice.len + 1;
18831883 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);
18851885 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);
18871887 path_buf[path_len] = 0;
18881888 const full_path = path_buf[0..path_len :0].ptr;
18891889 switch (arg0_expand) {
......@@ -1917,7 +1917,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {
19171917 if (builtin.link_libc) {
19181918 var small_key_buf: [64]u8 = undefined;
19191919 if (key.len < small_key_buf.len) {
1920 mem.copy(u8, &small_key_buf, key);
1920 @memcpy(small_key_buf[0..key.len], key);
19211921 small_key_buf[key.len] = 0;
19221922 const key0 = small_key_buf[0..key.len :0];
19231923 return getenvZ(key0);
......@@ -2022,8 +2022,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
20222022 } else if (builtin.os.tag == .wasi and !builtin.link_libc) {
20232023 const path = ".";
20242024 if (out_buffer.len < path.len) return error.NameTooLong;
2025 std.mem.copy(u8, out_buffer, path);
2026 return out_buffer[0..path.len];
2025 const result = out_buffer[0..path.len];
2026 @memcpy(result, path);
2027 return result;
20272028 }
20282029
20292030 const err = if (builtin.link_libc) blk: {
......@@ -2673,7 +2674,7 @@ pub fn renameatW(
26732674 .FileNameLength = @intCast(u32, new_path_w.len * 2), // already checked error.NameTooLong
26742675 .FileName = undefined,
26752676 };
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
26782679 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 {
52645265 }
52655266 const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse MAX_PATH_BYTES;
52665267 if (len == 0) return error.NameTooLong;
5267 mem.copy(u8, out_buffer, kfile.path[0..len]);
5268 return out_buffer[0..len];
5268 const result = out_buffer[0..len];
5269 @memcpy(result, kfile.path[0..len]);
5270 return result;
52695271 } else {
52705272 // This fallback implementation reimplements libutil's `kinfo_getfile()`.
52715273 // 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 {
52965298 if (kf.fd == fd) {
52975299 len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;
52985300 if (len == 0) return error.NameTooLong;
5299 mem.copy(u8, out_buffer, kf.path[0..len]);
5300 return out_buffer[0..len];
5301 const result = out_buffer[0..len];
5302 @memcpy(result, kf.path[0..len]);
5303 return result;
53015304 }
53025305 i += @intCast(usize, kf.structsize);
53035306 }
......@@ -5686,8 +5689,9 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
56865689 if (builtin.os.tag == .linux) {
56875690 const uts = uname();
56885691 const hostname = mem.sliceTo(&uts.nodename, 0);
5689 mem.copy(u8, name_buffer, hostname);
5690 return name_buffer[0..hostname.len];
5692 const result = name_buffer[0..hostname.len];
5693 @memcpy(result, hostname);
5694 return result;
56915695 }
56925696
56935697 @compileError("TODO implement gethostname for this OS");
......@@ -5725,7 +5729,7 @@ pub fn res_mkquery(
57255729 @memset(q[0..n], 0);
57265730 q[2] = @as(u8, op) * 8 + 1;
57275731 q[5] = 1;
5728 mem.copy(u8, q[13..], name);
5732 @memcpy(q[13..][0..name.len], name);
57295733 var i: usize = 13;
57305734 var j: usize = undefined;
57315735 while (q[i] != 0) : (i = j + 1) {
......@@ -5748,7 +5752,7 @@ pub fn res_mkquery(
57485752 q[0] = @truncate(u8, id / 256);
57495753 q[1] = @truncate(u8, id);
57505754
5751 mem.copy(u8, buf, q[0..n]);
5755 @memcpy(buf[0..n], q[0..n]);
57525756 return n;
57535757}
57545758
......@@ -6755,7 +6759,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
67556759 var path_with_null: [MFD_MAX_NAME_LEN:0]u8 = undefined;
67566760 // >= rather than > to make room for the null byte
67576761 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);
67596763 path_with_null[name.len] = 0;
67606764 return path_with_null;
67616765}
lib/std/os/linux/io_uring.zig+4-4
......@@ -1855,7 +1855,7 @@ test "write_fixed/read_fixed" {
18551855
18561856 var raw_buffers: [2][11]u8 = undefined;
18571857 // First buffer will be written to the file.
1858 std.mem.set(u8, &raw_buffers[0], 'z');
1858 @memset(&raw_buffers[0], 'z');
18591859 std.mem.copy(u8, &raw_buffers[0], "foobar");
18601860
18611861 var buffers = [2]os.iovec{
......@@ -2966,7 +2966,7 @@ test "provide_buffers: read" {
29662966 // Provide 1 buffer again
29672967
29682968 // 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
29712971 const reprovided_buffer_id = 2;
29722972
......@@ -3155,7 +3155,7 @@ test "provide_buffers: accept/connect/send/recv" {
31553155 // Do 4 recv which should consume all buffers
31563156
31573157 // 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
31603160 var i: usize = 0;
31613161 while (i < buffers.len) : (i += 1) {
......@@ -3235,7 +3235,7 @@ test "provide_buffers: accept/connect/send/recv" {
32353235 // Final recv which should work
32363236
32373237 // 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
32403240 {
32413241 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 {
275275/// architecture-specific value of the thread-pointer register
276276pub fn prepareTLS(area: []u8) usize {
277277 // Clear the area we're going to use, just to be safe
278 mem.set(u8, area, 0);
278 @memset(area, 0);
279279 // Prepare the DTV
280280 const dtv = alignPtrCast(DTV, area.ptr + tls_image.dtv_offset);
281281 dtv.entries = 1;
lib/std/os/test.zig+1-1
......@@ -587,7 +587,7 @@ test "mmap" {
587587 try testing.expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234));
588588
589589 // Make sure the memory is writeable as requested
590 std.mem.set(u8, data, 0x55);
590 @memset(data, 0x55);
591591 try testing.expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234));
592592 }
593593
lib/std/process.zig+1-1
......@@ -855,7 +855,7 @@ pub fn argsAlloc(allocator: Allocator) ![][:0]u8 {
855855
856856 const result_slice_list = mem.bytesAsSlice([:0]u8, buf[0..slice_list_bytes]);
857857 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
860860 var contents_index: usize = 0;
861861 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 {
4040 }
4141 if (i < bytes.len) {
4242 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);
4445 Cipher.xor(
4546 self.state[0..Cipher.key_length],
4647 self.state[0..Cipher.key_length],
......@@ -72,8 +73,8 @@ pub fn fill(self: *Self, buf_: []u8) void {
7273 if (avail > 0) {
7374 // Bytes from the current block
7475 const n = @min(avail, buf.len);
75 mem.copy(u8, buf[0..n], bytes[self.offset..][0..n]);
76 mem.set(u8, bytes[self.offset..][0..n], 0);
76 @memcpy(buf[0..n], bytes[self.offset..][0..n]);
77 @memset(bytes[self.offset..][0..n], 0);
7778 buf = buf[n..];
7879 self.offset += n;
7980 }
......@@ -83,15 +84,15 @@ pub fn fill(self: *Self, buf_: []u8) void {
8384
8485 // Full blocks
8586 while (buf.len >= bytes.len) {
86 mem.copy(u8, buf[0..bytes.len], bytes);
87 @memcpy(buf[0..bytes.len], bytes);
8788 buf = buf[bytes.len..];
8889 self.refill();
8990 }
9091
9192 // Remaining bytes
9293 if (buf.len > 0) {
93 mem.copy(u8, buf, bytes[0..buf.len]);
94 mem.set(u8, bytes[0..buf.len], 0);
94 @memcpy(buf, bytes[0..buf.len]);
95 @memset(bytes[0..buf.len], 0);
9596 self.offset = buf.len;
9697 }
9798}
lib/std/rand/Isaac64.zig+2-2
......@@ -87,7 +87,7 @@ fn next(self: *Isaac64) u64 {
8787fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
8888 // We ignore the multi-pass requirement since we don't currently expose full access to
8989 // seeding the self.m array completely.
90 mem.set(u64, self.m[0..], 0);
90 @memset(self.m[0..], 0);
9191 self.m[0] = init_s;
9292
9393 // prescrambled golden ratio constants
......@@ -143,7 +143,7 @@ fn seed(self: *Isaac64, init_s: u64, comptime rounds: usize) void {
143143 }
144144 }
145145
146 mem.set(u64, self.r[0..], 0);
146 @memset(self.r[0..], 0);
147147 self.a = 0;
148148 self.b = 0;
149149 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
230230 allocator.free(new_dynamic_segments);
231231 } else {
232232 // 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]);
234234 allocator.free(self.dynamic_segments);
235235 self.dynamic_segments = new_dynamic_segments;
236236 }
......@@ -248,24 +248,21 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
248248
249249 var i = start;
250250 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);
252253 return;
253254 } 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);
255257 i = prealloc_item_count;
256258 }
257259
258260 while (i < end) {
259261 const shelf_index = shelfIndex(i);
260262 const copy_start = boxIndex(i, shelf_index);
261 const copy_end = std.math.min(shelfSize(shelf_index), copy_start + end - i);
262
263 mem.copy(
264 T,
265 dest[i - start ..],
266 self.dynamic_segments[shelf_index][copy_start..copy_end],
267 );
268
263 const copy_end = @min(shelfSize(shelf_index), copy_start + end - i);
264 const src = self.dynamic_segments[shelf_index][copy_start..copy_end];
265 @memcpy(dest[i - start ..][0..src.len], src);
269266 i += (copy_end - copy_start);
270267 }
271268 }
......@@ -498,11 +495,11 @@ fn testSegmentedList(comptime prealloc: usize) !void {
498495 control[@intCast(usize, i)] = i + 1;
499496 }
500497
501 mem.set(i32, dest[0..], 0);
498 @memset(dest[0..], 0);
502499 list.writeToSlice(dest[0..], 0);
503500 try testing.expect(mem.eql(i32, control[0..], dest[0..]));
504501
505 mem.set(i32, dest[0..], 0);
502 @memset(dest[0..], 0);
506503 list.writeToSlice(dest[50..], 50);
507504 try testing.expect(mem.eql(i32, control[50..], dest[50..]));
508505 }
lib/std/sort.zig+38-21
......@@ -361,8 +361,10 @@ pub fn sort(
361361
362362 if (lessThan(context, items[B1.end - 1], items[A1.start])) {
363363 // 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]);
365 mem.copy(T, cache[0..], items[B1.start..B1.end]);
364 const a1_items = items[A1.start..A1.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);
366368 } else if (lessThan(context, items[B1.start], items[A1.end - 1])) {
367369 // these two ranges weren't already in order, so merge them into the cache
368370 mergeInto(T, items, A1, B1, context, lessThan, cache[0..]);
......@@ -371,23 +373,29 @@ pub fn sort(
371373 if (!lessThan(context, items[B2.start], items[A2.end - 1]) and !lessThan(context, items[A2.start], items[B1.end - 1])) continue;
372374
373375 // copy A1 and B1 into the cache in the same order
374 mem.copy(T, cache[0..], items[A1.start..A1.end]);
375 mem.copy(T, cache[A1.length()..], items[B1.start..B1.end]);
376 const a1_items = items[A1.start..A1.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);
376380 }
377381 A1 = Range.init(A1.start, B1.end);
378382
379383 // merge A2 and B2 into the cache
380384 if (lessThan(context, items[B2.end - 1], items[A2.start])) {
381385 // 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]);
383 mem.copy(T, cache[A1.length()..], items[B2.start..B2.end]);
386 const a2_items = items[A2.start..A2.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);
384390 } else if (lessThan(context, items[B2.start], items[A2.end - 1])) {
385391 // these two ranges weren't already in order, so merge them into the cache
386392 mergeInto(T, items, A2, B2, context, lessThan, cache[A1.length()..]);
387393 } else {
388394 // copy A2 and B2 into the cache in the same order
389 mem.copy(T, cache[A1.length()..], items[A2.start..A2.end]);
390 mem.copy(T, cache[A1.length() + A2.length() ..], items[B2.start..B2.end]);
395 const a2_items = items[A2.start..A2.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);
391399 }
392400 A2 = Range.init(A2.start, B2.end);
393401
......@@ -397,15 +405,19 @@ pub fn sort(
397405
398406 if (lessThan(context, cache[B3.end - 1], cache[A3.start])) {
399407 // 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]);
401 mem.copy(T, items[A1.start..], cache[B3.start..B3.end]);
408 const a3_items = cache[A3.start..A3.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);
402412 } else if (lessThan(context, cache[B3.start], cache[A3.end - 1])) {
403413 // these two ranges weren't already in order, so merge them back into the items
404414 mergeInto(T, cache[0..], A3, B3, context, lessThan, items[A1.start..]);
405415 } else {
406416 // copy A3 and B3 into the items in the same order
407 mem.copy(T, items[A1.start..], cache[A3.start..A3.end]);
408 mem.copy(T, items[A1.start + A1.length() ..], cache[B3.start..B3.end]);
417 const a3_items = cache[A3.start..A3.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);
409421 }
410422 }
411423
......@@ -423,7 +435,8 @@ pub fn sort(
423435 mem.rotate(T, items[A.start..B.end], A.length());
424436 } else if (lessThan(context, items[B.start], items[A.end - 1])) {
425437 // 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);
427440 mergeExternal(T, items, A, B, context, lessThan, cache[0..]);
428441 }
429442 }
......@@ -718,7 +731,8 @@ pub fn sort(
718731 // if the first unevenly sized A block fits into the cache, copy it there for when we go to Merge it
719732 // otherwise, if the second buffer is available, block swap the contents into that
720733 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);
722736 } else if (buffer2.length() > 0) {
723737 blockSwap(T, items, lastA.start, buffer2.start, lastA.length());
724738 }
......@@ -762,7 +776,7 @@ pub fn sort(
762776 if (buffer2.length() > 0 or block_size <= cache.len) {
763777 // 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
764778 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]);
766780 } else {
767781 blockSwap(T, items, blockA.start, buffer2.start, block_size);
768782 }
......@@ -1122,7 +1136,8 @@ fn mergeInto(
11221136 insert_index += 1;
11231137 if (A_index == A_last) {
11241138 // 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);
11261141 break;
11271142 }
11281143 } else {
......@@ -1131,7 +1146,8 @@ fn mergeInto(
11311146 insert_index += 1;
11321147 if (B_index == B_last) {
11331148 // 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);
11351151 break;
11361152 }
11371153 }
......@@ -1171,7 +1187,8 @@ fn mergeExternal(
11711187 }
11721188
11731189 // 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);
11751192}
11761193
11771194fn swap(
......@@ -1305,7 +1322,7 @@ test "sort" {
13051322 for (u8cases) |case| {
13061323 var buf: [8]u8 = undefined;
13071324 const slice = buf[0..case[0].len];
1308 mem.copy(u8, slice, case[0]);
1325 @memcpy(slice, case[0]);
13091326 sort(u8, slice, {}, asc_u8);
13101327 try testing.expect(mem.eql(u8, slice, case[1]));
13111328 }
......@@ -1340,7 +1357,7 @@ test "sort" {
13401357 for (i32cases) |case| {
13411358 var buf: [8]i32 = undefined;
13421359 const slice = buf[0..case[0].len];
1343 mem.copy(i32, slice, case[0]);
1360 @memcpy(slice, case[0]);
13441361 sort(i32, slice, {}, asc_i32);
13451362 try testing.expect(mem.eql(i32, slice, case[1]));
13461363 }
......@@ -1377,7 +1394,7 @@ test "sort descending" {
13771394 for (rev_cases) |case| {
13781395 var buf: [8]i32 = undefined;
13791396 const slice = buf[0..case[0].len];
1380 mem.copy(i32, slice, case[0]);
1397 @memcpy(slice, case[0]);
13811398 sort(i32, slice, {}, desc_i32);
13821399 try testing.expect(mem.eql(i32, slice, case[1]));
13831400 }
lib/std/target.zig+2-2
......@@ -1596,7 +1596,7 @@ pub const Target = struct {
15961596 /// Asserts that the length is less than or equal to 255 bytes.
15971597 pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void {
15981598 if (dl_or_null) |dl| {
1599 mem.copy(u8, &self.buffer, dl);
1599 @memcpy(self.buffer[0..dl.len], dl);
16001600 self.max_byte = @intCast(u8, dl.len - 1);
16011601 } else {
16021602 self.max_byte = null;
......@@ -1612,7 +1612,7 @@ pub const Target = struct {
16121612 return r.*;
16131613 }
16141614 fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker {
1615 mem.copy(u8, &r.buffer, s);
1615 @memcpy(r.buffer[0..s.len], s);
16161616 r.max_byte = @intCast(u8, s.len - 1);
16171617 return r.*;
16181618 }
lib/std/testing/failing_allocator.zig+1-1
......@@ -66,7 +66,7 @@ pub const FailingAllocator = struct {
6666 const self = @ptrCast(*FailingAllocator, @alignCast(@alignOf(FailingAllocator), ctx));
6767 if (self.index == self.fail_index) {
6868 if (!self.has_induced_failure) {
69 mem.set(usize, &self.stack_addresses, 0);
69 @memset(&self.stack_addresses, 0);
7070 var stack_trace = std.builtin.StackTrace{
7171 .instruction_addresses = &self.stack_addresses,
7272 .index = 0,
lib/std/tz.zig+1-1
......@@ -137,7 +137,7 @@ pub const Tz = struct {
137137 const name = std.mem.sliceTo(designators[tt.name_data[0]..], 0);
138138 // We are mandating the "SHOULD" 6-character limit so we can pack the struct better, and to conform to POSIX.
139139 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);
141141 tt.name_data[name.len] = 0;
142142 }
143143
lib/std/zig/render.zig+2-2
......@@ -1889,11 +1889,11 @@ fn renderArrayInit(
18891889 // A place to store the width of each expression and its column's maximum
18901890 const widths = try gpa.alloc(usize, row_exprs.len + row_size);
18911891 defer gpa.free(widths);
1892 mem.set(usize, widths, 0);
1892 @memset(widths, 0);
18931893
18941894 const expr_newlines = try gpa.alloc(bool, row_exprs.len);
18951895 defer gpa.free(expr_newlines);
1896 mem.set(bool, expr_newlines, false);
1896 @memset(expr_newlines, false);
18971897
18981898 const expr_widths = widths[0..row_exprs.len];
18991899 const column_widths = widths[row_exprs.len..];
lib/std/zig/system/NativeTargetInfo.zig+4-4
......@@ -877,17 +877,17 @@ pub fn abiAndDynamicLinkerFromFile(
877877 const cpu_arch = @tagName(result.target.cpu.arch);
878878 const os_tag = @tagName(result.target.os.tag);
879879 const abi = @tagName(result.target.abi);
880 mem.copy(u8, path_buf[index..], prefix);
880 @memcpy(path_buf[index..][0..prefix.len], prefix);
881881 index += prefix.len;
882 mem.copy(u8, path_buf[index..], cpu_arch);
882 @memcpy(path_buf[index..][0..cpu_arch.len], cpu_arch);
883883 index += cpu_arch.len;
884884 path_buf[index] = '-';
885885 index += 1;
886 mem.copy(u8, path_buf[index..], os_tag);
886 @memcpy(path_buf[index..][0..os_tag.len], os_tag);
887887 index += os_tag.len;
888888 path_buf[index] = '-';
889889 index += 1;
890 mem.copy(u8, path_buf[index..], abi);
890 @memcpy(path_buf[index..][0..abi.len], abi);
891891 index += abi.len;
892892 const rpath = path_buf[0..index];
893893 if (glibcVerFromRPath(rpath)) |ver| {
lib/std/zig/system/windows.zig+2-2
......@@ -171,10 +171,10 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
171171 const entry = @ptrCast([*]align(1) const u8, table[i + 1].EntryContext);
172172 switch (@field(args, field.name).value_type) {
173173 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]);
175175 },
176176 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]);
178178 },
179179 else => unreachable,
180180 }
src/Compilation.zig+3-3
......@@ -2165,7 +2165,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di
21652165 const digest_start = 2; // "o/[digest]/[basename]"
21662166
21672167 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
21702170 comp.bin_file.options.emit = .{
21712171 .directory = comp.local_cache_directory,
......@@ -2174,7 +2174,7 @@ fn wholeCacheModeSetBinFilePath(comp: *Compilation, digest: *const [Cache.hex_di
21742174 }
21752175
21762176 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
21792179 comp.bin_file.options.implib_emit = .{
21802180 .directory = comp.local_cache_directory,
......@@ -4432,7 +4432,7 @@ pub fn addCCArgs(
44324432 assert(prefix.len == prefix_len);
44334433 var march_buf: [prefix_len + letters.len + 1]u8 = undefined;
44344434 var march_index: usize = prefix_len;
4435 mem.copy(u8, &march_buf, prefix);
4435 @memcpy(march_buf[0..prefix.len], prefix);
44364436
44374437 if (std.Target.riscv.featureSetHas(target.cpu.features, .e)) {
44384438 march_buf[march_index] = 'e';
src/Liveness.zig+4-4
......@@ -156,7 +156,7 @@ pub fn analyze(gpa: Allocator, air: Air) Allocator.Error!Liveness {
156156 errdefer a.special.deinit(gpa);
157157 defer a.extra.deinit(gpa);
158158
159 std.mem.set(usize, a.tomb_bits, 0);
159 @memset(a.tomb_bits, 0);
160160
161161 const main_body = air.getMainBody();
162162
......@@ -1841,7 +1841,7 @@ fn analyzeInstSwitchBr(
18411841 var case_infos = try gpa.alloc(ControlBranchInfo, ncases + 1); // +1 for else
18421842 defer gpa.free(case_infos);
18431843
1844 std.mem.set(ControlBranchInfo, case_infos, .{});
1844 @memset(case_infos, .{});
18451845 defer for (case_infos) |*info| {
18461846 info.branch_deaths.deinit(gpa);
18471847 info.live_set.deinit(gpa);
......@@ -1898,7 +1898,7 @@ fn analyzeInstSwitchBr(
18981898 const mirrored_deaths = try gpa.alloc(DeathList, ncases + 1);
18991899 defer gpa.free(mirrored_deaths);
19001900
1901 std.mem.set(DeathList, mirrored_deaths, .{});
1901 @memset(mirrored_deaths, .{});
19021902 defer for (mirrored_deaths) |*md| md.deinit(gpa);
19031903
19041904 {
......@@ -1993,7 +1993,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
19931993 };
19941994 errdefer a.gpa.free(extra_tombs);
19951995
1996 std.mem.set(u32, extra_tombs, 0);
1996 @memset(extra_tombs, 0);
19971997
19981998 const will_die_immediately: bool = switch (pass) {
19991999 .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 {
206206
207207 const start_diff = old_start - better_start;
208208 const new_items = try allocator.alloc(Air.Inst.Ref, better_capacity);
209 mem.set(Air.Inst.Ref, new_items[0..start_diff], .none);
210 mem.copy(Air.Inst.Ref, new_items[start_diff..], map.items);
211 mem.set(Air.Inst.Ref, new_items[start_diff + map.items.len ..], .none);
209 @memset(new_items[0..start_diff], .none);
210 @memcpy(new_items[start_diff..][0..map.items.len], map.items);
211 @memset(new_items[start_diff + map.items.len ..], .none);
212212
213213 allocator.free(map.items);
214214 map.items = new_items;
......@@ -4307,7 +4307,7 @@ fn validateStructInit(
43074307 // Maps field index to field_ptr index of where it was already initialized.
43084308 const found_fields = try gpa.alloc(Zir.Inst.Index, struct_ty.structFieldCount());
43094309 defer gpa.free(found_fields);
4310 mem.set(Zir.Inst.Index, found_fields, 0);
4310 @memset(found_fields, 0);
43114311
43124312 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.
51135113 const byte_count = int.len * @sizeOf(std.math.big.Limb);
51145114 const limb_bytes = sema.code.string_bytes[int.start..][0..byte_count];
51155115 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
51185118 return sema.addConstant(
51195119 Type.initTag(.comptime_int),
......@@ -5967,7 +5967,7 @@ fn addDbgVar(
59675967 const elements_used = name.len / 4 + 1;
59685968 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);
59695969 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
5970 mem.copy(u8, buffer, name);
5970 @memcpy(buffer[0..name.len], name);
59715971 buffer[name.len] = 0;
59725972 sema.air_extra.items.len += elements_used;
59735973
......@@ -10354,7 +10354,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1035410354 .Enum => {
1035510355 seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount());
1035610356 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);
1035810358 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.
1035910359
1036010360 var extra_index: usize = special.end;
......@@ -12809,8 +12809,8 @@ fn analyzeTupleMul(
1280912809 }
1281012810 i = 0;
1281112811 while (i < factor) : (i += 1) {
12812 mem.copy(Type, types[tuple_len * i ..], types[0..tuple_len]);
12813 mem.copy(Value, values[tuple_len * i ..], values[0..tuple_len]);
12812 mem.copyForwards(Type, types[tuple_len * i ..], types[0..tuple_len]);
12813 mem.copyForwards(Value, values[tuple_len * i ..], values[0..tuple_len]);
1281412814 }
1281512815 break :rs runtime_src;
1281612816 };
......@@ -12835,7 +12835,7 @@ fn analyzeTupleMul(
1283512835 }
1283612836 i = 1;
1283712837 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]);
1283912839 }
1284012840
1284112841 return block.addAggregateInit(tuple_ty, element_refs);
......@@ -15057,29 +15057,29 @@ fn zirAsm(
1505715057 sema.appendRefsAssumeCapacity(args);
1505815058 for (outputs) |o| {
1505915059 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15060 mem.copy(u8, buffer, o.c);
15060 @memcpy(buffer[0..o.c.len], o.c);
1506115061 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);
1506315063 buffer[o.c.len + 1 + o.n.len] = 0;
1506415064 sema.air_extra.items.len += (o.c.len + o.n.len + (2 + 3)) / 4;
1506515065 }
1506615066 for (inputs) |input| {
1506715067 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15068 mem.copy(u8, buffer, input.c);
15068 @memcpy(buffer[0..input.c.len], input.c);
1506915069 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);
1507115071 buffer[input.c.len + 1 + input.n.len] = 0;
1507215072 sema.air_extra.items.len += (input.c.len + input.n.len + (2 + 3)) / 4;
1507315073 }
1507415074 for (clobbers) |clobber| {
1507515075 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15076 mem.copy(u8, buffer, clobber);
15076 @memcpy(buffer[0..clobber.len], clobber);
1507715077 buffer[clobber.len] = 0;
1507815078 sema.air_extra.items.len += clobber.len / 4 + 1;
1507915079 }
1508015080 {
1508115081 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
15082 mem.copy(u8, buffer, asm_source);
15082 @memcpy(buffer[0..asm_source.len], asm_source);
1508315083 sema.air_extra.items.len += (asm_source.len + 3) / 4;
1508415084 }
1508515085 return asm_air;
......@@ -17582,7 +17582,7 @@ fn structInitEmpty(
1758217582 // The init values to use for the struct instance.
1758317583 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount());
1758417584 defer gpa.free(field_inits);
17585 mem.set(Air.Inst.Ref, field_inits, .none);
17585 @memset(field_inits, .none);
1758617586
1758717587 return sema.finishStructInit(block, init_src, dest_src, field_inits, struct_ty, false);
1758817588}
......@@ -17675,7 +17675,7 @@ fn zirStructInit(
1767517675 // The init values to use for the struct instance.
1767617676 const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount());
1767717677 defer gpa.free(field_inits);
17678 mem.set(Air.Inst.Ref, field_inits, .none);
17678 @memset(field_inits, .none);
1767917679
1768017680 var field_i: u32 = 0;
1768117681 var extra_index = extra.end;
......@@ -27079,7 +27079,7 @@ fn beginComptimePtrMutation(
2707927079 const array_len_including_sentinel =
2708027080 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel());
2708127081 const elems = try arena.alloc(Value, array_len_including_sentinel);
27082 mem.set(Value, elems, Value.undef);
27082 @memset(elems, Value.undef);
2708327083
2708427084 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
2708527085
......@@ -27277,7 +27277,7 @@ fn beginComptimePtrMutation(
2727727277 switch (parent.ty.zigTypeTag()) {
2727827278 .Struct => {
2727927279 const fields = try arena.alloc(Value, parent.ty.structFieldCount());
27280 mem.set(Value, fields, Value.undef);
27280 @memset(fields, Value.undef);
2728127281
2728227282 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);
2728327283
......@@ -28425,7 +28425,7 @@ fn coerceTupleToStruct(
2842528425 const fields = struct_ty.structFields();
2842628426 const field_vals = try sema.arena.alloc(Value, fields.count());
2842728427 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
2843028430 const inst_ty = sema.typeOf(inst);
2843128431 var runtime_src: ?LazySrcLoc = null;
......@@ -28514,7 +28514,7 @@ fn coerceTupleToTuple(
2851428514 const dest_field_count = tuple_ty.structFieldCount();
2851528515 const field_vals = try sema.arena.alloc(Value, dest_field_count);
2851628516 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
2851928519 const inst_ty = sema.typeOf(inst);
2852028520 const inst_field_count = inst_ty.structFieldCount();
src/arch/aarch64/CodeGen.zig+4-4
......@@ -1630,7 +1630,7 @@ fn allocRegs(
16301630 const read_locks = locks[0..read_args.len];
16311631 const write_locks = locks[read_args.len..];
16321632
1633 std.mem.set(?RegisterLock, locks, null);
1633 @memset(locks, null);
16341634 defer for (locks) |lock| {
16351635 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
16361636 };
......@@ -4395,7 +4395,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43954395 if (args.len + 1 <= Liveness.bpi - 1) {
43964396 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
43974397 buf[0] = callee;
4398 std.mem.copy(Air.Inst.Ref, buf[1..], args);
4398 @memcpy(buf[1..][0..args.len], args);
43994399 return self.finishAir(inst, result, buf);
44004400 }
44014401 var bt = try self.iterateBigTomb(inst, 1 + args.len);
......@@ -5348,7 +5348,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
53485348 buf_index += 1;
53495349 }
53505350 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);
53525352 return self.finishAir(inst, result, buf);
53535353 }
53545354 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
......@@ -6055,7 +6055,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60556055
60566056 if (elements.len <= Liveness.bpi - 1) {
60576057 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);
60596059 return self.finishAir(inst, result, buf);
60606060 }
60616061 var bt = try self.iterateBigTomb(inst, elements.len);
src/arch/arm/CodeGen.zig+4-4
......@@ -3114,7 +3114,7 @@ fn allocRegs(
31143114 const read_locks = locks[0..read_args.len];
31153115 const write_locks = locks[read_args.len..];
31163116
3117 std.mem.set(?RegisterLock, locks, null);
3117 @memset(locks, null);
31183118 defer for (locks) |lock| {
31193119 if (lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
31203120 };
......@@ -4341,7 +4341,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43414341 if (args.len <= Liveness.bpi - 2) {
43424342 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
43434343 buf[0] = callee;
4344 std.mem.copy(Air.Inst.Ref, buf[1..], args);
4344 @memcpy(buf[1..][0..args.len], args);
43454345 return self.finishAir(inst, result, buf);
43464346 }
43474347 var bt = try self.iterateBigTomb(inst, 1 + args.len);
......@@ -5263,7 +5263,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
52635263 buf_index += 1;
52645264 }
52655265 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);
52675267 return self.finishAir(inst, result, buf);
52685268 }
52695269 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
......@@ -6000,7 +6000,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60006000
60016001 if (elements.len <= Liveness.bpi - 1) {
60026002 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);
60046004 return self.finishAir(inst, result, buf);
60056005 }
60066006 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
17841784 if (args.len <= Liveness.bpi - 2) {
17851785 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
17861786 buf[0] = callee;
1787 std.mem.copy(Air.Inst.Ref, buf[1..], args);
1787 @memcpy(buf[1..][0..args.len], args);
17881788 return self.finishAir(inst, result, buf);
17891789 }
17901790 var bt = try self.iterateBigTomb(inst, 1 + args.len);
......@@ -2225,7 +2225,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
22252225 buf_index += 1;
22262226 }
22272227 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);
22292229 return self.finishAir(inst, result, buf);
22302230 }
22312231 var bt = try self.iterateBigTomb(inst, outputs.len + inputs.len);
......@@ -2500,7 +2500,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
25002500
25012501 if (elements.len <= Liveness.bpi - 1) {
25022502 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);
25042504 return self.finishAir(inst, result, buf);
25052505 }
25062506 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 {
843843
844844 if (elements.len <= Liveness.bpi - 1) {
845845 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);
847847 return self.finishAir(inst, result, buf);
848848 }
849849 var bt = try self.iterateBigTomb(inst, elements.len);
......@@ -987,7 +987,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
987987 buf_index += 1;
988988 }
989989 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);
991991 return self.finishAir(inst, result, buf);
992992 }
993993
......@@ -1314,7 +1314,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13141314 if (args.len + 1 <= Liveness.bpi - 1) {
13151315 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
13161316 buf[0] = callee;
1317 std.mem.copy(Air.Inst.Ref, buf[1..], args);
1317 @memcpy(buf[1..][0..args.len], args);
13181318 return self.finishAir(inst, result, buf);
13191319 }
13201320
src/arch/x86_64/CodeGen.zig+2-2
......@@ -7117,7 +7117,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
71177117 buf_index += 1;
71187118 }
71197119 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);
71217121 return self.finishAir(inst, result, buf);
71227122 }
71237123 var bt = self.liveness.iterateBigTomb(inst);
......@@ -8505,7 +8505,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
85058505
85068506 if (elements.len <= Liveness.bpi - 1) {
85078507 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);
85098509 return self.finishAir(inst, result, buf);
85108510 }
85118511 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
546546 .encoding = encoding,
547547 .ops = [1]Operand{.none} ** 4,
548548 };
549 std.mem.copy(Operand, &inst.ops, ops);
549 @memcpy(inst.ops[0..ops.len], ops);
550550
551551 var cwriter = std.io.countingWriter(std.io.null_writer);
552552 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 {
321321 byte_i = 0;
322322 result_i += 1;
323323 }
324 std.mem.copy(Class, result[result_i..], field_class);
324 @memcpy(result[result_i..][0..field_class.len], field_class);
325325 result_i += field_class.len;
326326 // If there are any bytes leftover, we have to try to combine
327327 // the next field with them.
src/arch/x86_64/encoder.zig+2-2
......@@ -182,7 +182,7 @@ pub const Instruction = struct {
182182 .encoding = encoding,
183183 .ops = [1]Operand{.none} ** 4,
184184 };
185 std.mem.copy(Operand, &inst.ops, ops);
185 @memcpy(inst.ops[0..ops.len], ops);
186186 return inst;
187187 }
188188
......@@ -859,7 +859,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8, assembly: []co
859859 const idx = std.mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
860860 var padding = try testing.allocator.alloc(u8, idx + 5);
861861 defer testing.allocator.free(padding);
862 std.mem.set(u8, padding, ' ');
862 @memset(padding, ' ');
863863 std.debug.print("\nASM: {s}\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{
864864 assembly,
865865 expected_fmt,
src/codegen/c.zig+7-7
......@@ -2411,9 +2411,9 @@ pub fn genErrDecls(o: *Object) !void {
24112411 const name_buf = try o.dg.gpa.alloc(u8, name_prefix.len + max_name_len);
24122412 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);
24152415 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);
24172417 const identifier = name_buf[0 .. name_prefix.len + name.len];
24182418
24192419 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 {
48774877 const literal = mem.sliceTo(asm_source[src_i..], '%');
48784878 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);
48814881 dst_i += literal.len;
48824882
48834883 if (src_i >= asm_source.len) break;
......@@ -4902,9 +4902,9 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
49024902 const name = desc[0..colon];
49034903 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);
49064906 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);
49084908 dst_i += name.len;
49094909
49104910 src_i += desc.len;
......@@ -7455,7 +7455,7 @@ fn formatIntLiteral(
74557455 var int_buf: Value.BigIntSpace = undefined;
74567456 const int = if (data.val.isUndefDeep()) blk: {
74577457 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
74607460 var undef_int = BigInt.Mutable{
74617461 .limbs = undef_limbs,
......@@ -7550,7 +7550,7 @@ fn formatIntLiteral(
75507550 } else {
75517551 try data.cty.renderLiteralPrefix(writer, data.kind);
75527552 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);
75547554 wrap.len = wrap.limbs.len;
75557555 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
23672367fn setSectionName(self: *Coff, header: *coff.SectionHeader, name: []const u8) !void {
23682368 if (name.len <= 8) {
23692369 mem.copy(u8, &header.name, name);
2370 mem.set(u8, header.name[name.len..], 0);
2370 @memset(header.name[name.len..], 0);
23712371 return;
23722372 }
23732373 const offset = try self.strtab.insert(self.base.allocator, name);
23742374 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);
23762376}
23772377
23782378fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const u8 {
......@@ -2386,16 +2386,16 @@ fn getSectionName(self: *const Coff, header: *const coff.SectionHeader) []const
23862386fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void {
23872387 if (name.len <= 8) {
23882388 mem.copy(u8, &symbol.name, name);
2389 mem.set(u8, symbol.name[name.len..], 0);
2389 @memset(symbol.name[name.len..], 0);
23902390 return;
23912391 }
23922392 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);
23942394 mem.writeIntLittle(u32, symbol.name[4..8], offset);
23952395}
23962396
23972397fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 {
2398 mem.set(u8, buf[0..4], '_');
2398 @memset(buf[0..4], '_');
23992399 switch (sym.section_number) {
24002400 .UNDEFINED => {
24012401 buf[3] = 'u';
src/link/Dwarf.zig+4-4
......@@ -1189,7 +1189,7 @@ pub fn commitDeclState(
11891189 if (needed_size > segment_size) {
11901190 log.debug(" allocating {d} bytes for 'debug line' information", .{needed_size - segment_size});
11911191 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);
11931193 }
11941194 debug_line.items.len = needed_size;
11951195 }
......@@ -1458,7 +1458,7 @@ fn writeDeclDebugInfo(self: *Dwarf, atom_index: Atom.Index, dbg_info_buf: []cons
14581458 if (needed_size > segment_size) {
14591459 log.debug(" allocating {d} bytes for 'debug info' information", .{needed_size - segment_size});
14601460 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);
14621462 }
14631463 debug_info.items.len = needed_size;
14641464 }
......@@ -2076,9 +2076,9 @@ fn writeDbgInfoNopsToArrayList(
20762076 buffer.items.len,
20772077 offset + content.len + next_padding_size + 1,
20782078 ));
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));
20802080 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
20832083 if (trailing_zero) {
20842084 buffer.items[offset + content.len + next_padding_size] = 0;
src/link/Elf.zig+1-1
......@@ -1997,7 +1997,7 @@ fn writeElfHeader(self: *Elf) !void {
19971997 // OS ABI, often set to 0 regardless of target platform
19981998 // ABI Version, possibly used by glibc but not by static executables
19991999 // padding
2000 mem.set(u8, hdr_buf[index..][0..9], 0);
2000 @memset(hdr_buf[index..][0..9], 0);
20012001 index += 9;
20022002
20032003 assert(index == 16);
src/link/MachO.zig+5-5
......@@ -1454,7 +1454,7 @@ fn createThreadLocalDescriptorAtom(self: *MachO, sym_name: []const u8, target: S
14541454 });
14551455
14561456 var code: [size]u8 = undefined;
1457 mem.set(u8, &code, 0);
1457 @memset(&code, 0);
14581458 try self.writeAtom(atom_index, &code);
14591459
14601460 return atom_index;
......@@ -3234,7 +3234,7 @@ fn writeDyldInfoData(self: *MachO) !void {
32343234
32353235 var buffer = try gpa.alloc(u8, needed_size);
32363236 defer gpa.free(buffer);
3237 mem.set(u8, buffer, 0);
3237 @memset(buffer, 0);
32383238
32393239 var stream = std.io.fixedBufferStream(buffer);
32403240 const writer = stream.writer();
......@@ -3389,7 +3389,7 @@ fn writeStrtab(self: *MachO) !void {
33893389
33903390 const buffer = try gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
33913391 defer gpa.free(buffer);
3392 mem.set(u8, buffer, 0);
3392 @memset(buffer, 0);
33933393 mem.copy(u8, buffer, self.strtab.buffer.items);
33943394
33953395 try self.base.file.?.pwriteAll(buffer, offset);
......@@ -4096,8 +4096,8 @@ pub fn logSections(self: *MachO) void {
40964096}
40974097
40984098fn logSymAttributes(sym: macho.nlist_64, buf: *[4]u8) []const u8 {
4099 mem.set(u8, buf[0..4], '_');
4100 mem.set(u8, buf[4..], ' ');
4099 @memset(buf[0..4], '_');
4100 @memset(buf[4..], ' ');
41014101 if (sym.sect()) {
41024102 buf[0] = 's';
41034103 }
src/link/MachO/Object.zig+6-6
......@@ -156,7 +156,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
156156
157157 // Prepopulate relocations per section lookup table.
158158 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
161161 // Parse symtab.
162162 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)
189189 };
190190 }
191191
192 mem.set(i64, self.globals_lookup, -1);
193 mem.set(AtomIndex, self.atom_by_index_table, 0);
194 mem.set(Entry, self.source_section_index_lookup, .{});
195 mem.set(Entry, self.relocs_lookup, .{});
192 @memset(self.globals_lookup, -1);
193 @memset(self.atom_by_index_table, 0);
194 @memset(self.source_section_index_lookup, .{});
195 @memset(self.relocs_lookup, .{});
196196
197197 // You would expect that the symbol table is at least pre-sorted based on symbol's type:
198198 // 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)
252252 self.unwind_info_sect_id = self.getSourceSectionIndexByName("__LD", "__compact_unwind");
253253 if (self.hasUnwindRecords()) {
254254 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 = .{} });
256256 }
257257}
258258
src/link/MachO/Trie.zig+1-1
......@@ -499,7 +499,7 @@ fn expectEqualHexStrings(expected: []const u8, given: []const u8) !void {
499499 const idx = mem.indexOfDiff(u8, expected_fmt, given_fmt).?;
500500 var padding = try testing.allocator.alloc(u8, idx + 5);
501501 defer testing.allocator.free(padding);
502 mem.set(u8, padding, ' ');
502 @memset(padding, ' ');
503503 std.debug.print("\nEXP: {s}\nGIV: {s}\n{s}^ -- first differing byte\n", .{ expected_fmt, given_fmt, padding });
504504 return error.TestFailed;
505505}
src/link/MachO/UnwindInfo.zig+1-1
......@@ -659,7 +659,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void {
659659 const padding = buffer.items.len - cwriter.bytes_written;
660660 if (padding > 0) {
661661 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);
663663 }
664664
665665 try zld.file.pwriteAll(buffer.items, sect.offset);
src/link/MachO/zld.zig+5-5
......@@ -2140,7 +2140,7 @@ pub const Zld = struct {
21402140
21412141 var buffer = try gpa.alloc(u8, needed_size);
21422142 defer gpa.free(buffer);
2143 mem.set(u8, buffer, 0);
2143 @memset(buffer, 0);
21442144
21452145 var stream = std.io.fixedBufferStream(buffer);
21462146 const writer = stream.writer();
......@@ -2352,7 +2352,7 @@ pub const Zld = struct {
23522352
23532353 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
23542354 defer self.gpa.free(buffer);
2355 mem.set(u8, buffer, 0);
2355 @memset(buffer, 0);
23562356 mem.copy(u8, buffer, mem.sliceAsBytes(out_dice.items));
23572357
23582358 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 {
24842484
24852485 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
24862486 defer self.gpa.free(buffer);
2487 mem.set(u8, buffer, 0);
2487 @memset(buffer, 0);
24882488 mem.copy(u8, buffer, self.strtab.buffer.items);
24892489
24902490 try self.file.pwriteAll(buffer, offset);
......@@ -3199,7 +3199,7 @@ pub const Zld = struct {
31993199 scoped_log.debug(" object({d}): {s}", .{ id, object.name });
32003200 if (object.in_symtab == null) continue;
32013201 for (object.symtab, 0..) |sym, sym_id| {
3202 mem.set(u8, &buf, '_');
3202 @memset(&buf, '_');
32033203 scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{
32043204 sym_id,
32053205 object.getSymbolName(@intCast(u32, sym_id)),
......@@ -4007,7 +4007,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr
40074007 log.debug("zeroing out zerofill area of length {x} at {x}", .{ size, start });
40084008 var padding = try zld.gpa.alloc(u8, size);
40094009 defer zld.gpa.free(padding);
4010 mem.set(u8, padding, 0);
4010 @memset(padding, 0);
40114011 try zld.file.pwriteAll(padding, start);
40124012 }
40134013 }
src/link/Wasm.zig+1-1
......@@ -1976,7 +1976,7 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
19761976 // We do not have to do this when exporting the memory (the default) because the runtime
19771977 // will do it for us, and we do not emit the bss segment at all.
19781978 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);
19801980 }
19811981
19821982 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 {
10881088 const crc_offset = std.mem.alignForward(link.name.len + 1, 4);
10891089 const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4);
10901090 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);
10921092 std.mem.copy(u8, buf[crc_offset..], std.mem.asBytes(&link.crc32));
10931093 break :payload buf;
10941094 };
src/print_air.zig+1-1
......@@ -846,7 +846,7 @@ const Writer = struct {
846846 else blk: {
847847 const slice = w.gpa.alloc([]const Air.Inst.Index, switch_br.data.cases_len + 1) catch
848848 @panic("out of memory");
849 std.mem.set([]const Air.Inst.Index, slice, &.{});
849 @memset(slice, &.{});
850850 break :blk Liveness.SwitchBrTable{ .deaths = slice };
851851 };
852852 defer w.gpa.free(liveness.deaths);
src/print_zir.zig+1-1
......@@ -682,7 +682,7 @@ const Writer = struct {
682682 const limbs = try self.gpa.alloc(std.math.big.Limb, inst_data.len);
683683 defer self.gpa.free(limbs);
684684
685 mem.copy(u8, mem.sliceAsBytes(limbs), limb_bytes);
685 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
686686 const big_int: std.math.big.int.Const = .{
687687 .limbs = limbs,
688688 .positive = true,
src/value.zig+2-2
......@@ -875,7 +875,7 @@ pub const Value = extern union {
875875 .repeated => {
876876 const byte = @intCast(u8, val.castTag(.repeated).?.data.toUnsignedInt(target));
877877 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen()));
878 std.mem.set(u8, result, byte);
878 @memset(result, byte);
879879 return result;
880880 },
881881 .decl_ref => {
......@@ -1287,7 +1287,7 @@ pub const Value = extern union {
12871287 const endian = target.cpu.arch.endian();
12881288 if (val.isUndef()) {
12891289 const size = @intCast(usize, ty.abiSize(target));
1290 std.mem.set(u8, buffer[0..size], 0xaa);
1290 @memset(buffer[0..size], 0xaa);
12911291 return;
12921292 }
12931293 switch (ty.zigTypeTag()) {