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 {
765765 const num_masks = numMasks(self.bit_length);
766766 var copy = Self{};
767767 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]);
769769 return copy;
770770 }
771771
lib/std/compress/deflate.zig+14
......@@ -12,6 +12,20 @@ pub const Decompressor = inflate.Decompressor;
1212pub const compressor = deflate.compressor;
1313pub 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
1529test {
1630 _ = @import("deflate/token.zig");
1731 _ = @import("deflate/bits_utils.zig");
lib/std/compress/deflate/compressor.zig+6-7
......@@ -10,7 +10,6 @@ const Allocator = std.mem.Allocator;
1010const deflate_const = @import("deflate_const.zig");
1111const fast = @import("deflate_fast.zig");
1212const hm_bw = @import("huffman_bit_writer.zig");
13const mu = @import("mem_utils.zig");
1413const token = @import("token.zig");
1514
1615pub const Compression = enum(i5) {
......@@ -296,7 +295,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
296295 fn fillDeflate(self: *Self, b: []const u8) u32 {
297296 if (self.index >= 2 * window_size - (min_match_length + max_match_length)) {
298297 // 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]);
300299 self.index -= window_size;
301300 self.window_end -= window_size;
302301 if (self.block_start >= window_size) {
......@@ -328,7 +327,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
328327 }
329328 }
330329 }
331 var n = mu.copy(self.window[self.window_end..], b);
330 const n = std.compress.deflate.copy(self.window[self.window_end..], b);
332331 self.window_end += n;
333332 return @intCast(u32, n);
334333 }
......@@ -369,7 +368,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
369368 b = b[b.len - window_size ..];
370369 }
371370 // Add all to window.
372 mem.copy(u8, self.window, b);
371 @memcpy(self.window[0..b.len], b);
373372 var n = b.len;
374373
375374 // Calculate 256 hashes at the time (more L1 cache hits)
......@@ -706,7 +705,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
706705 }
707706
708707 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);
710709 self.window_end += n;
711710 return @intCast(u32, n);
712711 }
......@@ -1091,8 +1090,8 @@ test "bulkHash4" {
10911090 // double the test data
10921091 var out = try testing.allocator.alloc(u8, x.out.len * 2);
10931092 defer testing.allocator.free(out);
1094 mem.copy(u8, out[0..x.out.len], x.out);
1095 mem.copy(u8, out[x.out.len..], x.out);
1093 @memcpy(out[0..x.out.len], x.out);
1094 @memcpy(out[x.out.len..], x.out);
10961095
10971096 var j: usize = 4;
10981097 while (j < out.len) : (j += 1) {
lib/std/compress/deflate/decompressor.zig+1-2
......@@ -9,7 +9,6 @@ const ArrayList = std.ArrayList;
99const bu = @import("bits_utils.zig");
1010const ddec = @import("dict_decoder.zig");
1111const deflate_const = @import("deflate_const.zig");
12const mu = @import("mem_utils.zig");
1312
1413const max_match_offset = deflate_const.max_match_offset;
1514const end_block_marker = deflate_const.end_block_marker;
......@@ -451,7 +450,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
451450 pub fn read(self: *Self, output: []u8) Error!usize {
452451 while (true) {
453452 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);
455454 self.to_read = self.to_read[n..];
456455 if (self.to_read.len == 0 and
457456 self.err != null)
lib/std/compress/deflate/deflate_fast.zig+1-1
......@@ -237,7 +237,7 @@ pub const DeflateFast = struct {
237237 }
238238 self.cur += @intCast(i32, src.len);
239239 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);
241241 return;
242242 }
243243
lib/std/compress/deflate/deflate_fast_test.zig+5-5
......@@ -123,13 +123,13 @@ test "best speed max match offset" {
123123 var src = try testing.allocator.alloc(u8, src_len);
124124 defer testing.allocator.free(src);
125125
126 mem.copy(u8, src, abc);
126 @memcpy(src[0..abc.len], abc);
127127 if (!do_match_before) {
128 var src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));
129 mem.copy(u8, src[src_offset..], xyz);
128 const src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));
129 @memcpy(src[src_offset..][0..xyz.len], xyz);
130130 }
131 var src_offset: usize = @intCast(usize, offset);
132 mem.copy(u8, src[src_offset..], abc);
131 const src_offset: usize = @intCast(usize, offset);
132 @memcpy(src[src_offset..][0..abc.len], abc);
133133
134134 var compressed = ArrayList(u8).init(testing.allocator);
135135 defer compressed.deinit();
lib/std/compress/deflate/dict_decoder.zig+7-3
......@@ -47,7 +47,8 @@ pub const DictDecoder = struct {
4747 self.wr_pos = 0;
4848
4949 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);
5152 self.wr_pos = @intCast(u32, dict.?.len);
5253 }
5354
......@@ -103,12 +104,15 @@ pub const DictDecoder = struct {
103104 self.wr_pos += 1;
104105 }
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`.
106110 fn copy(dst: []u8, src: []const u8) u32 {
107111 if (src.len > dst.len) {
108 mem.copy(u8, dst, src[0..dst.len]);
112 mem.copyForwards(u8, dst, src[0..dst.len]);
109113 return @intCast(u32, dst.len);
110114 }
111 mem.copy(u8, dst, src);
115 mem.copyForwards(u8, dst[0..src.len], src);
112116 return @intCast(u32, src.len);
113117 }
114118
lib/std/compress/deflate/huffman_code.zig+1-1
......@@ -202,7 +202,7 @@ pub const HuffmanEncoder = struct {
202202 // more values in the level below
203203 l.last_freq = l.next_pair_freq;
204204 // 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]);
206206 levels[l.level - 1].needed = 2;
207207 }
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 {
5959 while (true) {
6060 if (self.to_read.items.len > 0) {
6161 const input = self.to_read.items;
62 const n = std.math.min(input.len, output.len);
63 std.mem.copy(u8, output[0..n], input[0..n]);
64 std.mem.copy(u8, input, input[n..]);
62 const n = @min(input.len, output.len);
63 @memcpy(output[0..n], input[0..n]);
64 std.mem.copyForwards(u8, input, input[n..]);
6565 self.to_read.shrinkRetainingCapacity(input.len - n);
6666 if (self.to_read.items.len == 0 and self.err != null) {
6767 if (self.err.? == DecodeError.EndOfStreamWithNoError) {
lib/std/crypto/argon2.zig+6-6
......@@ -149,7 +149,7 @@ fn blake2bLong(out: []u8, in: []const u8) void {
149149 h.update(&outlen_bytes);
150150 h.update(in);
151151 h.final(&out_buf);
152 mem.copy(u8, out, out_buf[0..out.len]);
152 @memcpy(out, out_buf[0..out.len]);
153153 return;
154154 }
155155
......@@ -158,19 +158,19 @@ fn blake2bLong(out: []u8, in: []const u8) void {
158158 h.update(in);
159159 h.final(&out_buf);
160160 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].*;
162162 out_slice = out_slice[H.digest_length / 2 ..];
163163
164164 var in_buf: [H.digest_length]u8 = undefined;
165165 while (out_slice.len > H.digest_length) {
166 mem.copy(u8, &in_buf, &out_buf);
166 in_buf = out_buf;
167167 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].*;
169169 out_slice = out_slice[H.digest_length / 2 ..];
170170 }
171 mem.copy(u8, &in_buf, &out_buf);
171 in_buf = out_buf;
172172 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]);
174174}
175175
176176fn initBlocks(
lib/std/crypto/kyber_d00.zig+13-17
......@@ -323,9 +323,9 @@ fn Kyber(comptime p: Params) type {
323323 s += InnerSk.bytes_length;
324324 ret.pk = InnerPk.fromBytes(buf[s .. s + InnerPk.bytes_length]);
325325 s += InnerPk.bytes_length;
326 mem.copy(u8, &ret.hpk, buf[s .. s + h_length]);
326 ret.hpk = buf[s..][0..h_length].*;
327327 s += h_length;
328 mem.copy(u8, &ret.z, buf[s .. s + shared_length]);
328 ret.z = buf[s..][0..shared_length].*;
329329 return ret;
330330 }
331331 };
......@@ -345,7 +345,7 @@ fn Kyber(comptime p: Params) type {
345345 break :sk random_seed;
346346 };
347347 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
350350 // Generate inner key
351351 innerKeyFromSeed(
......@@ -356,7 +356,7 @@ fn Kyber(comptime p: Params) type {
356356 ret.secret_key.pk = ret.public_key.pk;
357357
358358 // 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
361361 // Compute H(pk)
362362 var h = sha3.Sha3_256.init(.{});
......@@ -418,7 +418,7 @@ fn Kyber(comptime p: Params) type {
418418 fn fromBytes(buf: *const [bytes_length]u8) InnerPk {
419419 var ret: InnerPk = undefined;
420420 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].*;
422422 ret.aT = M.uniform(ret.rho, true);
423423 return ret;
424424 }
......@@ -459,7 +459,7 @@ fn Kyber(comptime p: Params) type {
459459 var h = sha3.Sha3_512.init(.{});
460460 h.update(&seed);
461461 h.final(&expanded_seed);
462 mem.copy(u8, &pk.rho, expanded_seed[0..32]);
462 pk.rho = expanded_seed[0..32].*;
463463 const sigma = expanded_seed[32..64];
464464 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 {
13811381 const cs = comptime Poly.compressedSize(d);
13821382 var ret: [compressedSize(d)]u8 = undefined;
13831383 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);
13851385 }
13861386 return ret;
13871387 }
......@@ -1399,11 +1399,7 @@ fn Vec(comptime K: u8) type {
13991399 fn toBytes(v: Self) [bytes_length]u8 {
14001400 var ret: [bytes_length]u8 = undefined;
14011401 inline for (0..K) |i| {
1402 mem.copy(
1403 u8,
1404 ret[i * Poly.bytes_length .. (i + 1) * Poly.bytes_length],
1405 &v.ps[i].toBytes(),
1406 );
1402 ret[i * Poly.bytes_length .. (i + 1) * Poly.bytes_length].* = v.ps[i].toBytes();
14071403 }
14081404 return ret;
14091405 }
......@@ -1742,15 +1738,15 @@ const NistDRBG = struct {
17421738 g.incV();
17431739 var block: [16]u8 = undefined;
17441740 ctx.encrypt(&block, &g.v);
1745 mem.copy(u8, buf[i * 16 .. (i + 1) * 16], &block);
1741 buf[i * 16 ..][0..16].* = block;
17461742 }
17471743 if (pd) |p| {
17481744 for (&buf, p) |*b, x| {
17491745 b.* ^= x;
17501746 }
17511747 }
1752 mem.copy(u8, &g.key, buf[0..32]);
1753 mem.copy(u8, &g.v, buf[32..48]);
1748 g.key = buf[0..32].*;
1749 g.v = buf[32..48].*;
17541750 }
17551751
17561752 // randombytes.
......@@ -1763,10 +1759,10 @@ const NistDRBG = struct {
17631759 g.incV();
17641760 ctx.encrypt(&block, &g.v);
17651761 if (dst.len < 16) {
1766 mem.copy(u8, dst, block[0..dst.len]);
1762 @memcpy(dst, block[0..dst.len]);
17671763 break;
17681764 }
1769 mem.copy(u8, dst, &block);
1765 dst[0..block.len].* = block;
17701766 dst = dst[16..dst.len];
17711767 }
17721768 g.update(null);
lib/std/crypto/scrypt.zig+3-3
......@@ -27,7 +27,7 @@ const max_salt_len = 64;
2727const max_hash_len = 64;
2828
2929fn 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]);
3131}
3232
3333fn blockXor(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {
......@@ -242,7 +242,7 @@ const crypt_format = struct {
242242 pub fn fromSlice(slice: []const u8) EncodingError!Self {
243243 if (slice.len > capacity) return EncodingError.NoSpaceLeft;
244244 var bin_value: Self = undefined;
245 mem.copy(u8, &bin_value.buf, slice);
245 @memcpy(bin_value.buf[0..slice.len], slice);
246246 bin_value.len = slice.len;
247247 return bin_value;
248248 }
......@@ -314,7 +314,7 @@ const crypt_format = struct {
314314
315315 fn serializeTo(params: anytype, out: anytype) !void {
316316 var header: [14]u8 = undefined;
317 mem.copy(u8, header[0..3], prefix);
317 header[0..3].* = prefix.*;
318318 Codec.intEncode(header[3..4], params.ln);
319319 Codec.intEncode(header[4..9], params.r);
320320 Codec.intEncode(header[9..14], params.p);
lib/std/crypto/tls.zig+2-2
......@@ -312,11 +312,11 @@ pub fn hkdfExpandLabel(
312312 buf[2] = @intCast(u8, tls13.len + label.len);
313313 buf[3..][0..tls13.len].* = tls13.*;
314314 var i: usize = 3 + tls13.len;
315 mem.copy(u8, buf[i..], label);
315 @memcpy(buf[i..][0..label.len], label);
316316 i += label.len;
317317 buf[i] = @intCast(u8, context.len);
318318 i += 1;
319 mem.copy(u8, buf[i..], context);
319 @memcpy(buf[i..][0..context.len], context);
320320 i += context.len;
321321
322322 var result: [len]u8 = undefined;
lib/std/debug.zig+2-2
......@@ -309,8 +309,8 @@ pub fn panicExtra(
309309 // error being part of the @panic stack trace (but that error should
310310 // only happen rarely)
311311 const msg = std.fmt.bufPrint(buf[0..size], format, args) catch |err| switch (err) {
312 std.fmt.BufPrintError.NoSpaceLeft => blk: {
313 std.mem.copy(u8, buf[size..], trunc_msg);
312 error.NoSpaceLeft => blk: {
313 @memcpy(buf[size..], trunc_msg);
314314 break :blk &buf;
315315 },
316316 };
lib/std/fs.zig+19-15
......@@ -106,7 +106,7 @@ pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path:
106106 var rand_buf: [AtomicFile.RANDOM_BYTES]u8 = undefined;
107107 const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64_encoder.calcSize(rand_buf.len));
108108 defer allocator.free(tmp_path);
109 mem.copy(u8, tmp_path[0..], dirname);
109 @memcpy(tmp_path[0..dirname.len], dirname);
110110 tmp_path[dirname.len] = path.sep;
111111 while (true) {
112112 crypto.random.bytes(rand_buf[0..]);
......@@ -1541,9 +1541,9 @@ pub const Dir = struct {
15411541 return error.NameTooLong;
15421542 }
15431543
1544 mem.copy(u8, out_buffer, out_path);
1545
1546 return out_buffer[0..out_path.len];
1544 const result = out_buffer[0..out_path.len];
1545 @memcpy(result, out_path);
1546 return result;
15471547 }
15481548
15491549 /// Windows-only. Same as `Dir.realpath` except `pathname` is WTF16 encoded.
......@@ -1593,9 +1593,9 @@ pub const Dir = struct {
15931593 return error.NameTooLong;
15941594 }
15951595
1596 mem.copy(u8, out_buffer, out_path);
1597
1598 return out_buffer[0..out_path.len];
1596 const result = out_buffer[0..out_path.len];
1597 @memcpy(result, out_path);
1598 return result;
15991599 }
16001600
16011601 /// Same as `Dir.realpath` except caller must free the returned memory.
......@@ -2346,8 +2346,9 @@ pub const Dir = struct {
23462346 if (cleanup_dir_parent) |*d| d.close();
23472347 cleanup_dir_parent = iterable_dir;
23482348 iterable_dir = new_dir;
2349 mem.copy(u8, &dir_name_buf, entry.name);
2350 dir_name = dir_name_buf[0..entry.name.len];
2349 const result = dir_name_buf[0..entry.name.len];
2350 @memcpy(result, entry.name);
2351 dir_name = result;
23512352 continue :scan_dir;
23522353 } else {
23532354 if (iterable_dir.dir.deleteFile(entry.name)) {
......@@ -2974,8 +2975,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
29742975 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;
29752976 const real_path = try std.os.realpathZ(&symlink_path_buf, &real_path_buf);
29762977 if (real_path.len > out_buffer.len) return error.NameTooLong;
2977 std.mem.copy(u8, out_buffer, real_path);
2978 return out_buffer[0..real_path.len];
2978 const result = out_buffer[0..real_path.len];
2979 @memcpy(result, real_path);
2980 return result;
29792981 }
29802982 switch (builtin.os.tag) {
29812983 .linux => return os.readlinkZ("/proc/self/exe", out_buffer),
......@@ -3014,8 +3016,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
30143016 const real_path = try os.realpathZ(os.argv[0], &real_path_buf);
30153017 if (real_path.len > out_buffer.len)
30163018 return error.NameTooLong;
3017 mem.copy(u8, out_buffer, real_path);
3018 return out_buffer[0..real_path.len];
3019 const result = out_buffer[0..real_path.len];
3020 @memcpy(result, real_path);
3021 return result;
30193022 } else if (argv0.len != 0) {
30203023 // argv[0] is not empty (and not a path): search it inside PATH
30213024 const PATH = std.os.getenvZ("PATH") orelse return error.FileNotFound;
......@@ -3032,8 +3035,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
30323035 // found a file, and hope it is the right file
30333036 if (real_path.len > out_buffer.len)
30343037 return error.NameTooLong;
3035 mem.copy(u8, out_buffer, real_path);
3036 return out_buffer[0..real_path.len];
3038 const result = out_buffer[0..real_path.len];
3039 @memcpy(result, real_path);
3040 return result;
30373041 } else |_| continue;
30383042 }
30393043 }
lib/std/http/Client.zig+1-1
......@@ -284,7 +284,7 @@ pub const BufferedConnection = struct {
284284 if (available > 0) {
285285 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]);
288288 out_index += can_read;
289289 bconn.start += can_read;
290290
lib/std/http/Headers.zig+2-1
......@@ -38,7 +38,8 @@ pub const Field = struct {
3838
3939 pub fn modify(entry: *Field, allocator: Allocator, new_value: []const u8) !void {
4040 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);
4243 } else {
4344 allocator.free(entry.value);
4445
lib/std/http/Server.zig+1-1
......@@ -128,7 +128,7 @@ pub const BufferedConnection = struct {
128128 if (available > 0) {
129129 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]);
132132 out_index += can_read;
133133 bconn.start += can_read;
134134
lib/std/http/protocol.zig+1-1
......@@ -654,7 +654,7 @@ const MockBufferedConnection = struct {
654654 if (available > 0) {
655655 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]);
658658 out_index += can_read;
659659 bconn.start += can_read;
660660
lib/std/net.zig+11-11
......@@ -107,7 +107,7 @@ pub const Address = extern union {
107107 if (path.len + 1 > sock_addr.path.len) return error.NameTooLong;
108108
109109 @memset(&sock_addr.path, 0);
110 mem.copy(u8, &sock_addr.path, path);
110 @memcpy(sock_addr.path[0..path.len], path);
111111
112112 return Address{ .un = sock_addr };
113113 }
......@@ -416,7 +416,7 @@ pub const Ip6Address = extern struct {
416416 index += 1;
417417 ip_slice[index] = @truncate(u8, x);
418418 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]);
420420 return result;
421421 }
422422 }
......@@ -550,7 +550,7 @@ pub const Ip6Address = extern struct {
550550 index += 1;
551551 ip_slice[index] = @truncate(u8, x);
552552 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]);
554554 return result;
555555 }
556556 }
......@@ -662,7 +662,7 @@ fn if_nametoindex(name: []const u8) !u32 {
662662 var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
663663 defer os.closeSocket(sockfd);
664664
665 std.mem.copy(u8, &ifr.ifrn.name, name);
665 @memcpy(ifr.ifrn.name[0..name.len], name);
666666 ifr.ifrn.name[name.len] = 0;
667667
668668 // TODO investigate if this needs to be integrated with evented I/O.
......@@ -676,7 +676,7 @@ fn if_nametoindex(name: []const u8) !u32 {
676676 return error.NameTooLong;
677677
678678 var if_name: [os.IFNAMESIZE:0]u8 = undefined;
679 std.mem.copy(u8, &if_name, name);
679 @memcpy(if_name[0..name.len], name);
680680 if_name[name.len] = 0;
681681 const if_slice = if_name[0..name.len :0];
682682 const index = os.system.if_nametoindex(if_slice);
......@@ -1041,14 +1041,14 @@ fn linuxLookupName(
10411041 var salen: os.socklen_t = undefined;
10421042 var dalen: os.socklen_t = undefined;
10431043 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;
10451045 da = @ptrCast(*os.sockaddr, &da6);
10461046 dalen = @sizeOf(os.sockaddr.in6);
10471047 sa = @ptrCast(*os.sockaddr, &sa6);
10481048 salen = @sizeOf(os.sockaddr.in6);
10491049 } else {
1050 mem.copy(u8, &sa6.addr, "\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");
1050 sa6.addr[0..12].* = "\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".*;
10521052 mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);
10531053 da4.addr = addr.addr.in.sa.addr;
10541054 da = @ptrCast(*os.sockaddr, &da4);
......@@ -1343,7 +1343,7 @@ fn linuxLookupNameFromDnsSearch(
13431343 // name is not a CNAME record) and serves as a buffer for passing
13441344 // the full requested name to name_from_dns.
13451345 try canon.resize(canon_name.len);
1346 mem.copy(u8, canon.items, canon_name);
1346 @memcpy(canon.items, canon_name);
13471347 try canon.append('.');
13481348
13491349 var tok_it = mem.tokenize(u8, search, " \t");
......@@ -1567,7 +1567,7 @@ fn resMSendRc(
15671567 for (0..ns.len) |i| {
15681568 if (ns[i].any.family != os.AF.INET) continue;
15691569 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".*;
15711571 ns[i].any.family = os.AF.INET6;
15721572 ns[i].in6.sa.flowinfo = 0;
15731573 ns[i].in6.sa.scope_id = 0;
......@@ -1665,7 +1665,7 @@ fn resMSendRc(
16651665 if (i == next) {
16661666 while (next < queries.len and answers[next].len != 0) : (next += 1) {}
16671667 } 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]);
16691669 }
16701670
16711671 if (next == queries.len) break :outer;
lib/std/os/linux/bpf.zig+1-1
......@@ -1631,7 +1631,7 @@ test "map lookup, update, and delete" {
16311631 const status = try map_get_next_key(map, &lookup_key, &next_key);
16321632 try expectEqual(status, true);
16331633 try expectEqual(next_key, key);
1634 std.mem.copy(u8, &lookup_key, &next_key);
1634 lookup_key = next_key;
16351635 const status2 = try map_get_next_key(map, &lookup_key, &next_key);
16361636 try expectEqual(status2, false);
16371637
lib/std/os/linux/io_uring.zig+1-1
......@@ -1856,7 +1856,7 @@ test "write_fixed/read_fixed" {
18561856 var raw_buffers: [2][11]u8 = undefined;
18571857 // First buffer will be written to the file.
18581858 @memset(&raw_buffers[0], 'z');
1859 std.mem.copy(u8, &raw_buffers[0], "foobar");
1859 raw_buffers[0][0.."foobar".len].* = "foobar".*;
18601860
18611861 var buffers = [2]os.iovec{
18621862 .{ .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 {
287287 .VariantII => area.ptr + tls_image.tcb_offset,
288288 };
289289 // 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
292292 // Return the corrected value (if needed) for the tp register.
293293 // 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 {
4848 // DevicePathProtocol for the extra node before the end
4949 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
5353 // Pointer to the copy of the end node of the current chain, which is - 4 from the buffer
5454 // 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(
754754 .Flags = if (dir) |_| SYMLINK_FLAG_RELATIVE else 0,
755755 };
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));
758758 @memcpy(buffer[@sizeOf(SYMLINK_DATA)..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));
759759 const paths_start = @sizeOf(SYMLINK_DATA) + target_path.len * 2;
760760 @memcpy(buffer[paths_start..][0 .. target_path.len * 2], @ptrCast([*]const u8, target_path));
......@@ -1208,8 +1208,8 @@ pub fn GetFinalPathNameByHandle(
12081208
12091209 if (out_buffer.len < drive_letter.len + file_name_u16.len) return error.NameTooLong;
12101210
1211 mem.copy(u16, out_buffer, drive_letter);
1212 mem.copy(u16, out_buffer[drive_letter.len..], file_name_u16);
1211 @memcpy(out_buffer[0..drive_letter.len], drive_letter);
1212 @memcpy(out_buffer[drive_letter.len..][0..file_name_u16.len], file_name_u16);
12131213 const total_len = drive_letter.len + file_name_u16.len;
12141214
12151215 // Validate that DOS does not contain any spurious nul bytes.
......@@ -2012,7 +2012,7 @@ pub fn sliceToPrefixedFileW(s: []const u8) !PathSpace {
20122012 }
20132013 const prefix_u16 = [_]u16{ '\\', '?', '?', '\\' };
20142014 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;
20162016 break :blk prefix_u16.len;
20172017 };
20182018 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 {
20252025 std.debug.assert(temp_path.len == path_space.len);
20262026 temp_path.data[path_space.len] = 0;
20272027 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;
20292029 std.debug.assert(path_space.data[path_space.len] == 0);
20302030 return path_space;
20312031 }
......@@ -2053,12 +2053,12 @@ pub fn wToPrefixedFileW(s: []const u16) !PathSpace {
20532053
20542054 const start_index = if (mem.startsWith(u16, s, &[_]u16{ '\\', '?' })) 0 else blk: {
20552055 const prefix = [_]u16{ '\\', '?', '?', '\\' };
2056 mem.copy(u16, path_space.data[0..], &prefix);
2056 path_space.data[0..prefix.len].* = prefix;
20572057 break :blk prefix.len;
20582058 };
20592059 path_space.len = start_index + s.len;
20602060 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);
20622062 // > File I/O functions in the Windows API convert "/" to "\" as part of
20632063 // > converting the name to an NT-style name, except when using the "\\?\"
20642064 // > prefix as detailed in the following sections.
lib/std/tar.zig+8-6
......@@ -55,9 +55,9 @@ pub const Header = struct {
5555 const p = prefix(header);
5656 if (p.len == 0)
5757 return n;
58 std.mem.copy(u8, buffer[0..p.len], p);
58 @memcpy(buffer[0..p.len], p);
5959 buffer[p.len] = '/';
60 std.mem.copy(u8, buffer[p.len + 1 ..], n);
60 @memcpy(buffer[p.len + 1 ..][0..n.len], n);
6161 return buffer[0 .. p.len + 1 + n.len];
6262 }
6363
......@@ -101,8 +101,9 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
101101 var end: usize = 0;
102102 header: while (true) {
103103 if (buffer.len - start < 1024) {
104 std.mem.copy(u8, &buffer, buffer[start..end]);
105 end -= start;
104 const dest_end = end - start;
105 @memcpy(buffer[0..dest_end], buffer[start..end]);
106 end = dest_end;
106107 start = 0;
107108 }
108109 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
138139 var file_off: usize = 0;
139140 while (true) {
140141 if (buffer.len - start < 1024) {
141 std.mem.copy(u8, &buffer, buffer[start..end]);
142 end -= start;
142 const dest_end = end - start;
143 @memcpy(buffer[0..dest_end], buffer[start..end]);
144 end = dest_end;
143145 start = 0;
144146 }
145147 // Ask for the rounded up file size + 512 for the next header.