authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-27 15:16:01-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-28 13:24:43-07:00
log125221cce9e985e9062f7b599431f3ff50ed79eb
tree70e592f0f9e6304fc9bb903b22f4a64cafe5b665
parent73d3fb9883c1d89fd1460a18f186a1737613bfbc

std: update to use `@memcpy` directly


27 files changed, 119 insertions(+), 115 deletions(-)

lib/std/bit_set.zig+1-1
...@@ -765,7 +765,7 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -765,7 +765,7 @@ pub const DynamicBitSetUnmanaged = struct {
765 const num_masks = numMasks(self.bit_length);765 const num_masks = numMasks(self.bit_length);
766 var copy = Self{};766 var copy = Self{};
767 try copy.resize(new_allocator, self.bit_length, false);767 try copy.resize(new_allocator, self.bit_length, false);
768 std.mem.copy(MaskInt, copy.masks[0..num_masks], self.masks[0..num_masks]);768 @memcpy(copy.masks[0..num_masks], self.masks[0..num_masks]);
769 return copy;769 return copy;
770 }770 }
771771
lib/std/compress/deflate.zig+14
...@@ -12,6 +12,20 @@ pub const Decompressor = inflate.Decompressor;...@@ -12,6 +12,20 @@ pub const Decompressor = inflate.Decompressor;
12pub const compressor = deflate.compressor;12pub const compressor = deflate.compressor;
13pub const decompressor = inflate.decompressor;13pub const decompressor = inflate.decompressor;
1414
15/// Copies elements from a source `src` slice into a destination `dst` slice.
16/// The copy never returns an error but might not be complete if the destination is too small.
17/// Returns the number of elements copied, which will be the minimum of `src.len` and `dst.len`.
18/// TODO: remove this smelly function
19pub fn copy(dst: []u8, src: []const u8) usize {
20 if (dst.len <= src.len) {
21 @memcpy(dst, src[0..dst.len]);
22 return dst.len;
23 } else {
24 @memcpy(dst[0..src.len], src);
25 return src.len;
26 }
27}
28
15test {29test {
16 _ = @import("deflate/token.zig");30 _ = @import("deflate/token.zig");
17 _ = @import("deflate/bits_utils.zig");31 _ = @import("deflate/bits_utils.zig");
lib/std/compress/deflate/compressor.zig+6-7
...@@ -10,7 +10,6 @@ const Allocator = std.mem.Allocator;...@@ -10,7 +10,6 @@ const Allocator = std.mem.Allocator;
10const deflate_const = @import("deflate_const.zig");10const deflate_const = @import("deflate_const.zig");
11const fast = @import("deflate_fast.zig");11const fast = @import("deflate_fast.zig");
12const hm_bw = @import("huffman_bit_writer.zig");12const hm_bw = @import("huffman_bit_writer.zig");
13const mu = @import("mem_utils.zig");
14const token = @import("token.zig");13const token = @import("token.zig");
1514
16pub const Compression = enum(i5) {15pub const Compression = enum(i5) {
...@@ -296,7 +295,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -296,7 +295,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
296 fn fillDeflate(self: *Self, b: []const u8) u32 {295 fn fillDeflate(self: *Self, b: []const u8) u32 {
297 if (self.index >= 2 * window_size - (min_match_length + max_match_length)) {296 if (self.index >= 2 * window_size - (min_match_length + max_match_length)) {
298 // shift the window by window_size297 // shift the window by window_size
299 mem.copy(u8, self.window, self.window[window_size .. 2 * window_size]);298 mem.copyForwards(u8, self.window, self.window[window_size .. 2 * window_size]);
300 self.index -= window_size;299 self.index -= window_size;
301 self.window_end -= window_size;300 self.window_end -= window_size;
302 if (self.block_start >= window_size) {301 if (self.block_start >= window_size) {
...@@ -328,7 +327,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -328,7 +327,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
328 }327 }
329 }328 }
330 }329 }
331 var n = mu.copy(self.window[self.window_end..], b);330 const n = std.compress.deflate.copy(self.window[self.window_end..], b);
332 self.window_end += n;331 self.window_end += n;
333 return @intCast(u32, n);332 return @intCast(u32, n);
334 }333 }
...@@ -369,7 +368,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -369,7 +368,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
369 b = b[b.len - window_size ..];368 b = b[b.len - window_size ..];
370 }369 }
371 // Add all to window.370 // Add all to window.
372 mem.copy(u8, self.window, b);371 @memcpy(self.window[0..b.len], b);
373 var n = b.len;372 var n = b.len;
374373
375 // Calculate 256 hashes at the time (more L1 cache hits)374 // Calculate 256 hashes at the time (more L1 cache hits)
...@@ -706,7 +705,7 @@ pub fn Compressor(comptime WriterType: anytype) type {...@@ -706,7 +705,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
706 }705 }
707706
708 fn fillStore(self: *Self, b: []const u8) u32 {707 fn fillStore(self: *Self, b: []const u8) u32 {
709 var n = mu.copy(self.window[self.window_end..], b);708 const n = std.compress.deflate.copy(self.window[self.window_end..], b);
710 self.window_end += n;709 self.window_end += n;
711 return @intCast(u32, n);710 return @intCast(u32, n);
712 }711 }
...@@ -1091,8 +1090,8 @@ test "bulkHash4" {...@@ -1091,8 +1090,8 @@ test "bulkHash4" {
1091 // double the test data1090 // double the test data
1092 var out = try testing.allocator.alloc(u8, x.out.len * 2);1091 var out = try testing.allocator.alloc(u8, x.out.len * 2);
1093 defer testing.allocator.free(out);1092 defer testing.allocator.free(out);
1094 mem.copy(u8, out[0..x.out.len], x.out);1093 @memcpy(out[0..x.out.len], x.out);
1095 mem.copy(u8, out[x.out.len..], x.out);1094 @memcpy(out[x.out.len..], x.out);
10961095
1097 var j: usize = 4;1096 var j: usize = 4;
1098 while (j < out.len) : (j += 1) {1097 while (j < out.len) : (j += 1) {
lib/std/compress/deflate/decompressor.zig+1-2
...@@ -9,7 +9,6 @@ const ArrayList = std.ArrayList;...@@ -9,7 +9,6 @@ const ArrayList = std.ArrayList;
9const bu = @import("bits_utils.zig");9const bu = @import("bits_utils.zig");
10const ddec = @import("dict_decoder.zig");10const ddec = @import("dict_decoder.zig");
11const deflate_const = @import("deflate_const.zig");11const deflate_const = @import("deflate_const.zig");
12const mu = @import("mem_utils.zig");
1312
14const max_match_offset = deflate_const.max_match_offset;13const max_match_offset = deflate_const.max_match_offset;
15const end_block_marker = deflate_const.end_block_marker;14const end_block_marker = deflate_const.end_block_marker;
...@@ -451,7 +450,7 @@ pub fn Decompressor(comptime ReaderType: type) type {...@@ -451,7 +450,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
451 pub fn read(self: *Self, output: []u8) Error!usize {450 pub fn read(self: *Self, output: []u8) Error!usize {
452 while (true) {451 while (true) {
453 if (self.to_read.len > 0) {452 if (self.to_read.len > 0) {
454 var n = mu.copy(output, self.to_read);453 const n = std.compress.deflate.copy(output, self.to_read);
455 self.to_read = self.to_read[n..];454 self.to_read = self.to_read[n..];
456 if (self.to_read.len == 0 and455 if (self.to_read.len == 0 and
457 self.err != null)456 self.err != null)
lib/std/compress/deflate/deflate_fast.zig+1-1
...@@ -237,7 +237,7 @@ pub const DeflateFast = struct {...@@ -237,7 +237,7 @@ pub const DeflateFast = struct {
237 }237 }
238 self.cur += @intCast(i32, src.len);238 self.cur += @intCast(i32, src.len);
239 self.prev_len = @intCast(u32, src.len);239 self.prev_len = @intCast(u32, src.len);
240 mem.copy(u8, self.prev[0..self.prev_len], src);240 @memcpy(self.prev[0..self.prev_len], src);
241 return;241 return;
242 }242 }
243243
lib/std/compress/deflate/deflate_fast_test.zig+5-5
...@@ -123,13 +123,13 @@ test "best speed max match offset" {...@@ -123,13 +123,13 @@ test "best speed max match offset" {
123 var src = try testing.allocator.alloc(u8, src_len);123 var src = try testing.allocator.alloc(u8, src_len);
124 defer testing.allocator.free(src);124 defer testing.allocator.free(src);
125125
126 mem.copy(u8, src, abc);126 @memcpy(src[0..abc.len], abc);
127 if (!do_match_before) {127 if (!do_match_before) {
128 var src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));128 const src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));
129 mem.copy(u8, src[src_offset..], xyz);129 @memcpy(src[src_offset..][0..xyz.len], xyz);
130 }130 }
131 var src_offset: usize = @intCast(usize, offset);131 const src_offset: usize = @intCast(usize, offset);
132 mem.copy(u8, src[src_offset..], abc);132 @memcpy(src[src_offset..][0..abc.len], abc);
133133
134 var compressed = ArrayList(u8).init(testing.allocator);134 var compressed = ArrayList(u8).init(testing.allocator);
135 defer compressed.deinit();135 defer compressed.deinit();
lib/std/compress/deflate/dict_decoder.zig+7-3
...@@ -47,7 +47,8 @@ pub const DictDecoder = struct {...@@ -47,7 +47,8 @@ pub const DictDecoder = struct {
47 self.wr_pos = 0;47 self.wr_pos = 0;
4848
49 if (dict != null) {49 if (dict != null) {
50 mem.copy(u8, self.hist, dict.?[dict.?.len -| self.hist.len..]);50 const src = dict.?[dict.?.len -| self.hist.len..];
51 @memcpy(self.hist[0..src.len], src);
51 self.wr_pos = @intCast(u32, dict.?.len);52 self.wr_pos = @intCast(u32, dict.?.len);
52 }53 }
5354
...@@ -103,12 +104,15 @@ pub const DictDecoder = struct {...@@ -103,12 +104,15 @@ pub const DictDecoder = struct {
103 self.wr_pos += 1;104 self.wr_pos += 1;
104 }105 }
105106
107 /// TODO: eliminate this function because the callsites should care about whether
108 /// or not their arguments alias and then they should directly call `@memcpy` or
109 /// `mem.copyForwards`.
106 fn copy(dst: []u8, src: []const u8) u32 {110 fn copy(dst: []u8, src: []const u8) u32 {
107 if (src.len > dst.len) {111 if (src.len > dst.len) {
108 mem.copy(u8, dst, src[0..dst.len]);112 mem.copyForwards(u8, dst, src[0..dst.len]);
109 return @intCast(u32, dst.len);113 return @intCast(u32, dst.len);
110 }114 }
111 mem.copy(u8, dst, src);115 mem.copyForwards(u8, dst[0..src.len], src);
112 return @intCast(u32, src.len);116 return @intCast(u32, src.len);
113 }117 }
114118
lib/std/compress/deflate/huffman_code.zig+1-1
...@@ -202,7 +202,7 @@ pub const HuffmanEncoder = struct {...@@ -202,7 +202,7 @@ pub const HuffmanEncoder = struct {
202 // more values in the level below202 // more values in the level below
203 l.last_freq = l.next_pair_freq;203 l.last_freq = l.next_pair_freq;
204 // Take leaf counts from the lower level, except counts[level] remains the same.204 // Take leaf counts from the lower level, except counts[level] remains the same.
205 mem.copy(u32, leaf_counts[level][0..level], leaf_counts[level - 1][0..level]);205 @memcpy(leaf_counts[level][0..level], leaf_counts[level - 1][0..level]);
206 levels[l.level - 1].needed = 2;206 levels[l.level - 1].needed = 2;
207 }207 }
208208
lib/std/compress/deflate/mem_utils.zig deleted-15
...@@ -1,15 +0,0 @@
1const std = @import("std");
2const math = std.math;
3const mem = std.mem;
4
5// Copies elements from a source `src` slice into a destination `dst` slice.
6// The copy never returns an error but might not be complete if the destination is too small.
7// Returns the number of elements copied, which will be the minimum of `src.len` and `dst.len`.
8pub fn copy(dst: []u8, src: []const u8) usize {
9 if (dst.len <= src.len) {
10 mem.copy(u8, dst[0..], src[0..dst.len]);
11 } else {
12 mem.copy(u8, dst[0..src.len], src[0..]);
13 }
14 return math.min(dst.len, src.len);
15}
lib/std/compress/xz/block.zig+3-3
...@@ -59,9 +59,9 @@ pub fn Decoder(comptime ReaderType: type) type {...@@ -59,9 +59,9 @@ pub fn Decoder(comptime ReaderType: type) type {
59 while (true) {59 while (true) {
60 if (self.to_read.items.len > 0) {60 if (self.to_read.items.len > 0) {
61 const input = self.to_read.items;61 const input = self.to_read.items;
62 const n = std.math.min(input.len, output.len);62 const n = @min(input.len, output.len);
63 std.mem.copy(u8, output[0..n], input[0..n]);63 @memcpy(output[0..n], input[0..n]);
64 std.mem.copy(u8, input, input[n..]);64 std.mem.copyForwards(u8, input, input[n..]);
65 self.to_read.shrinkRetainingCapacity(input.len - n);65 self.to_read.shrinkRetainingCapacity(input.len - n);
66 if (self.to_read.items.len == 0 and self.err != null) {66 if (self.to_read.items.len == 0 and self.err != null) {
67 if (self.err.? == DecodeError.EndOfStreamWithNoError) {67 if (self.err.? == DecodeError.EndOfStreamWithNoError) {
lib/std/crypto/argon2.zig+6-6
...@@ -149,7 +149,7 @@ fn blake2bLong(out: []u8, in: []const u8) void {...@@ -149,7 +149,7 @@ fn blake2bLong(out: []u8, in: []const u8) void {
149 h.update(&outlen_bytes);149 h.update(&outlen_bytes);
150 h.update(in);150 h.update(in);
151 h.final(&out_buf);151 h.final(&out_buf);
152 mem.copy(u8, out, out_buf[0..out.len]);152 @memcpy(out, out_buf[0..out.len]);
153 return;153 return;
154 }154 }
155155
...@@ -158,19 +158,19 @@ fn blake2bLong(out: []u8, in: []const u8) void {...@@ -158,19 +158,19 @@ fn blake2bLong(out: []u8, in: []const u8) void {
158 h.update(in);158 h.update(in);
159 h.final(&out_buf);159 h.final(&out_buf);
160 var out_slice = out;160 var out_slice = out;
161 mem.copy(u8, out_slice, out_buf[0 .. H.digest_length / 2]);161 out_slice[0 .. H.digest_length / 2].* = out_buf[0 .. H.digest_length / 2].*;
162 out_slice = out_slice[H.digest_length / 2 ..];162 out_slice = out_slice[H.digest_length / 2 ..];
163163
164 var in_buf: [H.digest_length]u8 = undefined;164 var in_buf: [H.digest_length]u8 = undefined;
165 while (out_slice.len > H.digest_length) {165 while (out_slice.len > H.digest_length) {
166 mem.copy(u8, &in_buf, &out_buf);166 in_buf = out_buf;
167 H.hash(&in_buf, &out_buf, .{});167 H.hash(&in_buf, &out_buf, .{});
168 mem.copy(u8, out_slice, out_buf[0 .. H.digest_length / 2]);168 out_slice[0 .. H.digest_length / 2].* = out_buf[0 .. H.digest_length / 2].*;
169 out_slice = out_slice[H.digest_length / 2 ..];169 out_slice = out_slice[H.digest_length / 2 ..];
170 }170 }
171 mem.copy(u8, &in_buf, &out_buf);171 in_buf = out_buf;
172 H.hash(&in_buf, &out_buf, .{ .expected_out_bits = out_slice.len * 8 });172 H.hash(&in_buf, &out_buf, .{ .expected_out_bits = out_slice.len * 8 });
173 mem.copy(u8, out_slice, out_buf[0..out_slice.len]);173 @memcpy(out_slice, out_buf[0..out_slice.len]);
174}174}
175175
176fn initBlocks(176fn initBlocks(
lib/std/crypto/kyber_d00.zig+13-17
...@@ -323,9 +323,9 @@ fn Kyber(comptime p: Params) type {...@@ -323,9 +323,9 @@ fn Kyber(comptime p: Params) type {
323 s += InnerSk.bytes_length;323 s += InnerSk.bytes_length;
324 ret.pk = InnerPk.fromBytes(buf[s .. s + InnerPk.bytes_length]);324 ret.pk = InnerPk.fromBytes(buf[s .. s + InnerPk.bytes_length]);
325 s += InnerPk.bytes_length;325 s += InnerPk.bytes_length;
326 mem.copy(u8, &ret.hpk, buf[s .. s + h_length]);326 ret.hpk = buf[s..][0..h_length].*;
327 s += h_length;327 s += h_length;
328 mem.copy(u8, &ret.z, buf[s .. s + shared_length]);328 ret.z = buf[s..][0..shared_length].*;
329 return ret;329 return ret;
330 }330 }
331 };331 };
...@@ -345,7 +345,7 @@ fn Kyber(comptime p: Params) type {...@@ -345,7 +345,7 @@ fn Kyber(comptime p: Params) type {
345 break :sk random_seed;345 break :sk random_seed;
346 };346 };
347 var ret: KeyPair = undefined;347 var ret: KeyPair = undefined;
348 mem.copy(u8, &ret.secret_key.z, seed[inner_seed_length..seed_length]);348 ret.secret_key.z = seed[inner_seed_length..seed_length].*;
349349
350 // Generate inner key350 // Generate inner key
351 innerKeyFromSeed(351 innerKeyFromSeed(
...@@ -356,7 +356,7 @@ fn Kyber(comptime p: Params) type {...@@ -356,7 +356,7 @@ fn Kyber(comptime p: Params) type {
356 ret.secret_key.pk = ret.public_key.pk;356 ret.secret_key.pk = ret.public_key.pk;
357357
358 // Copy over z from seed.358 // Copy over z from seed.
359 mem.copy(u8, &ret.secret_key.z, seed[inner_seed_length..seed_length]);359 ret.secret_key.z = seed[inner_seed_length..seed_length].*;
360360
361 // Compute H(pk)361 // Compute H(pk)
362 var h = sha3.Sha3_256.init(.{});362 var h = sha3.Sha3_256.init(.{});
...@@ -418,7 +418,7 @@ fn Kyber(comptime p: Params) type {...@@ -418,7 +418,7 @@ fn Kyber(comptime p: Params) type {
418 fn fromBytes(buf: *const [bytes_length]u8) InnerPk {418 fn fromBytes(buf: *const [bytes_length]u8) InnerPk {
419 var ret: InnerPk = undefined;419 var ret: InnerPk = undefined;
420 ret.th = V.fromBytes(buf[0..V.bytes_length]).normalize();420 ret.th = V.fromBytes(buf[0..V.bytes_length]).normalize();
421 mem.copy(u8, &ret.rho, buf[V.bytes_length..bytes_length]);421 ret.rho = buf[V.bytes_length..bytes_length].*;
422 ret.aT = M.uniform(ret.rho, true);422 ret.aT = M.uniform(ret.rho, true);
423 return ret;423 return ret;
424 }424 }
...@@ -459,7 +459,7 @@ fn Kyber(comptime p: Params) type {...@@ -459,7 +459,7 @@ fn Kyber(comptime p: Params) type {
459 var h = sha3.Sha3_512.init(.{});459 var h = sha3.Sha3_512.init(.{});
460 h.update(&seed);460 h.update(&seed);
461 h.final(&expanded_seed);461 h.final(&expanded_seed);
462 mem.copy(u8, &pk.rho, expanded_seed[0..32]);462 pk.rho = expanded_seed[0..32].*;
463 const sigma = expanded_seed[32..64];463 const sigma = expanded_seed[32..64];
464 pk.aT = M.uniform(pk.rho, false); // Expand ρ to A; we'll transpose later on464 pk.aT = M.uniform(pk.rho, false); // Expand ρ to A; we'll transpose later on
465465
...@@ -1381,7 +1381,7 @@ fn Vec(comptime K: u8) type {...@@ -1381,7 +1381,7 @@ fn Vec(comptime K: u8) type {
1381 const cs = comptime Poly.compressedSize(d);1381 const cs = comptime Poly.compressedSize(d);
1382 var ret: [compressedSize(d)]u8 = undefined;1382 var ret: [compressedSize(d)]u8 = undefined;
1383 inline for (0..K) |i| {1383 inline for (0..K) |i| {
1384 mem.copy(u8, ret[i * cs .. (i + 1) * cs], &v.ps[i].compress(d));1384 ret[i * cs .. (i + 1) * cs].* = v.ps[i].compress(d);
1385 }1385 }
1386 return ret;1386 return ret;
1387 }1387 }
...@@ -1399,11 +1399,7 @@ fn Vec(comptime K: u8) type {...@@ -1399,11 +1399,7 @@ fn Vec(comptime K: u8) type {
1399 fn toBytes(v: Self) [bytes_length]u8 {1399 fn toBytes(v: Self) [bytes_length]u8 {
1400 var ret: [bytes_length]u8 = undefined;1400 var ret: [bytes_length]u8 = undefined;
1401 inline for (0..K) |i| {1401 inline for (0..K) |i| {
1402 mem.copy(1402 ret[i * Poly.bytes_length .. (i + 1) * Poly.bytes_length].* = v.ps[i].toBytes();
1403 u8,
1404 ret[i * Poly.bytes_length .. (i + 1) * Poly.bytes_length],
1405 &v.ps[i].toBytes(),
1406 );
1407 }1403 }
1408 return ret;1404 return ret;
1409 }1405 }
...@@ -1742,15 +1738,15 @@ const NistDRBG = struct {...@@ -1742,15 +1738,15 @@ const NistDRBG = struct {
1742 g.incV();1738 g.incV();
1743 var block: [16]u8 = undefined;1739 var block: [16]u8 = undefined;
1744 ctx.encrypt(&block, &g.v);1740 ctx.encrypt(&block, &g.v);
1745 mem.copy(u8, buf[i * 16 .. (i + 1) * 16], &block);1741 buf[i * 16 ..][0..16].* = block;
1746 }1742 }
1747 if (pd) |p| {1743 if (pd) |p| {
1748 for (&buf, p) |*b, x| {1744 for (&buf, p) |*b, x| {
1749 b.* ^= x;1745 b.* ^= x;
1750 }1746 }
1751 }1747 }
1752 mem.copy(u8, &g.key, buf[0..32]);1748 g.key = buf[0..32].*;
1753 mem.copy(u8, &g.v, buf[32..48]);1749 g.v = buf[32..48].*;
1754 }1750 }
17551751
1756 // randombytes.1752 // randombytes.
...@@ -1763,10 +1759,10 @@ const NistDRBG = struct {...@@ -1763,10 +1759,10 @@ const NistDRBG = struct {
1763 g.incV();1759 g.incV();
1764 ctx.encrypt(&block, &g.v);1760 ctx.encrypt(&block, &g.v);
1765 if (dst.len < 16) {1761 if (dst.len < 16) {
1766 mem.copy(u8, dst, block[0..dst.len]);1762 @memcpy(dst, block[0..dst.len]);
1767 break;1763 break;
1768 }1764 }
1769 mem.copy(u8, dst, &block);1765 dst[0..block.len].* = block;
1770 dst = dst[16..dst.len];1766 dst = dst[16..dst.len];
1771 }1767 }
1772 g.update(null);1768 g.update(null);
lib/std/crypto/scrypt.zig+3-3
...@@ -27,7 +27,7 @@ const max_salt_len = 64;...@@ -27,7 +27,7 @@ const max_salt_len = 64;
27const max_hash_len = 64;27const max_hash_len = 64;
2828
29fn blockCopy(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {29fn blockCopy(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {
30 mem.copy(u32, dst, src[0 .. n * 16]);30 @memcpy(dst[0 .. n * 16], src[0 .. n * 16]);
31}31}
3232
33fn blockXor(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {33fn blockXor(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {
...@@ -242,7 +242,7 @@ const crypt_format = struct {...@@ -242,7 +242,7 @@ const crypt_format = struct {
242 pub fn fromSlice(slice: []const u8) EncodingError!Self {242 pub fn fromSlice(slice: []const u8) EncodingError!Self {
243 if (slice.len > capacity) return EncodingError.NoSpaceLeft;243 if (slice.len > capacity) return EncodingError.NoSpaceLeft;
244 var bin_value: Self = undefined;244 var bin_value: Self = undefined;
245 mem.copy(u8, &bin_value.buf, slice);245 @memcpy(bin_value.buf[0..slice.len], slice);
246 bin_value.len = slice.len;246 bin_value.len = slice.len;
247 return bin_value;247 return bin_value;
248 }248 }
...@@ -314,7 +314,7 @@ const crypt_format = struct {...@@ -314,7 +314,7 @@ const crypt_format = struct {
314314
315 fn serializeTo(params: anytype, out: anytype) !void {315 fn serializeTo(params: anytype, out: anytype) !void {
316 var header: [14]u8 = undefined;316 var header: [14]u8 = undefined;
317 mem.copy(u8, header[0..3], prefix);317 header[0..3].* = prefix.*;
318 Codec.intEncode(header[3..4], params.ln);318 Codec.intEncode(header[3..4], params.ln);
319 Codec.intEncode(header[4..9], params.r);319 Codec.intEncode(header[4..9], params.r);
320 Codec.intEncode(header[9..14], params.p);320 Codec.intEncode(header[9..14], params.p);
lib/std/crypto/tls.zig+2-2
...@@ -312,11 +312,11 @@ pub fn hkdfExpandLabel(...@@ -312,11 +312,11 @@ pub fn hkdfExpandLabel(
312 buf[2] = @intCast(u8, tls13.len + label.len);312 buf[2] = @intCast(u8, tls13.len + label.len);
313 buf[3..][0..tls13.len].* = tls13.*;313 buf[3..][0..tls13.len].* = tls13.*;
314 var i: usize = 3 + tls13.len;314 var i: usize = 3 + tls13.len;
315 mem.copy(u8, buf[i..], label);315 @memcpy(buf[i..][0..label.len], label);
316 i += label.len;316 i += label.len;
317 buf[i] = @intCast(u8, context.len);317 buf[i] = @intCast(u8, context.len);
318 i += 1;318 i += 1;
319 mem.copy(u8, buf[i..], context);319 @memcpy(buf[i..][0..context.len], context);
320 i += context.len;320 i += context.len;
321321
322 var result: [len]u8 = undefined;322 var result: [len]u8 = undefined;
lib/std/debug.zig+2-2
...@@ -309,8 +309,8 @@ pub fn panicExtra(...@@ -309,8 +309,8 @@ pub fn panicExtra(
309 // error being part of the @panic stack trace (but that error should309 // error being part of the @panic stack trace (but that error should
310 // only happen rarely)310 // only happen rarely)
311 const msg = std.fmt.bufPrint(buf[0..size], format, args) catch |err| switch (err) {311 const msg = std.fmt.bufPrint(buf[0..size], format, args) catch |err| switch (err) {
312 std.fmt.BufPrintError.NoSpaceLeft => blk: {312 error.NoSpaceLeft => blk: {
313 std.mem.copy(u8, buf[size..], trunc_msg);313 @memcpy(buf[size..], trunc_msg);
314 break :blk &buf;314 break :blk &buf;
315 },315 },
316 };316 };
lib/std/fs.zig+19-15
...@@ -106,7 +106,7 @@ pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path:...@@ -106,7 +106,7 @@ pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path:
106 var rand_buf: [AtomicFile.RANDOM_BYTES]u8 = undefined;106 var rand_buf: [AtomicFile.RANDOM_BYTES]u8 = undefined;
107 const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64_encoder.calcSize(rand_buf.len));107 const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64_encoder.calcSize(rand_buf.len));
108 defer allocator.free(tmp_path);108 defer allocator.free(tmp_path);
109 mem.copy(u8, tmp_path[0..], dirname);109 @memcpy(tmp_path[0..dirname.len], dirname);
110 tmp_path[dirname.len] = path.sep;110 tmp_path[dirname.len] = path.sep;
111 while (true) {111 while (true) {
112 crypto.random.bytes(rand_buf[0..]);112 crypto.random.bytes(rand_buf[0..]);
...@@ -1541,9 +1541,9 @@ pub const Dir = struct {...@@ -1541,9 +1541,9 @@ pub const Dir = struct {
1541 return error.NameTooLong;1541 return error.NameTooLong;
1542 }1542 }
15431543
1544 mem.copy(u8, out_buffer, out_path);1544 const result = out_buffer[0..out_path.len];
15451545 @memcpy(result, out_path);
1546 return out_buffer[0..out_path.len];1546 return result;
1547 }1547 }
15481548
1549 /// Windows-only. Same as `Dir.realpath` except `pathname` is WTF16 encoded.1549 /// Windows-only. Same as `Dir.realpath` except `pathname` is WTF16 encoded.
...@@ -1593,9 +1593,9 @@ pub const Dir = struct {...@@ -1593,9 +1593,9 @@ pub const Dir = struct {
1593 return error.NameTooLong;1593 return error.NameTooLong;
1594 }1594 }
15951595
1596 mem.copy(u8, out_buffer, out_path);1596 const result = out_buffer[0..out_path.len];
15971597 @memcpy(result, out_path);
1598 return out_buffer[0..out_path.len];1598 return result;
1599 }1599 }
16001600
1601 /// Same as `Dir.realpath` except caller must free the returned memory.1601 /// Same as `Dir.realpath` except caller must free the returned memory.
...@@ -2346,8 +2346,9 @@ pub const Dir = struct {...@@ -2346,8 +2346,9 @@ pub const Dir = struct {
2346 if (cleanup_dir_parent) |*d| d.close();2346 if (cleanup_dir_parent) |*d| d.close();
2347 cleanup_dir_parent = iterable_dir;2347 cleanup_dir_parent = iterable_dir;
2348 iterable_dir = new_dir;2348 iterable_dir = new_dir;
2349 mem.copy(u8, &dir_name_buf, entry.name);2349 const result = dir_name_buf[0..entry.name.len];
2350 dir_name = dir_name_buf[0..entry.name.len];2350 @memcpy(result, entry.name);
2351 dir_name = result;
2351 continue :scan_dir;2352 continue :scan_dir;
2352 } else {2353 } else {
2353 if (iterable_dir.dir.deleteFile(entry.name)) {2354 if (iterable_dir.dir.deleteFile(entry.name)) {
...@@ -2974,8 +2975,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -2974,8 +2975,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
2974 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;2975 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;
2975 const real_path = try std.os.realpathZ(&symlink_path_buf, &real_path_buf);2976 const real_path = try std.os.realpathZ(&symlink_path_buf, &real_path_buf);
2976 if (real_path.len > out_buffer.len) return error.NameTooLong;2977 if (real_path.len > out_buffer.len) return error.NameTooLong;
2977 std.mem.copy(u8, out_buffer, real_path);2978 const result = out_buffer[0..real_path.len];
2978 return out_buffer[0..real_path.len];2979 @memcpy(result, real_path);
2980 return result;
2979 }2981 }
2980 switch (builtin.os.tag) {2982 switch (builtin.os.tag) {
2981 .linux => return os.readlinkZ("/proc/self/exe", out_buffer),2983 .linux => return os.readlinkZ("/proc/self/exe", out_buffer),
...@@ -3014,8 +3016,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -3014,8 +3016,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
3014 const real_path = try os.realpathZ(os.argv[0], &real_path_buf);3016 const real_path = try os.realpathZ(os.argv[0], &real_path_buf);
3015 if (real_path.len > out_buffer.len)3017 if (real_path.len > out_buffer.len)
3016 return error.NameTooLong;3018 return error.NameTooLong;
3017 mem.copy(u8, out_buffer, real_path);3019 const result = out_buffer[0..real_path.len];
3018 return out_buffer[0..real_path.len];3020 @memcpy(result, real_path);
3021 return result;
3019 } else if (argv0.len != 0) {3022 } else if (argv0.len != 0) {
3020 // argv[0] is not empty (and not a path): search it inside PATH3023 // argv[0] is not empty (and not a path): search it inside PATH
3021 const PATH = std.os.getenvZ("PATH") orelse return error.FileNotFound;3024 const PATH = std.os.getenvZ("PATH") orelse return error.FileNotFound;
...@@ -3032,8 +3035,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -3032,8 +3035,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
3032 // found a file, and hope it is the right file3035 // found a file, and hope it is the right file
3033 if (real_path.len > out_buffer.len)3036 if (real_path.len > out_buffer.len)
3034 return error.NameTooLong;3037 return error.NameTooLong;
3035 mem.copy(u8, out_buffer, real_path);3038 const result = out_buffer[0..real_path.len];
3036 return out_buffer[0..real_path.len];3039 @memcpy(result, real_path);
3040 return result;
3037 } else |_| continue;3041 } else |_| continue;
3038 }3042 }
3039 }3043 }
lib/std/http/Client.zig+1-1
...@@ -284,7 +284,7 @@ pub const BufferedConnection = struct {...@@ -284,7 +284,7 @@ pub const BufferedConnection = struct {
284 if (available > 0) {284 if (available > 0) {
285 const can_read = @truncate(u16, @min(available, left));285 const can_read = @truncate(u16, @min(available, left));
286286
287 std.mem.copy(u8, buffer[out_index..], bconn.buf[bconn.start..][0..can_read]);287 @memcpy(buffer[out_index..][0..can_read], bconn.buf[bconn.start..][0..can_read]);
288 out_index += can_read;288 out_index += can_read;
289 bconn.start += can_read;289 bconn.start += can_read;
290290
lib/std/http/Headers.zig+2-1
...@@ -38,7 +38,8 @@ pub const Field = struct {...@@ -38,7 +38,8 @@ pub const Field = struct {
3838
39 pub fn modify(entry: *Field, allocator: Allocator, new_value: []const u8) !void {39 pub fn modify(entry: *Field, allocator: Allocator, new_value: []const u8) !void {
40 if (entry.value.len <= new_value.len) {40 if (entry.value.len <= new_value.len) {
41 std.mem.copy(u8, @constCast(entry.value), new_value);41 // TODO: eliminate this use of `@constCast`.
42 @memcpy(@constCast(entry.value)[0..new_value.len], new_value);
42 } else {43 } else {
43 allocator.free(entry.value);44 allocator.free(entry.value);
4445
lib/std/http/Server.zig+1-1
...@@ -128,7 +128,7 @@ pub const BufferedConnection = struct {...@@ -128,7 +128,7 @@ pub const BufferedConnection = struct {
128 if (available > 0) {128 if (available > 0) {
129 const can_read = @truncate(u16, @min(available, left));129 const can_read = @truncate(u16, @min(available, left));
130130
131 std.mem.copy(u8, buffer[out_index..], bconn.buf[bconn.start..][0..can_read]);131 @memcpy(buffer[out_index..][0..can_read], bconn.buf[bconn.start..][0..can_read]);
132 out_index += can_read;132 out_index += can_read;
133 bconn.start += can_read;133 bconn.start += can_read;
134134
lib/std/http/protocol.zig+1-1
...@@ -654,7 +654,7 @@ const MockBufferedConnection = struct {...@@ -654,7 +654,7 @@ const MockBufferedConnection = struct {
654 if (available > 0) {654 if (available > 0) {
655 const can_read = @truncate(u16, @min(available, left));655 const can_read = @truncate(u16, @min(available, left));
656656
657 std.mem.copy(u8, buffer[out_index..], bconn.buf[bconn.start..][0..can_read]);657 @memcpy(buffer[out_index..][0..can_read], bconn.buf[bconn.start..][0..can_read]);
658 out_index += can_read;658 out_index += can_read;
659 bconn.start += can_read;659 bconn.start += can_read;
660660
lib/std/net.zig+11-11
...@@ -107,7 +107,7 @@ pub const Address = extern union {...@@ -107,7 +107,7 @@ pub const Address = extern union {
107 if (path.len + 1 > sock_addr.path.len) return error.NameTooLong;107 if (path.len + 1 > sock_addr.path.len) return error.NameTooLong;
108108
109 @memset(&sock_addr.path, 0);109 @memset(&sock_addr.path, 0);
110 mem.copy(u8, &sock_addr.path, path);110 @memcpy(sock_addr.path[0..path.len], path);
111111
112 return Address{ .un = sock_addr };112 return Address{ .un = sock_addr };
113 }113 }
...@@ -416,7 +416,7 @@ pub const Ip6Address = extern struct {...@@ -416,7 +416,7 @@ pub const Ip6Address = extern struct {
416 index += 1;416 index += 1;
417 ip_slice[index] = @truncate(u8, x);417 ip_slice[index] = @truncate(u8, x);
418 index += 1;418 index += 1;
419 mem.copy(u8, result.sa.addr[16 - index ..], ip_slice[0..index]);419 @memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);
420 return result;420 return result;
421 }421 }
422 }422 }
...@@ -550,7 +550,7 @@ pub const Ip6Address = extern struct {...@@ -550,7 +550,7 @@ pub const Ip6Address = extern struct {
550 index += 1;550 index += 1;
551 ip_slice[index] = @truncate(u8, x);551 ip_slice[index] = @truncate(u8, x);
552 index += 1;552 index += 1;
553 mem.copy(u8, result.sa.addr[16 - index ..], ip_slice[0..index]);553 @memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);
554 return result;554 return result;
555 }555 }
556 }556 }
...@@ -662,7 +662,7 @@ fn if_nametoindex(name: []const u8) !u32 {...@@ -662,7 +662,7 @@ fn if_nametoindex(name: []const u8) !u32 {
662 var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);662 var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
663 defer os.closeSocket(sockfd);663 defer os.closeSocket(sockfd);
664664
665 std.mem.copy(u8, &ifr.ifrn.name, name);665 @memcpy(ifr.ifrn.name[0..name.len], name);
666 ifr.ifrn.name[name.len] = 0;666 ifr.ifrn.name[name.len] = 0;
667667
668 // TODO investigate if this needs to be integrated with evented I/O.668 // TODO investigate if this needs to be integrated with evented I/O.
...@@ -676,7 +676,7 @@ fn if_nametoindex(name: []const u8) !u32 {...@@ -676,7 +676,7 @@ fn if_nametoindex(name: []const u8) !u32 {
676 return error.NameTooLong;676 return error.NameTooLong;
677677
678 var if_name: [os.IFNAMESIZE:0]u8 = undefined;678 var if_name: [os.IFNAMESIZE:0]u8 = undefined;
679 std.mem.copy(u8, &if_name, name);679 @memcpy(if_name[0..name.len], name);
680 if_name[name.len] = 0;680 if_name[name.len] = 0;
681 const if_slice = if_name[0..name.len :0];681 const if_slice = if_name[0..name.len :0];
682 const index = os.system.if_nametoindex(if_slice);682 const index = os.system.if_nametoindex(if_slice);
...@@ -1041,14 +1041,14 @@ fn linuxLookupName(...@@ -1041,14 +1041,14 @@ fn linuxLookupName(
1041 var salen: os.socklen_t = undefined;1041 var salen: os.socklen_t = undefined;
1042 var dalen: os.socklen_t = undefined;1042 var dalen: os.socklen_t = undefined;
1043 if (addr.addr.any.family == os.AF.INET6) {1043 if (addr.addr.any.family == os.AF.INET6) {
1044 mem.copy(u8, &da6.addr, &addr.addr.in6.sa.addr);1044 da6.addr = addr.addr.in6.sa.addr;
1045 da = @ptrCast(*os.sockaddr, &da6);1045 da = @ptrCast(*os.sockaddr, &da6);
1046 dalen = @sizeOf(os.sockaddr.in6);1046 dalen = @sizeOf(os.sockaddr.in6);
1047 sa = @ptrCast(*os.sockaddr, &sa6);1047 sa = @ptrCast(*os.sockaddr, &sa6);
1048 salen = @sizeOf(os.sockaddr.in6);1048 salen = @sizeOf(os.sockaddr.in6);
1049 } else {1049 } else {
1050 mem.copy(u8, &sa6.addr, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");1050 sa6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
1051 mem.copy(u8, &da6.addr, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");1051 da6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
1052 mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);1052 mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);
1053 da4.addr = addr.addr.in.sa.addr;1053 da4.addr = addr.addr.in.sa.addr;
1054 da = @ptrCast(*os.sockaddr, &da4);1054 da = @ptrCast(*os.sockaddr, &da4);
...@@ -1343,7 +1343,7 @@ fn linuxLookupNameFromDnsSearch(...@@ -1343,7 +1343,7 @@ fn linuxLookupNameFromDnsSearch(
1343 // name is not a CNAME record) and serves as a buffer for passing1343 // name is not a CNAME record) and serves as a buffer for passing
1344 // the full requested name to name_from_dns.1344 // the full requested name to name_from_dns.
1345 try canon.resize(canon_name.len);1345 try canon.resize(canon_name.len);
1346 mem.copy(u8, canon.items, canon_name);1346 @memcpy(canon.items, canon_name);
1347 try canon.append('.');1347 try canon.append('.');
13481348
1349 var tok_it = mem.tokenize(u8, search, " \t");1349 var tok_it = mem.tokenize(u8, search, " \t");
...@@ -1567,7 +1567,7 @@ fn resMSendRc(...@@ -1567,7 +1567,7 @@ fn resMSendRc(
1567 for (0..ns.len) |i| {1567 for (0..ns.len) |i| {
1568 if (ns[i].any.family != os.AF.INET) continue;1568 if (ns[i].any.family != os.AF.INET) continue;
1569 mem.writeIntNative(u32, ns[i].in6.sa.addr[12..], ns[i].in.sa.addr);1569 mem.writeIntNative(u32, ns[i].in6.sa.addr[12..], ns[i].in.sa.addr);
1570 mem.copy(u8, ns[i].in6.sa.addr[0..12], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");1570 ns[i].in6.sa.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
1571 ns[i].any.family = os.AF.INET6;1571 ns[i].any.family = os.AF.INET6;
1572 ns[i].in6.sa.flowinfo = 0;1572 ns[i].in6.sa.flowinfo = 0;
1573 ns[i].in6.sa.scope_id = 0;1573 ns[i].in6.sa.scope_id = 0;
...@@ -1665,7 +1665,7 @@ fn resMSendRc(...@@ -1665,7 +1665,7 @@ fn resMSendRc(
1665 if (i == next) {1665 if (i == next) {
1666 while (next < queries.len and answers[next].len != 0) : (next += 1) {}1666 while (next < queries.len and answers[next].len != 0) : (next += 1) {}
1667 } else {1667 } else {
1668 mem.copy(u8, answer_bufs[i], answer_bufs[next][0..rlen]);1668 @memcpy(answer_bufs[i][0..rlen], answer_bufs[next][0..rlen]);
1669 }1669 }
16701670
1671 if (next == queries.len) break :outer;1671 if (next == queries.len) break :outer;
lib/std/os/linux/bpf.zig+1-1
...@@ -1631,7 +1631,7 @@ test "map lookup, update, and delete" {...@@ -1631,7 +1631,7 @@ test "map lookup, update, and delete" {
1631 const status = try map_get_next_key(map, &lookup_key, &next_key);1631 const status = try map_get_next_key(map, &lookup_key, &next_key);
1632 try expectEqual(status, true);1632 try expectEqual(status, true);
1633 try expectEqual(next_key, key);1633 try expectEqual(next_key, key);
1634 std.mem.copy(u8, &lookup_key, &next_key);1634 lookup_key = next_key;
1635 const status2 = try map_get_next_key(map, &lookup_key, &next_key);1635 const status2 = try map_get_next_key(map, &lookup_key, &next_key);
1636 try expectEqual(status2, false);1636 try expectEqual(status2, false);
16371637
lib/std/os/linux/io_uring.zig+1-1
...@@ -1856,7 +1856,7 @@ test "write_fixed/read_fixed" {...@@ -1856,7 +1856,7 @@ test "write_fixed/read_fixed" {
1856 var raw_buffers: [2][11]u8 = undefined;1856 var raw_buffers: [2][11]u8 = undefined;
1857 // First buffer will be written to the file.1857 // First buffer will be written to the file.
1858 @memset(&raw_buffers[0], 'z');1858 @memset(&raw_buffers[0], 'z');
1859 std.mem.copy(u8, &raw_buffers[0], "foobar");1859 raw_buffers[0][0.."foobar".len].* = "foobar".*;
18601860
1861 var buffers = [2]os.iovec{1861 var buffers = [2]os.iovec{
1862 .{ .iov_base = &raw_buffers[0], .iov_len = raw_buffers[0].len },1862 .{ .iov_base = &raw_buffers[0], .iov_len = raw_buffers[0].len },
lib/std/os/linux/tls.zig+1-1
...@@ -287,7 +287,7 @@ pub fn prepareTLS(area: []u8) usize {...@@ -287,7 +287,7 @@ pub fn prepareTLS(area: []u8) usize {
287 .VariantII => area.ptr + tls_image.tcb_offset,287 .VariantII => area.ptr + tls_image.tcb_offset,
288 };288 };
289 // Copy the data289 // Copy the data
290 mem.copy(u8, area[tls_image.data_offset..], tls_image.init_data);290 @memcpy(area[tls_image.data_offset..][0..tls_image.init_data.len], tls_image.init_data);
291291
292 // Return the corrected value (if needed) for the tp register.292 // Return the corrected value (if needed) for the tp register.
293 // Overflow here is not a problem, the pointer arithmetic involving the tp293 // Overflow here is not a problem, the pointer arithmetic involving the tp
lib/std/os/uefi/protocols/device_path_protocol.zig+1-1
...@@ -48,7 +48,7 @@ pub const DevicePathProtocol = extern struct {...@@ -48,7 +48,7 @@ pub const DevicePathProtocol = extern struct {
48 // DevicePathProtocol for the extra node before the end48 // DevicePathProtocol for the extra node before the end
49 var buf = try allocator.alloc(u8, path_size + 2 * (path.len + 1) + @sizeOf(DevicePathProtocol));49 var buf = try allocator.alloc(u8, path_size + 2 * (path.len + 1) + @sizeOf(DevicePathProtocol));
5050
51 mem.copy(u8, buf, @ptrCast([*]const u8, self)[0..path_size]);51 @memcpy(buf[0..path_size.len], @ptrCast([*]const u8, self)[0..path_size]);
5252
53 // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer53 // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer
54 // as the end node itself is 4 bytes (type: u8 + subtype: u8 + length: u16).54 // as the end node itself is 4 bytes (type: u8 + subtype: u8 + length: u16).
lib/std/os/windows.zig+7-7
...@@ -754,7 +754,7 @@ pub fn CreateSymbolicLink(...@@ -754,7 +754,7 @@ pub fn CreateSymbolicLink(
754 .Flags = if (dir) |_| SYMLINK_FLAG_RELATIVE else 0,754 .Flags = if (dir) |_| SYMLINK_FLAG_RELATIVE else 0,
755 };755 };
756756
757 std.mem.copy(u8, buffer[0..], std.mem.asBytes(&symlink_data));757 @memcpy(buffer[0..@sizeOf(SYMLINK_DATA)], std.mem.asBytes(&symlink_data));
758 @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));758 @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));
759 const paths_start = @sizeOf(SYMLINK_DATA) + target_path.len * 2;759 const paths_start = @sizeOf(SYMLINK_DATA) + target_path.len * 2;
760 @memcpy(buffer[paths_start..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));760 @memcpy(buffer[paths_start..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));
...@@ -1208,8 +1208,8 @@ pub fn GetFinalPathNameByHandle(...@@ -1208,8 +1208,8 @@ pub fn GetFinalPathNameByHandle(
12081208
1209 if (out_buffer.len < drive_letter.len + file_name_u16.len) return error.NameTooLong;1209 if (out_buffer.len < drive_letter.len + file_name_u16.len) return error.NameTooLong;
12101210
1211 mem.copy(u16, out_buffer, drive_letter);1211 @memcpy(out_buffer[0..drive_letter.len], drive_letter);
1212 mem.copy(u16, out_buffer[drive_letter.len..], file_name_u16);1212 @memcpy(out_buffer[drive_letter.len..][0..file_name_u16.len], file_name_u16);
1213 const total_len = drive_letter.len + file_name_u16.len;1213 const total_len = drive_letter.len + file_name_u16.len;
12141214
1215 // Validate that DOS does not contain any spurious nul bytes.1215 // Validate that DOS does not contain any spurious nul bytes.
...@@ -2012,7 +2012,7 @@ pub fn sliceToPrefixedFileW(s: []const u8) !PathSpace {...@@ -2012,7 +2012,7 @@ pub fn sliceToPrefixedFileW(s: []const u8) !PathSpace {
2012 }2012 }
2013 const prefix_u16 = [_]u16{ '\\', '?', '?', '\\' };2013 const prefix_u16 = [_]u16{ '\\', '?', '?', '\\' };
2014 const start_index = if (prefix_index > 0 or !std.fs.path.isAbsolute(s)) 0 else blk: {2014 const start_index = if (prefix_index > 0 or !std.fs.path.isAbsolute(s)) 0 else blk: {
2015 mem.copy(u16, path_space.data[0..], prefix_u16[0..]);2015 path_space.data[0..prefix_u16.len].* = prefix_u16;
2016 break :blk prefix_u16.len;2016 break :blk prefix_u16.len;
2017 };2017 };
2018 path_space.len = start_index + try std.unicode.utf8ToUtf16Le(path_space.data[start_index..], s);2018 path_space.len = start_index + try std.unicode.utf8ToUtf16Le(path_space.data[start_index..], s);
...@@ -2025,7 +2025,7 @@ pub fn sliceToPrefixedFileW(s: []const u8) !PathSpace {...@@ -2025,7 +2025,7 @@ pub fn sliceToPrefixedFileW(s: []const u8) !PathSpace {
2025 std.debug.assert(temp_path.len == path_space.len);2025 std.debug.assert(temp_path.len == path_space.len);
2026 temp_path.data[path_space.len] = 0;2026 temp_path.data[path_space.len] = 0;
2027 path_space.len = prefix_u16.len + try getFullPathNameW(&temp_path.data, path_space.data[prefix_u16.len..]);2027 path_space.len = prefix_u16.len + try getFullPathNameW(&temp_path.data, path_space.data[prefix_u16.len..]);
2028 mem.copy(u16, &path_space.data, &prefix_u16);2028 path_space.data[0..prefix_u16.len].* = prefix_u16;
2029 std.debug.assert(path_space.data[path_space.len] == 0);2029 std.debug.assert(path_space.data[path_space.len] == 0);
2030 return path_space;2030 return path_space;
2031 }2031 }
...@@ -2053,12 +2053,12 @@ pub fn wToPrefixedFileW(s: []const u16) !PathSpace {...@@ -2053,12 +2053,12 @@ pub fn wToPrefixedFileW(s: []const u16) !PathSpace {
20532053
2054 const start_index = if (mem.startsWith(u16, s, &[_]u16{ '\\', '?' })) 0 else blk: {2054 const start_index = if (mem.startsWith(u16, s, &[_]u16{ '\\', '?' })) 0 else blk: {
2055 const prefix = [_]u16{ '\\', '?', '?', '\\' };2055 const prefix = [_]u16{ '\\', '?', '?', '\\' };
2056 mem.copy(u16, path_space.data[0..], &prefix);2056 path_space.data[0..prefix.len].* = prefix;
2057 break :blk prefix.len;2057 break :blk prefix.len;
2058 };2058 };
2059 path_space.len = start_index + s.len;2059 path_space.len = start_index + s.len;
2060 if (path_space.len > path_space.data.len) return error.NameTooLong;2060 if (path_space.len > path_space.data.len) return error.NameTooLong;
2061 mem.copy(u16, path_space.data[start_index..], s);2061 @memcpy(path_space.data[start_index..][0..s.len], s);
2062 // > File I/O functions in the Windows API convert "/" to "\" as part of2062 // > File I/O functions in the Windows API convert "/" to "\" as part of
2063 // > converting the name to an NT-style name, except when using the "\\?\"2063 // > converting the name to an NT-style name, except when using the "\\?\"
2064 // > prefix as detailed in the following sections.2064 // > prefix as detailed in the following sections.
lib/std/tar.zig+8-6
...@@ -55,9 +55,9 @@ pub const Header = struct {...@@ -55,9 +55,9 @@ pub const Header = struct {
55 const p = prefix(header);55 const p = prefix(header);
56 if (p.len == 0)56 if (p.len == 0)
57 return n;57 return n;
58 std.mem.copy(u8, buffer[0..p.len], p);58 @memcpy(buffer[0..p.len], p);
59 buffer[p.len] = '/';59 buffer[p.len] = '/';
60 std.mem.copy(u8, buffer[p.len + 1 ..], n);60 @memcpy(buffer[p.len + 1 ..][0..n.len], n);
61 return buffer[0 .. p.len + 1 + n.len];61 return buffer[0 .. p.len + 1 + n.len];
62 }62 }
6363
...@@ -101,8 +101,9 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -101,8 +101,9 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
101 var end: usize = 0;101 var end: usize = 0;
102 header: while (true) {102 header: while (true) {
103 if (buffer.len - start < 1024) {103 if (buffer.len - start < 1024) {
104 std.mem.copy(u8, &buffer, buffer[start..end]);104 const dest_end = end - start;
105 end -= start;105 @memcpy(buffer[0..dest_end], buffer[start..end]);
106 end = dest_end;
106 start = 0;107 start = 0;
107 }108 }
108 const ask_header = @min(buffer.len - end, 1024 -| (end - start));109 const ask_header = @min(buffer.len - end, 1024 -| (end - start));
...@@ -138,8 +139,9 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -138,8 +139,9 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
138 var file_off: usize = 0;139 var file_off: usize = 0;
139 while (true) {140 while (true) {
140 if (buffer.len - start < 1024) {141 if (buffer.len - start < 1024) {
141 std.mem.copy(u8, &buffer, buffer[start..end]);142 const dest_end = end - start;
142 end -= start;143 @memcpy(buffer[0..dest_end], buffer[start..end]);
144 end = dest_end;
143 start = 0;145 start = 0;
144 }146 }
145 // Ask for the rounded up file size + 512 for the next header.147 // Ask for the rounded up file size + 512 for the next header.