Merge pull request #15481 from ziglang/use-mem-intrinsics

actually use the new memory intrinsics
This commit is contained in:
Andrew Kelley 2023-04-29 00:19:55 -07:00 committed by GitHub
commit d65b42e07c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
155 changed files with 1188 additions and 882 deletions

View File

@ -29,8 +29,8 @@ inline fn limb_set(x: []u32, i: usize, v: u32) void {
// Uses Knuth's Algorithm D, 4.3.1, p. 272.
fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
if (q) |q_| std.mem.set(u32, q_[0..], 0);
if (r) |r_| std.mem.set(u32, r_[0..], 0);
if (q) |q_| @memset(q_[0..], 0);
if (r) |r_| @memset(r_[0..], 0);
if (u.len == 0 or v.len == 0) return error.DivisionByZero;
@ -44,7 +44,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
}
if (n > m) {
if (r) |r_| std.mem.copy(u32, r_[0..], u[0..]);
if (r) |r_| @memcpy(r_[0..u.len], u);
return;
}

View File

@ -1693,10 +1693,10 @@ pub fn constructCMacro(allocator: Allocator, name: []const u8, value: ?[]const u
u8,
name.len + if (value) |value_slice| value_slice.len + 1 else 0,
) catch |err| if (err == error.OutOfMemory) @panic("Out of memory") else unreachable;
mem.copy(u8, macro, name);
@memcpy(macro[0..name.len], name);
if (value) |value_slice| {
macro[name.len] = '=';
mem.copy(u8, macro[name.len + 1 ..], value_slice);
@memcpy(macro[name.len + 1 ..][0..value_slice.len], value_slice);
}
return macro;
}

View File

@ -388,7 +388,7 @@ pub const Manifest = struct {
self.hash.hasher = hasher_init;
self.hash.hasher.update(&bin_digest);
mem.copy(u8, &manifest_file_path, &self.hex_digest);
@memcpy(manifest_file_path[0..self.hex_digest.len], &self.hex_digest);
manifest_file_path[hex_digest_len..][0..ext.len].* = ext.*;
if (self.files.items.len == 0) {

View File

@ -1139,7 +1139,7 @@ fn appendModuleArgs(
// We'll use this buffer to store the name we decide on
var buf = try b.allocator.alloc(u8, dep.name.len + 32);
// First, try just the exposed dependency name
std.mem.copy(u8, buf, dep.name);
@memcpy(buf[0..dep.name.len], dep.name);
var name = buf[0..dep.name.len];
var n: usize = 0;
while (names.contains(name)) {

View File

@ -822,9 +822,19 @@ fn runCommand(
},
},
.zig_test => {
const prefix: []const u8 = p: {
if (result.stdio.test_metadata) |tm| {
if (tm.next_index <= tm.names.len) {
const name = tm.testName(tm.next_index - 1);
break :p b.fmt("while executing test '{s}', ", .{name});
}
}
break :p "";
};
const expected_term: std.process.Child.Term = .{ .Exited = 0 };
if (!termMatches(expected_term, result.term)) {
return step.fail("the following command {} (expected {}):\n{s}", .{
return step.fail("{s}the following command {} (expected {}):\n{s}", .{
prefix,
fmtTerm(result.term),
fmtTerm(expected_term),
try Step.allocPrintCmd(arena, self.cwd, final_argv),
@ -832,8 +842,8 @@ fn runCommand(
}
if (!result.stdio.test_results.isSuccess()) {
return step.fail(
"the following test command failed:\n{s}",
.{try Step.allocPrintCmd(arena, self.cwd, final_argv)},
"{s}the following test command failed:\n{s}",
.{ prefix, try Step.allocPrintCmd(arena, self.cwd, final_argv) },
);
}
},
@ -922,6 +932,7 @@ const StdIoResult = struct {
stdout_null: bool,
stderr_null: bool,
test_results: Step.TestResults,
test_metadata: ?TestMetadata,
};
fn evalZigTest(
@ -1057,6 +1068,7 @@ fn evalZigTest(
.skip_count = skip_count,
.leak_count = leak_count,
},
.test_metadata = metadata,
};
}
@ -1172,6 +1184,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {
.stdout_null = stdout_null,
.stderr_null = stderr_null,
.test_results = .{},
.test_metadata = null,
};
}

View File

@ -374,7 +374,7 @@ fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: any
self.columns_written += self.output_buffer.len - end.*;
end.* = self.output_buffer.len;
const suffix = "... ";
std.mem.copy(u8, self.output_buffer[self.output_buffer.len - suffix.len ..], suffix);
@memcpy(self.output_buffer[self.output_buffer.len - suffix.len ..], suffix);
},
}
}

View File

@ -56,7 +56,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
const name_with_terminator = blk: {
var name_buf: [max_name_len:0]u8 = undefined;
std.mem.copy(u8, &name_buf, name);
@memcpy(name_buf[0..name.len], name);
name_buf[name.len] = 0;
break :blk name_buf[0..name.len :0];
};

View File

@ -578,9 +578,9 @@ pub fn ArrayHashMapUnmanaged(
self.entries.len = 0;
if (self.index_header) |header| {
switch (header.capacityIndexType()) {
.u8 => mem.set(Index(u8), header.indexes(u8), Index(u8).empty),
.u16 => mem.set(Index(u16), header.indexes(u16), Index(u16).empty),
.u32 => mem.set(Index(u32), header.indexes(u32), Index(u32).empty),
.u8 => @memset(header.indexes(u8), Index(u8).empty),
.u16 => @memset(header.indexes(u16), Index(u16).empty),
.u32 => @memset(header.indexes(u32), Index(u32).empty),
}
}
}

View File

@ -120,7 +120,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
}
const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
mem.copy(T, new_memory, self.items);
@memcpy(new_memory, self.items);
@memset(self.items, undefined);
self.clearAndFree();
return new_memory;
@ -170,7 +170,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
self.items.len += items.len;
mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);
mem.copy(T, self.items[i .. i + items.len], items);
@memcpy(self.items[i..][0..items.len], items);
}
/// 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 {
const range = self.items[start..after_range];
if (range.len == new_items.len)
mem.copy(T, range, new_items)
@memcpy(range[0..new_items.len], new_items)
else if (range.len < new_items.len) {
const first = new_items[0..range.len];
const rest = new_items[range.len..];
mem.copy(T, range, first);
@memcpy(range[0..first.len], first);
try self.insertSlice(after_range, rest);
} else {
mem.copy(T, range, new_items);
@memcpy(range[0..new_items.len], new_items);
const after_subrange = start + new_items.len;
for (self.items[after_range..], 0..) |item, i| {
@ -260,7 +260,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
const new_len = old_len + items.len;
assert(new_len <= self.capacity);
self.items.len = new_len;
mem.copy(T, self.items[old_len..], items);
@memcpy(self.items[old_len..][0..items.len], items);
}
/// Append an unaligned slice of items to the list. Allocates more
@ -306,18 +306,22 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
/// Append a value to the list `n` times.
/// Allocates more memory as necessary.
/// Invalidates pointers if additional memory is needed.
pub fn appendNTimes(self: *Self, value: T, n: usize) Allocator.Error!void {
/// The function is inline so that a comptime-known `value` parameter will
/// have a more optimal memset codegen in case it has a repeated byte pattern.
pub inline fn appendNTimes(self: *Self, value: T, n: usize) Allocator.Error!void {
const old_len = self.items.len;
try self.resize(self.items.len + n);
mem.set(T, self.items[old_len..self.items.len], value);
@memset(self.items[old_len..self.items.len], value);
}
/// Append a value to the list `n` times.
/// Asserts the capacity is enough. **Does not** invalidate pointers.
pub fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
/// The function is inline so that a comptime-known `value` parameter will
/// have a more optimal memset codegen in case it has a repeated byte pattern.
pub inline fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
const new_len = self.items.len + n;
assert(new_len <= self.capacity);
mem.set(T, self.items.ptr[self.items.len..new_len], value);
@memset(self.items.ptr[self.items.len..new_len], value);
self.items.len = new_len;
}
@ -397,7 +401,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
self.capacity = new_capacity;
} else {
const new_memory = try self.allocator.alignedAlloc(T, alignment, new_capacity);
mem.copy(T, new_memory, self.items);
@memcpy(new_memory[0..self.items.len], self.items);
self.allocator.free(old_memory);
self.items.ptr = new_memory.ptr;
self.capacity = new_memory.len;
@ -596,7 +600,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
}
const new_memory = try allocator.alignedAlloc(T, alignment, self.items.len);
mem.copy(T, new_memory, self.items);
@memcpy(new_memory, self.items);
@memset(self.items, undefined);
self.clearAndFree(allocator);
return new_memory;
@ -647,7 +651,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
self.items.len += items.len;
mem.copyBackwards(T, self.items[i + items.len .. self.items.len], self.items[i .. self.items.len - items.len]);
mem.copy(T, self.items[i .. i + items.len], items);
@memcpy(self.items[i..][0..items.len], items);
}
/// Replace range of elements `list[start..start+len]` with `new_items`
@ -716,7 +720,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
const new_len = old_len + items.len;
assert(new_len <= self.capacity);
self.items.len = new_len;
mem.copy(T, self.items[old_len..], items);
@memcpy(self.items[old_len..][0..items.len], items);
}
/// Append the slice of items to the list. Allocates more
@ -766,19 +770,23 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
/// Append a value to the list `n` times.
/// Allocates more memory as necessary.
/// Invalidates pointers if additional memory is needed.
pub fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) Allocator.Error!void {
/// The function is inline so that a comptime-known `value` parameter will
/// have a more optimal memset codegen in case it has a repeated byte pattern.
pub inline fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) Allocator.Error!void {
const old_len = self.items.len;
try self.resize(allocator, self.items.len + n);
mem.set(T, self.items[old_len..self.items.len], value);
@memset(self.items[old_len..self.items.len], value);
}
/// Append a value to the list `n` times.
/// **Does not** invalidate pointers.
/// Asserts the capacity is enough.
pub fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
/// The function is inline so that a comptime-known `value` parameter will
/// have a more optimal memset codegen in case it has a repeated byte pattern.
pub inline fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void {
const new_len = self.items.len + n;
assert(new_len <= self.capacity);
mem.set(T, self.items.ptr[self.items.len..new_len], value);
@memset(self.items.ptr[self.items.len..new_len], value);
self.items.len = new_len;
}
@ -815,7 +823,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
},
};
mem.copy(T, new_memory, self.items[0..new_len]);
@memcpy(new_memory, self.items[0..new_len]);
allocator.free(old_memory);
self.items = new_memory;
self.capacity = new_memory.len;
@ -877,7 +885,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
self.capacity = new_capacity;
} else {
const new_memory = try allocator.alignedAlloc(T, alignment, new_capacity);
mem.copy(T, new_memory, self.items);
@memcpy(new_memory[0..self.items.len], self.items);
allocator.free(old_memory);
self.items.ptr = new_memory.ptr;
self.capacity = new_memory.len;

View File

@ -309,11 +309,11 @@ test "base64 padding dest overflow" {
const input = "foo";
var expect: [128]u8 = undefined;
std.mem.set(u8, &expect, 0);
@memset(&expect, 0);
_ = url_safe.Encoder.encode(expect[0..url_safe.Encoder.calcSize(input.len)], input);
var got: [128]u8 = undefined;
std.mem.set(u8, &got, 0);
@memset(&got, 0);
_ = url_safe.Encoder.encode(&got, input);
try std.testing.expectEqualSlices(u8, &expect, &got);

View File

@ -738,7 +738,7 @@ pub const DynamicBitSetUnmanaged = struct {
// fill in any new masks
if (new_masks > old_masks) {
const fill_value = std.math.boolMask(MaskInt, fill);
std.mem.set(MaskInt, self.masks[old_masks..new_masks], fill_value);
@memset(self.masks[old_masks..new_masks], fill_value);
}
}
@ -765,7 +765,7 @@ pub const DynamicBitSetUnmanaged = struct {
const num_masks = numMasks(self.bit_length);
var copy = Self{};
try copy.resize(new_allocator, self.bit_length, false);
std.mem.copy(MaskInt, copy.masks[0..num_masks], self.masks[0..num_masks]);
@memcpy(copy.masks[0..num_masks], self.masks[0..num_masks]);
return copy;
}

View File

@ -73,7 +73,7 @@ pub fn BoundedArrayAligned(
/// Copy the content of an existing slice.
pub fn fromSlice(m: []const T) error{Overflow}!Self {
var list = try init(m.len);
std.mem.copy(T, list.slice(), m);
@memcpy(list.slice(), m);
return list;
}
@ -165,7 +165,7 @@ pub fn BoundedArrayAligned(
try self.ensureUnusedCapacity(items.len);
self.len += items.len;
mem.copyBackwards(T, self.slice()[i + items.len .. self.len], self.constSlice()[i .. self.len - items.len]);
mem.copy(T, self.slice()[i .. i + items.len], items);
@memcpy(self.slice()[i..][0..items.len], items);
}
/// Replace range of elements `slice[start..start+len]` with `new_items`.
@ -181,14 +181,14 @@ pub fn BoundedArrayAligned(
var range = self.slice()[start..after_range];
if (range.len == new_items.len) {
mem.copy(T, range, new_items);
@memcpy(range[0..new_items.len], new_items);
} else if (range.len < new_items.len) {
const first = new_items[0..range.len];
const rest = new_items[range.len..];
mem.copy(T, range, first);
@memcpy(range[0..first.len], first);
try self.insertSlice(after_range, rest);
} else {
mem.copy(T, range, new_items);
@memcpy(range[0..new_items.len], new_items);
const after_subrange = start + new_items.len;
for (self.constSlice()[after_range..], 0..) |item, i| {
self.slice()[after_subrange..][i] = item;
@ -243,9 +243,9 @@ pub fn BoundedArrayAligned(
/// Append the slice of items to the slice, asserting the capacity is already
/// enough to store the new items.
pub fn appendSliceAssumeCapacity(self: *Self, items: []const T) void {
const oldlen = self.len;
const old_len = self.len;
self.len += items.len;
mem.copy(T, self.slice()[oldlen..], items);
@memcpy(self.slice()[old_len..][0..items.len], items);
}
/// Append a value to the slice `n` times.
@ -253,7 +253,7 @@ pub fn BoundedArrayAligned(
pub fn appendNTimes(self: *Self, value: T, n: usize) error{Overflow}!void {
const old_len = self.len;
try self.resize(old_len + n);
mem.set(T, self.slice()[old_len..self.len], value);
@memset(self.slice()[old_len..self.len], value);
}
/// Append a value to the slice `n` times.
@ -262,7 +262,7 @@ pub fn BoundedArrayAligned(
const old_len = self.len;
self.len += n;
assert(self.len <= buffer_capacity);
mem.set(T, self.slice()[old_len..self.len], value);
@memset(self.slice()[old_len..self.len], value);
}
pub const Writer = if (T != u8)
@ -329,7 +329,7 @@ test "BoundedArray" {
try testing.expectEqual(a.popOrNull(), 0);
try testing.expectEqual(a.popOrNull(), null);
var unused = a.unusedCapacitySlice();
mem.set(u8, unused[0..8], 2);
@memset(unused[0..8], 2);
unused[8] = 3;
unused[9] = 4;
try testing.expectEqual(unused.len, a.capacity());

View File

@ -97,7 +97,7 @@ pub const BufSet = struct {
fn copy(self: *const BufSet, value: []const u8) ![]const u8 {
const result = try self.hash_map.allocator.alloc(u8, value.len);
mem.copy(u8, result, value);
@memcpy(result, value);
return result;
}
};

View File

@ -259,7 +259,7 @@ pub const ChildProcess = struct {
fn fifoToOwnedArrayList(fifo: *std.io.PollFifo) std.ArrayList(u8) {
if (fifo.head > 0) {
std.mem.copy(u8, fifo.buf[0..fifo.count], fifo.buf[fifo.head .. fifo.head + fifo.count]);
@memcpy(fifo.buf[0..fifo.count], fifo.buf[fifo.head..][0..fifo.count]);
}
const result = std.ArrayList(u8){
.items = fifo.buf[0..fifo.count],
@ -1436,9 +1436,9 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) !
var i: usize = 0;
while (it.next()) |pair| : (i += 1) {
const env_buf = try arena.allocSentinel(u8, pair.key_ptr.len + pair.value_ptr.len + 1, 0);
mem.copy(u8, env_buf, pair.key_ptr.*);
@memcpy(env_buf[0..pair.key_ptr.len], pair.key_ptr.*);
env_buf[pair.key_ptr.len] = '=';
mem.copy(u8, env_buf[pair.key_ptr.len + 1 ..], pair.value_ptr.*);
@memcpy(env_buf[pair.key_ptr.len + 1 ..][0..pair.value_ptr.len], pair.value_ptr.*);
envp_buf[i] = env_buf.ptr;
}
assert(i == envp_count);

View File

@ -12,6 +12,20 @@ pub const Decompressor = inflate.Decompressor;
pub const compressor = deflate.compressor;
pub const decompressor = inflate.decompressor;
/// Copies elements from a source `src` slice into a destination `dst` slice.
/// The copy never returns an error but might not be complete if the destination is too small.
/// Returns the number of elements copied, which will be the minimum of `src.len` and `dst.len`.
/// TODO: remove this smelly function
pub fn copy(dst: []u8, src: []const u8) usize {
if (dst.len <= src.len) {
@memcpy(dst, src[0..dst.len]);
return dst.len;
} else {
@memcpy(dst[0..src.len], src);
return src.len;
}
}
test {
_ = @import("deflate/token.zig");
_ = @import("deflate/bits_utils.zig");

View File

@ -10,7 +10,6 @@ const Allocator = std.mem.Allocator;
const deflate_const = @import("deflate_const.zig");
const fast = @import("deflate_fast.zig");
const hm_bw = @import("huffman_bit_writer.zig");
const mu = @import("mem_utils.zig");
const token = @import("token.zig");
pub const Compression = enum(i5) {
@ -296,7 +295,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
fn fillDeflate(self: *Self, b: []const u8) u32 {
if (self.index >= 2 * window_size - (min_match_length + max_match_length)) {
// shift the window by window_size
mem.copy(u8, self.window, self.window[window_size .. 2 * window_size]);
mem.copyForwards(u8, self.window, self.window[window_size .. 2 * window_size]);
self.index -= window_size;
self.window_end -= window_size;
if (self.block_start >= window_size) {
@ -328,7 +327,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
}
}
}
var n = mu.copy(self.window[self.window_end..], b);
const n = std.compress.deflate.copy(self.window[self.window_end..], b);
self.window_end += n;
return @intCast(u32, n);
}
@ -369,7 +368,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
b = b[b.len - window_size ..];
}
// Add all to window.
mem.copy(u8, self.window, b);
@memcpy(self.window[0..b.len], b);
var n = b.len;
// Calculate 256 hashes at the time (more L1 cache hits)
@ -543,7 +542,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
self.hash_offset = 1;
self.tokens = try self.allocator.alloc(token.Token, max_flate_block_tokens);
self.tokens_count = 0;
mem.set(token.Token, self.tokens, 0);
@memset(self.tokens, 0);
self.length = min_match_length - 1;
self.offset = 0;
self.byte_available = false;
@ -706,7 +705,7 @@ pub fn Compressor(comptime WriterType: anytype) type {
}
fn fillStore(self: *Self, b: []const u8) u32 {
var n = mu.copy(self.window[self.window_end..], b);
const n = std.compress.deflate.copy(self.window[self.window_end..], b);
self.window_end += n;
return @intCast(u32, n);
}
@ -841,9 +840,9 @@ pub fn Compressor(comptime WriterType: anytype) type {
s.hash_head = try allocator.alloc(u32, hash_size);
s.hash_prev = try allocator.alloc(u32, window_size);
s.hash_match = try allocator.alloc(u32, max_match_length - 1);
mem.set(u32, s.hash_head, 0);
mem.set(u32, s.hash_prev, 0);
mem.set(u32, s.hash_match, 0);
@memset(s.hash_head, 0);
@memset(s.hash_prev, 0);
@memset(s.hash_match, 0);
switch (options.level) {
.no_compression => {
@ -936,8 +935,8 @@ pub fn Compressor(comptime WriterType: anytype) type {
.best_compression,
=> {
self.chain_head = 0;
mem.set(u32, self.hash_head, 0);
mem.set(u32, self.hash_prev, 0);
@memset(self.hash_head, 0);
@memset(self.hash_prev, 0);
self.hash_offset = 1;
self.index = 0;
self.window_end = 0;
@ -1091,8 +1090,8 @@ test "bulkHash4" {
// double the test data
var out = try testing.allocator.alloc(u8, x.out.len * 2);
defer testing.allocator.free(out);
mem.copy(u8, out[0..x.out.len], x.out);
mem.copy(u8, out[x.out.len..], x.out);
@memcpy(out[0..x.out.len], x.out);
@memcpy(out[x.out.len..], x.out);
var j: usize = 4;
while (j < out.len) : (j += 1) {

View File

@ -9,7 +9,6 @@ const ArrayList = std.ArrayList;
const bu = @import("bits_utils.zig");
const ddec = @import("dict_decoder.zig");
const deflate_const = @import("deflate_const.zig");
const mu = @import("mem_utils.zig");
const max_match_offset = deflate_const.max_match_offset;
const end_block_marker = deflate_const.end_block_marker;
@ -159,7 +158,7 @@ const HuffmanDecoder = struct {
if (sanity) {
// initialize to a known invalid chunk code (0) to see if we overwrite
// this value later on
mem.set(u16, self.links[off], 0);
@memset(self.links[off], 0);
}
try self.sub_chunks.append(off);
}
@ -451,7 +450,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
pub fn read(self: *Self, output: []u8) Error!usize {
while (true) {
if (self.to_read.len > 0) {
var n = mu.copy(output, self.to_read);
const n = std.compress.deflate.copy(output, self.to_read);
self.to_read = self.to_read[n..];
if (self.to_read.len == 0 and
self.err != null)

View File

@ -237,7 +237,7 @@ pub const DeflateFast = struct {
}
self.cur += @intCast(i32, src.len);
self.prev_len = @intCast(u32, src.len);
mem.copy(u8, self.prev[0..self.prev_len], src);
@memcpy(self.prev[0..self.prev_len], src);
return;
}
@ -566,11 +566,11 @@ test "best speed match 2/2" {
for (cases) |c| {
var previous = try testing.allocator.alloc(u8, c.previous);
defer testing.allocator.free(previous);
mem.set(u8, previous, 0);
@memset(previous, 0);
var current = try testing.allocator.alloc(u8, c.current);
defer testing.allocator.free(current);
mem.set(u8, current, 0);
@memset(current, 0);
var e = DeflateFast{
.prev = previous,

View File

@ -123,13 +123,13 @@ test "best speed max match offset" {
var src = try testing.allocator.alloc(u8, src_len);
defer testing.allocator.free(src);
mem.copy(u8, src, abc);
@memcpy(src[0..abc.len], abc);
if (!do_match_before) {
var src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));
mem.copy(u8, src[src_offset..], xyz);
const src_offset: usize = @intCast(usize, offset - @as(i32, xyz.len));
@memcpy(src[src_offset..][0..xyz.len], xyz);
}
var src_offset: usize = @intCast(usize, offset);
mem.copy(u8, src[src_offset..], abc);
const src_offset: usize = @intCast(usize, offset);
@memcpy(src[src_offset..][0..abc.len], abc);
var compressed = ArrayList(u8).init(testing.allocator);
defer compressed.deinit();

View File

@ -47,7 +47,8 @@ pub const DictDecoder = struct {
self.wr_pos = 0;
if (dict != null) {
mem.copy(u8, self.hist, dict.?[dict.?.len -| self.hist.len..]);
const src = dict.?[dict.?.len -| self.hist.len..];
@memcpy(self.hist[0..src.len], src);
self.wr_pos = @intCast(u32, dict.?.len);
}
@ -103,12 +104,15 @@ pub const DictDecoder = struct {
self.wr_pos += 1;
}
/// TODO: eliminate this function because the callsites should care about whether
/// or not their arguments alias and then they should directly call `@memcpy` or
/// `mem.copyForwards`.
fn copy(dst: []u8, src: []const u8) u32 {
if (src.len > dst.len) {
mem.copy(u8, dst, src[0..dst.len]);
mem.copyForwards(u8, dst, src[0..dst.len]);
return @intCast(u32, dst.len);
}
mem.copy(u8, dst, src);
mem.copyForwards(u8, dst[0..src.len], src);
return @intCast(u32, src.len);
}

View File

@ -202,7 +202,7 @@ pub const HuffmanEncoder = struct {
// more values in the level below
l.last_freq = l.next_pair_freq;
// Take leaf counts from the lower level, except counts[level] remains the same.
mem.copy(u32, leaf_counts[level][0..level], leaf_counts[level - 1][0..level]);
@memcpy(leaf_counts[level][0..level], leaf_counts[level - 1][0..level]);
levels[l.level - 1].needed = 2;
}

View File

@ -1,15 +0,0 @@
const std = @import("std");
const math = std.math;
const mem = std.mem;
// Copies elements from a source `src` slice into a destination `dst` slice.
// The copy never returns an error but might not be complete if the destination is too small.
// Returns the number of elements copied, which will be the minimum of `src.len` and `dst.len`.
pub fn copy(dst: []u8, src: []const u8) usize {
if (dst.len <= src.len) {
mem.copy(u8, dst[0..], src[0..dst.len]);
} else {
mem.copy(u8, dst[0..src.len], src[0..]);
}
return math.min(dst.len, src.len);
}

View File

@ -75,9 +75,9 @@ pub fn Decompress(comptime ReaderType: type) type {
}
}
const input = self.to_read.items;
const n = math.min(input.len, output.len);
mem.copy(u8, output[0..n], input[0..n]);
mem.copy(u8, input, input[n..]);
const n = @min(input.len, output.len);
@memcpy(output[0..n], input[0..n]);
@memcpy(input[0 .. input.len - n], input[n..]);
self.to_read.shrinkRetainingCapacity(input.len - n);
return n;
}

View File

@ -143,7 +143,7 @@ pub fn BitTree(comptime num_bits: usize) type {
}
pub fn reset(self: *Self) void {
mem.set(u16, &self.probs, 0x400);
@memset(&self.probs, 0x400);
}
};
}

View File

@ -13,7 +13,7 @@ pub fn Vec2D(comptime T: type) type {
pub fn init(allocator: Allocator, value: T, size: struct { usize, usize }) !Self {
const len = try math.mul(usize, size[0], size[1]);
const data = try allocator.alloc(T, len);
mem.set(T, data, value);
@memset(data, value);
return Self{
.data = data,
.cols = size[1],
@ -26,7 +26,7 @@ pub fn Vec2D(comptime T: type) type {
}
pub fn fill(self: *Self, value: T) void {
mem.set(T, self.data, value);
@memset(self.data, value);
}
inline fn _get(self: Self, row: usize) ![]T {

View File

@ -59,9 +59,9 @@ pub fn Decoder(comptime ReaderType: type) type {
while (true) {
if (self.to_read.items.len > 0) {
const input = self.to_read.items;
const n = std.math.min(input.len, output.len);
std.mem.copy(u8, output[0..n], input[0..n]);
std.mem.copy(u8, input, input[n..]);
const n = @min(input.len, output.len);
@memcpy(output[0..n], input[0..n]);
std.mem.copyForwards(u8, input, input[n..]);
self.to_read.shrinkRetainingCapacity(input.len - n);
if (self.to_read.items.len == 0 and self.err != null) {
if (self.err.? == DecodeError.EndOfStreamWithNoError) {

View File

@ -293,10 +293,10 @@ pub const DecodeState = struct {
try self.decodeLiteralsSlice(dest[write_pos..], sequence.literal_length);
const copy_start = write_pos + sequence.literal_length - sequence.offset;
const copy_end = copy_start + sequence.match_length;
// NOTE: we ignore the usage message for std.mem.copy and copy with dest.ptr >= src.ptr
// to allow repeats
std.mem.copy(u8, dest[write_pos + sequence.literal_length ..], dest[copy_start..copy_end]);
for (
dest[write_pos + sequence.literal_length ..][0..sequence.match_length],
dest[copy_start..][0..sequence.match_length],
) |*d, s| d.* = s;
self.written_count += sequence.match_length;
}
@ -311,7 +311,6 @@ pub const DecodeState = struct {
try self.decodeLiteralsRingBuffer(dest, sequence.literal_length);
const copy_start = dest.write_index + dest.data.len - sequence.offset;
const copy_slice = dest.sliceAt(copy_start, sequence.match_length);
// TODO: would std.mem.copy and figuring out dest slice be better/faster?
for (copy_slice.first) |b| dest.writeAssumeCapacity(b);
for (copy_slice.second) |b| dest.writeAssumeCapacity(b);
self.written_count += sequence.match_length;
@ -444,9 +443,8 @@ pub const DecodeState = struct {
switch (self.literal_header.block_type) {
.raw => {
const literals_end = self.literal_written_count + len;
const literal_data = self.literal_streams.one[self.literal_written_count..literals_end];
std.mem.copy(u8, dest, literal_data);
const literal_data = self.literal_streams.one[self.literal_written_count..][0..len];
@memcpy(dest[0..len], literal_data);
self.literal_written_count += len;
self.written_count += len;
},
@ -615,8 +613,7 @@ pub fn decodeBlock(
.raw => {
if (src.len < block_size) return error.MalformedBlockSize;
if (dest[written_count..].len < block_size) return error.DestTooSmall;
const data = src[0..block_size];
std.mem.copy(u8, dest[written_count..], data);
@memcpy(dest[written_count..][0..block_size], src[0..block_size]);
consumed_count.* += block_size;
decode_state.written_count += block_size;
return block_size;

View File

@ -79,8 +79,8 @@ pub const Ed25519 = struct {
const r_bytes = r.toBytes();
var t: [64]u8 = undefined;
mem.copy(u8, t[0..32], &r_bytes);
mem.copy(u8, t[32..], &public_key.bytes);
t[0..32].* = r_bytes;
t[32..].* = public_key.bytes;
var h = Sha512.init(.{});
h.update(&t);
@ -200,8 +200,8 @@ pub const Ed25519 = struct {
/// Return the raw signature (r, s) in little-endian format.
pub fn toBytes(self: Signature) [encoded_length]u8 {
var bytes: [encoded_length]u8 = undefined;
mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);
mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);
bytes[0 .. encoded_length / 2].* = self.r;
bytes[encoded_length / 2 ..].* = self.s;
return bytes;
}
@ -260,8 +260,8 @@ pub const Ed25519 = struct {
const pk_p = Curve.basePoint.clampedMul(az[0..32].*) catch return error.IdentityElement;
const pk_bytes = pk_p.toBytes();
var sk_bytes: [SecretKey.encoded_length]u8 = undefined;
mem.copy(u8, &sk_bytes, &ss);
mem.copy(u8, sk_bytes[seed_length..], &pk_bytes);
sk_bytes[0..ss.len].* = ss;
sk_bytes[seed_length..].* = pk_bytes;
return KeyPair{
.public_key = PublicKey.fromBytes(pk_bytes) catch unreachable,
.secret_key = try SecretKey.fromBytes(sk_bytes),
@ -373,7 +373,7 @@ pub const Ed25519 = struct {
var z_batch: [count]Curve.scalar.CompressedScalar = undefined;
for (&z_batch) |*z| {
crypto.random.bytes(z[0..16]);
mem.set(u8, z[16..], 0);
@memset(z[16..], 0);
}
var zs_sum = Curve.scalar.zero;
@ -444,8 +444,8 @@ pub const Ed25519 = struct {
};
var prefix: [64]u8 = undefined;
mem.copy(u8, prefix[0..32], h[32..64]);
mem.copy(u8, prefix[32..64], blind_h[32..64]);
prefix[0..32].* = h[32..64].*;
prefix[32..64].* = blind_h[32..64].*;
const blind_secret_key = BlindSecretKey{
.prefix = prefix,

View File

@ -306,7 +306,7 @@ pub const Edwards25519 = struct {
var pcs: [count][9]Edwards25519 = undefined;
var bpc: [9]Edwards25519 = undefined;
mem.copy(Edwards25519, bpc[0..], basePointPc[0..bpc.len]);
@memcpy(&bpc, basePointPc[0..bpc.len]);
for (ps, 0..) |p, i| {
if (p.is_base) {
@ -439,7 +439,7 @@ pub const Edwards25519 = struct {
var u: [n * H.digest_length]u8 = undefined;
var i: usize = 0;
while (i < n * H.digest_length) : (i += H.digest_length) {
mem.copy(u8, u[i..][0..H.digest_length], u_0[0..]);
u[i..][0..H.digest_length].* = u_0;
var j: usize = 0;
while (i > 0 and j < H.digest_length) : (j += 1) {
u[i + j] ^= u[i + j - H.digest_length];
@ -455,8 +455,8 @@ pub const Edwards25519 = struct {
var px: [n]Edwards25519 = undefined;
i = 0;
while (i < n) : (i += 1) {
mem.set(u8, u_0[0 .. H.digest_length - h_l], 0);
mem.copy(u8, u_0[H.digest_length - h_l ..][0..h_l], u[i * h_l ..][0..h_l]);
@memset(u_0[0 .. H.digest_length - h_l], 0);
u_0[H.digest_length - h_l ..][0..h_l].* = u[i * h_l ..][0..h_l].*;
px[i] = fromHash(u_0);
}
return px;

View File

@ -83,8 +83,8 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar {
pub fn neg(s: CompressedScalar) CompressedScalar {
const fs: [64]u8 = field_order_s ++ [_]u8{0} ** 32;
var sx: [64]u8 = undefined;
mem.copy(u8, sx[0..32], s[0..]);
mem.set(u8, sx[32..], 0);
sx[0..32].* = s;
@memset(sx[32..], 0);
var carry: u32 = 0;
var i: usize = 0;
while (i < 64) : (i += 1) {
@ -593,7 +593,7 @@ const ScalarDouble = struct {
limbs[i] = mem.readIntLittle(u64, bytes[i * 7 ..][0..8]) & 0xffffffffffffff;
}
limbs[i] = @as(u64, mem.readIntLittle(u32, bytes[i * 7 ..][0..4]));
mem.set(u64, limbs[5..], 0);
@memset(limbs[5..], 0);
return ScalarDouble{ .limbs = limbs };
}

View File

@ -37,7 +37,7 @@ pub const X25519 = struct {
break :sk random_seed;
};
var kp: KeyPair = undefined;
mem.copy(u8, &kp.secret_key, sk[0..]);
kp.secret_key = sk;
kp.public_key = try X25519.recoverPublicKey(sk);
return kp;
}
@ -120,8 +120,8 @@ test "x25519 rfc7748 one iteration" {
var i: usize = 0;
while (i < 1) : (i += 1) {
const output = try X25519.scalarmult(k, u);
mem.copy(u8, u[0..], k[0..]);
mem.copy(u8, k[0..], output[0..]);
u = k;
k = output;
}
try std.testing.expectEqual(k, expected_output);
@ -142,8 +142,8 @@ test "x25519 rfc7748 1,000 iterations" {
var i: usize = 0;
while (i < 1000) : (i += 1) {
const output = try X25519.scalarmult(&k, &u);
mem.copy(u8, u[0..], k[0..]);
mem.copy(u8, k[0..], output[0..]);
u = k;
k = output;
}
try std.testing.expectEqual(k, expected_output);
@ -163,8 +163,8 @@ test "x25519 rfc7748 1,000,000 iterations" {
var i: usize = 0;
while (i < 1000000) : (i += 1) {
const output = try X25519.scalarmult(&k, &u);
mem.copy(u8, u[0..], k[0..]);
mem.copy(u8, k[0..], output[0..]);
u = k;
k = output;
}
try std.testing.expectEqual(k[0..], expected_output);

View File

@ -928,7 +928,7 @@ pub const rsa = struct {
pub const PSSSignature = struct {
pub fn fromBytes(comptime modulus_len: usize, msg: []const u8) [modulus_len]u8 {
var result = [1]u8{0} ** modulus_len;
std.mem.copy(u8, &result, msg);
std.mem.copyForwards(u8, &result, msg);
return result;
}
@ -1025,9 +1025,9 @@ pub const rsa = struct {
// initial zero octets.
var m_p = try allocator.alloc(u8, 8 + Hash.digest_length + sLen);
defer allocator.free(m_p);
std.mem.copy(u8, m_p, &([_]u8{0} ** 8));
std.mem.copy(u8, m_p[8..], &mHash);
std.mem.copy(u8, m_p[(8 + Hash.digest_length)..], salt);
std.mem.copyForwards(u8, m_p, &([_]u8{0} ** 8));
std.mem.copyForwards(u8, m_p[8..], &mHash);
std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt);
// 13. Let H' = Hash(M'), an octet string of length hLen.
var h_p: [Hash.digest_length]u8 = undefined;
@ -1047,7 +1047,7 @@ pub const rsa = struct {
var hash = try allocator.alloc(u8, seed.len + c.len);
defer allocator.free(hash);
std.mem.copy(u8, hash, seed);
std.mem.copyForwards(u8, hash, seed);
var hashed: [Hash.digest_length]u8 = undefined;
while (idx < len) {
@ -1056,10 +1056,10 @@ pub const rsa = struct {
c[2] = @intCast(u8, (counter >> 8) & 0xFF);
c[3] = @intCast(u8, counter & 0xFF);
std.mem.copy(u8, hash[seed.len..], &c);
std.mem.copyForwards(u8, hash[seed.len..], &c);
Hash.hash(hash, &hashed, .{});
std.mem.copy(u8, out[idx..], &hashed);
std.mem.copyForwards(u8, out[idx..], &hashed);
idx += hashed.len;
counter += 1;

View File

@ -152,8 +152,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
state.absorb(ad[i..][0..32]);
}
if (ad.len % 32 != 0) {
mem.set(u8, src[0..], 0);
mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);
@memset(src[0..], 0);
@memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
state.absorb(&src);
}
i = 0;
@ -161,10 +161,10 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
state.enc(c[i..][0..32], m[i..][0..32]);
}
if (m.len % 32 != 0) {
mem.set(u8, src[0..], 0);
mem.copy(u8, src[0 .. m.len % 32], m[i .. i + m.len % 32]);
@memset(src[0..], 0);
@memcpy(src[0 .. m.len % 32], m[i..][0 .. m.len % 32]);
state.enc(&dst, &src);
mem.copy(u8, c[i .. i + m.len % 32], dst[0 .. m.len % 32]);
@memcpy(c[i..][0 .. m.len % 32], dst[0 .. m.len % 32]);
}
tag.* = state.mac(tag_bits, ad.len, m.len);
}
@ -185,8 +185,8 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
state.absorb(ad[i..][0..32]);
}
if (ad.len % 32 != 0) {
mem.set(u8, src[0..], 0);
mem.copy(u8, src[0 .. ad.len % 32], ad[i .. i + ad.len % 32]);
@memset(src[0..], 0);
@memcpy(src[0 .. ad.len % 32], ad[i..][0 .. ad.len % 32]);
state.absorb(&src);
}
i = 0;
@ -194,11 +194,11 @@ fn Aegis128LGeneric(comptime tag_bits: u9) type {
state.dec(m[i..][0..32], c[i..][0..32]);
}
if (m.len % 32 != 0) {
mem.set(u8, src[0..], 0);
mem.copy(u8, src[0 .. m.len % 32], c[i .. i + m.len % 32]);
@memset(src[0..], 0);
@memcpy(src[0 .. m.len % 32], c[i..][0 .. m.len % 32]);
state.dec(&dst, &src);
mem.copy(u8, m[i .. i + m.len % 32], dst[0 .. m.len % 32]);
mem.set(u8, dst[0 .. m.len % 32], 0);
@memcpy(m[i..][0 .. m.len % 32], dst[0 .. m.len % 32]);
@memset(dst[0 .. m.len % 32], 0);
const blocks = &state.blocks;
blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(dst[0..16]));
blocks[4] = blocks[4].xorBlocks(AesBlock.fromBytes(dst[16..32]));
@ -334,8 +334,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
state.enc(&dst, ad[i..][0..16]);
}
if (ad.len % 16 != 0) {
mem.set(u8, src[0..], 0);
mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);
@memset(src[0..], 0);
@memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
state.enc(&dst, &src);
}
i = 0;
@ -343,10 +343,10 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
state.enc(c[i..][0..16], m[i..][0..16]);
}
if (m.len % 16 != 0) {
mem.set(u8, src[0..], 0);
mem.copy(u8, src[0 .. m.len % 16], m[i .. i + m.len % 16]);
@memset(src[0..], 0);
@memcpy(src[0 .. m.len % 16], m[i..][0 .. m.len % 16]);
state.enc(&dst, &src);
mem.copy(u8, c[i .. i + m.len % 16], dst[0 .. m.len % 16]);
@memcpy(c[i..][0 .. m.len % 16], dst[0 .. m.len % 16]);
}
tag.* = state.mac(tag_bits, ad.len, m.len);
}
@ -367,8 +367,8 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
state.enc(&dst, ad[i..][0..16]);
}
if (ad.len % 16 != 0) {
mem.set(u8, src[0..], 0);
mem.copy(u8, src[0 .. ad.len % 16], ad[i .. i + ad.len % 16]);
@memset(src[0..], 0);
@memcpy(src[0 .. ad.len % 16], ad[i..][0 .. ad.len % 16]);
state.enc(&dst, &src);
}
i = 0;
@ -376,11 +376,11 @@ fn Aegis256Generic(comptime tag_bits: u9) type {
state.dec(m[i..][0..16], c[i..][0..16]);
}
if (m.len % 16 != 0) {
mem.set(u8, src[0..], 0);
mem.copy(u8, src[0 .. m.len % 16], c[i .. i + m.len % 16]);
@memset(src[0..], 0);
@memcpy(src[0 .. m.len % 16], c[i..][0 .. m.len % 16]);
state.dec(&dst, &src);
mem.copy(u8, m[i .. i + m.len % 16], dst[0 .. m.len % 16]);
mem.set(u8, dst[0 .. m.len % 16], 0);
@memcpy(m[i..][0 .. m.len % 16], dst[0 .. m.len % 16]);
@memset(dst[0 .. m.len % 16], 0);
const blocks = &state.blocks;
blocks[0] = blocks[0].xorBlocks(AesBlock.fromBytes(&dst));
}
@ -457,7 +457,7 @@ fn AegisMac(comptime T: type) type {
self.msg_len += b.len;
const len_partial = @min(b.len, block_length - self.off);
mem.copy(u8, self.buf[self.off..][0..len_partial], b[0..len_partial]);
@memcpy(self.buf[self.off..][0..len_partial], b[0..len_partial]);
self.off += len_partial;
if (self.off < block_length) {
return;
@ -470,7 +470,7 @@ fn AegisMac(comptime T: type) type {
self.state.absorb(b[i..][0..block_length]);
}
if (i != b.len) {
mem.copy(u8, self.buf[0..], b[i..]);
@memcpy(self.buf[0..], b[i..]);
self.off = b.len - i;
}
}
@ -479,7 +479,7 @@ fn AegisMac(comptime T: type) type {
pub fn final(self: *Self, out: *[mac_length]u8) void {
if (self.off > 0) {
var pad = [_]u8{0} ** block_length;
mem.copy(u8, pad[0..], self.buf[0..self.off]);
@memcpy(pad[0..self.off], self.buf[0..self.off]);
self.state.absorb(&pad);
}
out.* = self.state.mac(T.tag_length * 8, self.msg_len, 0);

View File

@ -31,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type {
var t: [16]u8 = undefined;
var j: [16]u8 = undefined;
mem.copy(u8, j[0..nonce_length], npub[0..]);
j[0..nonce_length].* = npub;
mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
aes.encrypt(&t, &j);
@ -64,7 +64,7 @@ fn AesGcm(comptime Aes: anytype) type {
var t: [16]u8 = undefined;
var j: [16]u8 = undefined;
mem.copy(u8, j[0..nonce_length], npub[0..]);
j[0..nonce_length].* = npub;
mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
aes.encrypt(&t, &j);

View File

@ -75,7 +75,7 @@ fn AesOcb(comptime Aes: anytype) type {
if (leftover > 0) {
xorWith(&offset, lx.star);
var padded = [_]u8{0} ** 16;
mem.copy(u8, padded[0..leftover], a[i * 16 ..][0..leftover]);
@memcpy(padded[0..leftover], a[i * 16 ..][0..leftover]);
padded[leftover] = 1;
var e = xorBlocks(offset, padded);
aes_enc_ctx.encrypt(&e, &e);
@ -88,7 +88,7 @@ fn AesOcb(comptime Aes: anytype) type {
var nx = [_]u8{0} ** 16;
nx[0] = @intCast(u8, @truncate(u7, tag_length * 8) << 1);
nx[16 - nonce_length - 1] = 1;
mem.copy(u8, nx[16 - nonce_length ..], &npub);
nx[nx.len - nonce_length ..].* = npub;
const bottom = @truncate(u6, nx[15]);
nx[15] &= 0xc0;
@ -132,14 +132,14 @@ fn AesOcb(comptime Aes: anytype) type {
xorWith(&offset, lt[@ctz(i + 1 + j)]);
offsets[j] = offset;
const p = m[(i + j) * 16 ..][0..16].*;
mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(p, offsets[j]));
es[j * 16 ..][0..16].* = xorBlocks(p, offsets[j]);
xorWith(&sum, p);
}
aes_enc_ctx.encryptWide(wb, &es, &es);
j = 0;
while (j < wb) : (j += 1) {
const e = es[j * 16 ..][0..16].*;
mem.copy(u8, c[(i + j) * 16 ..][0..16], &xorBlocks(e, offsets[j]));
c[(i + j) * 16 ..][0..16].* = xorBlocks(e, offsets[j]);
}
}
while (i < full_blocks) : (i += 1) {
@ -147,7 +147,7 @@ fn AesOcb(comptime Aes: anytype) type {
const p = m[i * 16 ..][0..16].*;
var e = xorBlocks(p, offset);
aes_enc_ctx.encrypt(&e, &e);
mem.copy(u8, c[i * 16 ..][0..16], &xorBlocks(e, offset));
c[i * 16 ..][0..16].* = xorBlocks(e, offset);
xorWith(&sum, p);
}
const leftover = m.len % 16;
@ -159,7 +159,7 @@ fn AesOcb(comptime Aes: anytype) type {
c[i * 16 + j] = pad[j] ^ x;
}
var e = [_]u8{0} ** 16;
mem.copy(u8, e[0..leftover], m[i * 16 ..][0..leftover]);
@memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
e[leftover] = 0x80;
xorWith(&sum, e);
}
@ -196,13 +196,13 @@ fn AesOcb(comptime Aes: anytype) type {
xorWith(&offset, lt[@ctz(i + 1 + j)]);
offsets[j] = offset;
const q = c[(i + j) * 16 ..][0..16].*;
mem.copy(u8, es[j * 16 ..][0..16], &xorBlocks(q, offsets[j]));
es[j * 16 ..][0..16].* = xorBlocks(q, offsets[j]);
}
aes_dec_ctx.decryptWide(wb, &es, &es);
j = 0;
while (j < wb) : (j += 1) {
const p = xorBlocks(es[j * 16 ..][0..16].*, offsets[j]);
mem.copy(u8, m[(i + j) * 16 ..][0..16], &p);
m[(i + j) * 16 ..][0..16].* = p;
xorWith(&sum, p);
}
}
@ -212,7 +212,7 @@ fn AesOcb(comptime Aes: anytype) type {
var e = xorBlocks(q, offset);
aes_dec_ctx.decrypt(&e, &e);
const p = xorBlocks(e, offset);
mem.copy(u8, m[i * 16 ..][0..16], &p);
m[i * 16 ..][0..16].* = p;
xorWith(&sum, p);
}
const leftover = m.len % 16;
@ -224,7 +224,7 @@ fn AesOcb(comptime Aes: anytype) type {
m[i * 16 + j] = pad[j] ^ x;
}
var e = [_]u8{0} ** 16;
mem.copy(u8, e[0..leftover], m[i * 16 ..][0..leftover]);
@memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
e[leftover] = 0x80;
xorWith(&sum, e);
}

View File

@ -149,7 +149,7 @@ fn blake2bLong(out: []u8, in: []const u8) void {
h.update(&outlen_bytes);
h.update(in);
h.final(&out_buf);
mem.copy(u8, out, out_buf[0..out.len]);
@memcpy(out, out_buf[0..out.len]);
return;
}
@ -158,19 +158,19 @@ fn blake2bLong(out: []u8, in: []const u8) void {
h.update(in);
h.final(&out_buf);
var out_slice = out;
mem.copy(u8, out_slice, out_buf[0 .. H.digest_length / 2]);
out_slice[0 .. H.digest_length / 2].* = out_buf[0 .. H.digest_length / 2].*;
out_slice = out_slice[H.digest_length / 2 ..];
var in_buf: [H.digest_length]u8 = undefined;
while (out_slice.len > H.digest_length) {
mem.copy(u8, &in_buf, &out_buf);
in_buf = out_buf;
H.hash(&in_buf, &out_buf, .{});
mem.copy(u8, out_slice, out_buf[0 .. H.digest_length / 2]);
out_slice[0 .. H.digest_length / 2].* = out_buf[0 .. H.digest_length / 2].*;
out_slice = out_slice[H.digest_length / 2 ..];
}
mem.copy(u8, &in_buf, &out_buf);
in_buf = out_buf;
H.hash(&in_buf, &out_buf, .{ .expected_out_bits = out_slice.len * 8 });
mem.copy(u8, out_slice, out_buf[0..out_slice.len]);
@memcpy(out_slice, out_buf[0..out_slice.len]);
}
fn initBlocks(
@ -494,7 +494,7 @@ pub fn kdf(
if (params.t < 1 or params.p < 1) return KdfError.WeakParameters;
var h0 = initHash(password, salt, params, derived_key.len, mode);
const memory = math.max(
const memory = @max(
params.m / (sync_points * params.p) * (sync_points * params.p),
2 * sync_points * params.p,
);
@ -877,7 +877,7 @@ test "kdf" {
.hash = "1640b932f4b60e272f5d2207b9a9c626ffa1bd88d2349016",
},
};
inline for (test_vectors) |v| {
for (test_vectors) |v| {
var want: [24]u8 = undefined;
_ = try std.fmt.hexToBytes(&want, v.hash);

View File

@ -34,7 +34,7 @@ pub fn State(comptime endian: builtin.Endian) type {
/// Initialize the state from a slice of bytes.
pub fn init(initial_state: [block_bytes]u8) Self {
var state = Self{ .st = undefined };
mem.copy(u8, state.asBytes(), &initial_state);
@memcpy(state.asBytes(), &initial_state);
state.endianSwap();
return state;
}
@ -87,7 +87,7 @@ pub fn State(comptime endian: builtin.Endian) type {
}
if (i < bytes.len) {
var padded = [_]u8{0} ** 8;
mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
@memcpy(padded[0 .. bytes.len - i], bytes[i..]);
self.st[i / 8] = mem.readInt(u64, padded[0..], endian);
}
}
@ -109,7 +109,7 @@ pub fn State(comptime endian: builtin.Endian) type {
}
if (i < bytes.len) {
var padded = [_]u8{0} ** 8;
mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
@memcpy(padded[0 .. bytes.len - i], bytes[i..]);
self.st[i / 8] ^= mem.readInt(u64, padded[0..], endian);
}
}
@ -123,7 +123,7 @@ pub fn State(comptime endian: builtin.Endian) type {
if (i < out.len) {
var padded = [_]u8{0} ** 8;
mem.writeInt(u64, padded[0..], self.st[i / 8], endian);
mem.copy(u8, out[i..], padded[0 .. out.len - i]);
@memcpy(out[i..], padded[0 .. out.len - i]);
}
}
@ -138,16 +138,16 @@ pub fn State(comptime endian: builtin.Endian) type {
}
if (i < in.len) {
var padded = [_]u8{0} ** 8;
mem.copy(u8, padded[0 .. in.len - i], in[i..]);
@memcpy(padded[0 .. in.len - i], in[i..]);
const x = mem.readIntNative(u64, &padded) ^ mem.nativeTo(u64, self.st[i / 8], endian);
mem.writeIntNative(u64, &padded, x);
mem.copy(u8, out[i..], padded[0 .. in.len - i]);
@memcpy(out[i..], padded[0 .. in.len - i]);
}
}
/// Set the words storing the bytes of a given range to zero.
pub fn clear(self: *Self, from: usize, to: usize) void {
mem.set(u64, self.st[from / 8 .. (to + 7) / 8], 0);
@memset(self.st[from / 8 .. (to + 7) / 8], 0);
}
/// Clear the entire state, disabling compiler optimizations.

View File

@ -416,8 +416,8 @@ pub fn bcrypt(
) [dk_length]u8 {
var state = State{};
var password_buf: [73]u8 = undefined;
const trimmed_len = math.min(password.len, password_buf.len - 1);
mem.copy(u8, password_buf[0..], password[0..trimmed_len]);
const trimmed_len = @min(password.len, password_buf.len - 1);
@memcpy(password_buf[0..trimmed_len], password[0..trimmed_len]);
password_buf[trimmed_len] = 0;
var passwordZ = password_buf[0 .. trimmed_len + 1];
state.expand(salt[0..], passwordZ);
@ -626,7 +626,7 @@ const CryptFormatHasher = struct {
crypto.random.bytes(&salt);
const hash = crypt_format.strHashInternal(password, salt, params);
mem.copy(u8, buf, &hash);
@memcpy(buf[0..hash.len], &hash);
return buf[0..pwhash_str_length];
}

View File

@ -113,8 +113,8 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_c
var i: usize = 0;
while (i < exchange_count) : (i += 1) {
const out = try DhKeyExchange.scalarmult(secret, public);
mem.copy(u8, secret[0..16], out[0..16]);
mem.copy(u8, public[0..16], out[16..32]);
secret[0..16].* = out[0..16].*;
public[0..16].* = out[16..32].*;
mem.doNotOptimizeAway(&out);
}
}

View File

@ -76,7 +76,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
comptime debug.assert(8 <= out_bits and out_bits <= 256);
var d: Self = undefined;
mem.copy(u32, d.h[0..], iv[0..]);
d.h = iv;
const key_len = if (options.key) |key| key.len else 0;
// default parameters
@ -93,7 +93,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
d.h[7] ^= mem.readIntLittle(u32, context[4..8]);
}
if (key_len > 0) {
mem.set(u8, d.buf[key_len..], 0);
@memset(d.buf[key_len..], 0);
d.update(options.key.?);
d.buf_len = 64;
}
@ -112,7 +112,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len > 64) {
off += 64 - d.buf_len;
mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
@memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.t += 64;
d.round(d.buf[0..], false);
d.buf_len = 0;
@ -125,16 +125,17 @@ pub fn Blake2s(comptime out_bits: usize) type {
}
// Copy any remainder for next pass.
mem.copy(u8, d.buf[d.buf_len..], b[off..]);
d.buf_len += @intCast(u8, b[off..].len);
const b_slice = b[off..];
@memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
d.buf_len += @intCast(u8, b_slice.len);
}
pub fn final(d: *Self, out: *[digest_length]u8) void {
mem.set(u8, d.buf[d.buf_len..], 0);
@memset(d.buf[d.buf_len..], 0);
d.t += d.buf_len;
d.round(d.buf[0..], true);
for (&d.h) |*x| x.* = mem.nativeToLittle(u32, x.*);
mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
out.* = @ptrCast(*[digest_length]u8, &d.h).*;
}
fn round(d: *Self, b: *const [64]u8, last: bool) void {
@ -511,7 +512,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
comptime debug.assert(8 <= out_bits and out_bits <= 512);
var d: Self = undefined;
mem.copy(u64, d.h[0..], iv[0..]);
d.h = iv;
const key_len = if (options.key) |key| key.len else 0;
// default parameters
@ -528,7 +529,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
d.h[7] ^= mem.readIntLittle(u64, context[8..16]);
}
if (key_len > 0) {
mem.set(u8, d.buf[key_len..], 0);
@memset(d.buf[key_len..], 0);
d.update(options.key.?);
d.buf_len = 128;
}
@ -547,7 +548,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len > 128) {
off += 128 - d.buf_len;
mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
@memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.t += 128;
d.round(d.buf[0..], false);
d.buf_len = 0;
@ -560,16 +561,17 @@ pub fn Blake2b(comptime out_bits: usize) type {
}
// Copy any remainder for next pass.
mem.copy(u8, d.buf[d.buf_len..], b[off..]);
d.buf_len += @intCast(u8, b[off..].len);
const b_slice = b[off..];
@memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
d.buf_len += @intCast(u8, b_slice.len);
}
pub fn final(d: *Self, out: *[digest_length]u8) void {
mem.set(u8, d.buf[d.buf_len..], 0);
@memset(d.buf[d.buf_len..], 0);
d.t += d.buf_len;
d.round(d.buf[0..], true);
for (&d.h) |*x| x.* = mem.nativeToLittle(u64, x.*);
mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h));
out.* = @ptrCast(*[digest_length]u8, &d.h).*;
}
fn round(d: *Self, b: *const [128]u8, last: bool) void {

View File

@ -253,7 +253,7 @@ const Output = struct {
while (out_word_it.next()) |out_word| {
var word_bytes: [4]u8 = undefined;
mem.writeIntLittle(u32, &word_bytes, words[word_counter]);
mem.copy(u8, out_word, word_bytes[0..out_word.len]);
@memcpy(out_word, word_bytes[0..out_word.len]);
word_counter += 1;
}
output_block_counter += 1;
@ -284,7 +284,7 @@ const ChunkState = struct {
fn fillBlockBuf(self: *ChunkState, input: []const u8) []const u8 {
const want = BLOCK_LEN - self.block_len;
const take = math.min(want, input.len);
mem.copy(u8, self.block[self.block_len..][0..take], input[0..take]);
@memcpy(self.block[self.block_len..][0..take], input[0..take]);
self.block_len += @truncate(u8, take);
return input[take..];
}
@ -336,8 +336,8 @@ fn parentOutput(
flags: u8,
) Output {
var block_words: [16]u32 align(16) = undefined;
mem.copy(u32, block_words[0..8], left_child_cv[0..]);
mem.copy(u32, block_words[8..], right_child_cv[0..]);
block_words[0..8].* = left_child_cv;
block_words[8..].* = right_child_cv;
return Output{
.input_chaining_value = key,
.block_words = block_words,

View File

@ -211,7 +211,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type {
var buf: [64]u8 = undefined;
hashToBytes(buf[0..], x);
mem.copy(u8, out[i..], buf[0 .. out.len - i]);
@memcpy(out[i..], buf[0 .. out.len - i]);
}
}
@ -372,7 +372,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
var buf: [64]u8 = undefined;
hashToBytes(buf[0..], x);
mem.copy(u8, out[i..], buf[0 .. out.len - i]);
@memcpy(out[i..], buf[0 .. out.len - i]);
}
}
@ -413,8 +413,8 @@ fn keyToWords(key: [32]u8) [8]u32 {
fn extend(key: [32]u8, nonce: [24]u8, comptime rounds_nb: usize) struct { key: [32]u8, nonce: [12]u8 } {
var subnonce: [12]u8 = undefined;
mem.set(u8, subnonce[0..4], 0);
mem.copy(u8, subnonce[4..], nonce[16..24]);
@memset(subnonce[0..4], 0);
subnonce[4..].* = nonce[16..24].*;
return .{
.key = ChaChaImpl(rounds_nb).hchacha20(nonce[0..16].*, key),
.nonce = subnonce,

View File

@ -102,8 +102,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
/// Return the raw signature (r, s) in big-endian format.
pub fn toBytes(self: Signature) [encoded_length]u8 {
var bytes: [encoded_length]u8 = undefined;
mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r);
mem.copy(u8, bytes[encoded_length / 2 ..], &self.s);
@memcpy(bytes[0 .. encoded_length / 2], &self.r);
@memcpy(bytes[encoded_length / 2 ..], &self.s);
return bytes;
}
@ -325,11 +325,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar {
if (unreduced_len >= 48) {
var xs = [_]u8{0} ** 64;
mem.copy(u8, xs[xs.len - s.len ..], s[0..]);
@memcpy(xs[xs.len - s.len ..], s[0..]);
return Curve.scalar.Scalar.fromBytes64(xs, .Big);
}
var xs = [_]u8{0} ** 48;
mem.copy(u8, xs[xs.len - s.len ..], s[0..]);
@memcpy(xs[xs.len - s.len ..], s[0..]);
return Curve.scalar.Scalar.fromBytes48(xs, .Big);
}
@ -345,14 +345,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
const m_x = m[m_v.len + 1 + noise_length ..][0..secret_key.len];
const m_h = m[m.len - h.len ..];
mem.set(u8, m_v, 0x01);
@memset(m_v, 0x01);
m_i.* = 0x00;
if (noise) |n| mem.copy(u8, m_z, &n);
mem.copy(u8, m_x, &secret_key);
mem.copy(u8, m_h, &h);
if (noise) |n| @memcpy(m_z, &n);
@memcpy(m_x, &secret_key);
@memcpy(m_h, &h);
Hmac.create(&k, &m, &k);
Hmac.create(m_v, m_v, &k);
mem.copy(u8, m_v, m_v);
m_i.* = 0x01;
Hmac.create(&k, &m, &k);
Hmac.create(m_v, m_v, &k);
@ -361,10 +360,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
while (t_off < t.len) : (t_off += m_v.len) {
const t_end = @min(t_off + m_v.len, t.len);
Hmac.create(m_v, m_v, &k);
std.mem.copy(u8, t[t_off..t_end], m_v[0 .. t_end - t_off]);
@memcpy(t[t_off..t_end], m_v[0 .. t_end - t_off]);
}
if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {}
mem.copy(u8, m_v, m_v);
m_i.* = 0x00;
Hmac.create(&k, m[0 .. m_v.len + 1], &k);
Hmac.create(m_v, m_v, &k);

View File

@ -63,7 +63,7 @@ pub fn Hkdf(comptime Hmac: type) type {
st.update(&counter);
var tmp: [prk_length]u8 = undefined;
st.final(tmp[0..prk_length]);
mem.copy(u8, out[i..][0..left], tmp[0..left]);
@memcpy(out[i..][0..left], tmp[0..left]);
}
}
};

View File

@ -38,12 +38,12 @@ pub fn Hmac(comptime Hash: type) type {
// Normalize key length to block size of hash
if (key.len > Hash.block_length) {
Hash.hash(key, scratch[0..mac_length], .{});
mem.set(u8, scratch[mac_length..Hash.block_length], 0);
@memset(scratch[mac_length..Hash.block_length], 0);
} else if (key.len < Hash.block_length) {
mem.copy(u8, scratch[0..key.len], key);
mem.set(u8, scratch[key.len..Hash.block_length], 0);
@memcpy(scratch[0..key.len], key);
@memset(scratch[key.len..Hash.block_length], 0);
} else {
mem.copy(u8, scratch[0..], key);
@memcpy(&scratch, key);
}
for (&ctx.o_key_pad, 0..) |*b, i| {

View File

@ -43,7 +43,7 @@ pub const IsapA128A = struct {
}
} else {
var padded = [_]u8{0} ** 8;
mem.copy(u8, padded[0..left], m[i..]);
@memcpy(padded[0..left], m[i..]);
padded[left] = 0x80;
isap.st.addBytes(&padded);
isap.st.permute();

View File

@ -68,7 +68,7 @@ pub fn KeccakF(comptime f: u11) type {
}
if (i < bytes.len) {
var padded = [_]u8{0} ** @sizeOf(T);
mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
@memcpy(padded[0 .. bytes.len - i], bytes[i..]);
self.st[i / @sizeOf(T)] = mem.readIntLittle(T, padded[0..]);
}
}
@ -87,7 +87,7 @@ pub fn KeccakF(comptime f: u11) type {
}
if (i < bytes.len) {
var padded = [_]u8{0} ** @sizeOf(T);
mem.copy(u8, padded[0 .. bytes.len - i], bytes[i..]);
@memcpy(padded[0 .. bytes.len - i], bytes[i..]);
self.st[i / @sizeOf(T)] ^= mem.readIntLittle(T, padded[0..]);
}
}
@ -101,7 +101,7 @@ pub fn KeccakF(comptime f: u11) type {
if (i < out.len) {
var padded = [_]u8{0} ** @sizeOf(T);
mem.writeIntLittle(T, padded[0..], self.st[i / @sizeOf(T)]);
mem.copy(u8, out[i..], padded[0 .. out.len - i]);
@memcpy(out[i..], padded[0 .. out.len - i]);
}
}
@ -116,16 +116,16 @@ pub fn KeccakF(comptime f: u11) type {
}
if (i < in.len) {
var padded = [_]u8{0} ** @sizeOf(T);
mem.copy(u8, padded[0 .. in.len - i], in[i..]);
@memcpy(padded[0 .. in.len - i], in[i..]);
const x = mem.readIntNative(T, &padded) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
mem.writeIntNative(T, &padded, x);
mem.copy(u8, out[i..], padded[0 .. in.len - i]);
@memcpy(out[i..], padded[0 .. in.len - i]);
}
}
/// Set the words storing the bytes of a given range to zero.
pub fn clear(self: *Self, from: usize, to: usize) void {
mem.set(T, self.st[from / @sizeOf(T) .. (to + @sizeOf(T) - 1) / @sizeOf(T)], 0);
@memset(self.st[from / @sizeOf(T) .. (to + @sizeOf(T) - 1) / @sizeOf(T)], 0);
}
/// Clear the entire state, disabling compiler optimizations.
@ -215,7 +215,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
var bytes = bytes_;
if (self.offset > 0) {
const left = math.min(rate - self.offset, bytes.len);
mem.copy(u8, self.buf[self.offset..], bytes[0..left]);
@memcpy(self.buf[self.offset..][0..left], bytes[0..left]);
self.offset += left;
if (self.offset == rate) {
self.offset = 0;
@ -231,7 +231,7 @@ pub fn State(comptime f: u11, comptime capacity: u11, comptime delim: u8, compti
bytes = bytes[rate..];
}
if (bytes.len > 0) {
mem.copy(u8, &self.buf, bytes);
@memcpy(self.buf[0..bytes.len], bytes);
self.offset = bytes.len;
}
}

View File

@ -323,9 +323,9 @@ fn Kyber(comptime p: Params) type {
s += InnerSk.bytes_length;
ret.pk = InnerPk.fromBytes(buf[s .. s + InnerPk.bytes_length]);
s += InnerPk.bytes_length;
mem.copy(u8, &ret.hpk, buf[s .. s + h_length]);
ret.hpk = buf[s..][0..h_length].*;
s += h_length;
mem.copy(u8, &ret.z, buf[s .. s + shared_length]);
ret.z = buf[s..][0..shared_length].*;
return ret;
}
};
@ -345,7 +345,7 @@ fn Kyber(comptime p: Params) type {
break :sk random_seed;
};
var ret: KeyPair = undefined;
mem.copy(u8, &ret.secret_key.z, seed[inner_seed_length..seed_length]);
ret.secret_key.z = seed[inner_seed_length..seed_length].*;
// Generate inner key
innerKeyFromSeed(
@ -356,7 +356,7 @@ fn Kyber(comptime p: Params) type {
ret.secret_key.pk = ret.public_key.pk;
// Copy over z from seed.
mem.copy(u8, &ret.secret_key.z, seed[inner_seed_length..seed_length]);
ret.secret_key.z = seed[inner_seed_length..seed_length].*;
// Compute H(pk)
var h = sha3.Sha3_256.init(.{});
@ -418,7 +418,7 @@ fn Kyber(comptime p: Params) type {
fn fromBytes(buf: *const [bytes_length]u8) InnerPk {
var ret: InnerPk = undefined;
ret.th = V.fromBytes(buf[0..V.bytes_length]).normalize();
mem.copy(u8, &ret.rho, buf[V.bytes_length..bytes_length]);
ret.rho = buf[V.bytes_length..bytes_length].*;
ret.aT = M.uniform(ret.rho, true);
return ret;
}
@ -459,7 +459,7 @@ fn Kyber(comptime p: Params) type {
var h = sha3.Sha3_512.init(.{});
h.update(&seed);
h.final(&expanded_seed);
mem.copy(u8, &pk.rho, expanded_seed[0..32]);
pk.rho = expanded_seed[0..32].*;
const sigma = expanded_seed[32..64];
pk.aT = M.uniform(pk.rho, false); // Expand ρ to A; we'll transpose later on
@ -1381,7 +1381,7 @@ fn Vec(comptime K: u8) type {
const cs = comptime Poly.compressedSize(d);
var ret: [compressedSize(d)]u8 = undefined;
inline for (0..K) |i| {
mem.copy(u8, ret[i * cs .. (i + 1) * cs], &v.ps[i].compress(d));
ret[i * cs .. (i + 1) * cs].* = v.ps[i].compress(d);
}
return ret;
}
@ -1399,11 +1399,7 @@ fn Vec(comptime K: u8) type {
fn toBytes(v: Self) [bytes_length]u8 {
var ret: [bytes_length]u8 = undefined;
inline for (0..K) |i| {
mem.copy(
u8,
ret[i * Poly.bytes_length .. (i + 1) * Poly.bytes_length],
&v.ps[i].toBytes(),
);
ret[i * Poly.bytes_length .. (i + 1) * Poly.bytes_length].* = v.ps[i].toBytes();
}
return ret;
}
@ -1479,7 +1475,7 @@ test "MulHat" {
const p2 = a.ntt().mulHat(b.ntt()).barrettReduce().invNTT().normalize();
var p: Poly = undefined;
mem.set(i16, &p.cs, 0);
@memset(&p.cs, 0);
for (0..N) |i| {
for (0..N) |j| {
@ -1742,15 +1738,15 @@ const NistDRBG = struct {
g.incV();
var block: [16]u8 = undefined;
ctx.encrypt(&block, &g.v);
mem.copy(u8, buf[i * 16 .. (i + 1) * 16], &block);
buf[i * 16 ..][0..16].* = block;
}
if (pd) |p| {
for (&buf, p) |*b, x| {
b.* ^= x;
}
}
mem.copy(u8, &g.key, buf[0..32]);
mem.copy(u8, &g.v, buf[32..48]);
g.key = buf[0..32].*;
g.v = buf[32..48].*;
}
// randombytes.
@ -1763,10 +1759,10 @@ const NistDRBG = struct {
g.incV();
ctx.encrypt(&block, &g.v);
if (dst.len < 16) {
mem.copy(u8, dst, block[0..dst.len]);
@memcpy(dst, block[0..dst.len]);
break;
}
mem.copy(u8, dst, &block);
dst[0..block.len].* = block;
dst = dst[16..dst.len];
}
g.update(null);

View File

@ -66,7 +66,7 @@ pub const Md5 = struct {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
off += 64 - d.buf_len;
mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
@memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.round(&d.buf);
d.buf_len = 0;
@ -78,8 +78,9 @@ pub const Md5 = struct {
}
// Copy any remainder for next pass.
mem.copy(u8, d.buf[d.buf_len..], b[off..]);
d.buf_len += @intCast(u8, b[off..].len);
const b_slice = b[off..];
@memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
d.buf_len += @intCast(u8, b_slice.len);
// Md5 uses the bottom 64-bits for length padding
d.total_len +%= b.len;
@ -87,7 +88,7 @@ pub const Md5 = struct {
pub fn final(d: *Self, out: *[digest_length]u8) void {
// The buffer here will never be completely full.
mem.set(u8, d.buf[d.buf_len..], 0);
@memset(d.buf[d.buf_len..], 0);
// Append padding bits.
d.buf[d.buf_len] = 0x80;
@ -96,7 +97,7 @@ pub const Md5 = struct {
// > 448 mod 512 so need to add an extra round to wrap around.
if (64 - d.buf_len < 8) {
d.round(d.buf[0..]);
mem.set(u8, d.buf[0..], 0);
@memset(d.buf[0..], 0);
}
// Append message length.

View File

@ -38,8 +38,10 @@ pub fn ctr(comptime BlockCipher: anytype, block_cipher: BlockCipher, dst: []u8,
if (i < src.len) {
mem.writeInt(u128, &counter, counterInt, endian);
var pad = [_]u8{0} ** block_length;
mem.copy(u8, &pad, src[i..]);
const src_slice = src[i..];
@memcpy(pad[0..src_slice.len], src_slice);
block_cipher.xor(&pad, &pad, counter);
mem.copy(u8, dst[i..], pad[0 .. src.len - i]);
const pad_slice = pad[0 .. src.len - i];
@memcpy(dst[i..][0..pad_slice.len], pad_slice);
}
}

View File

@ -129,13 +129,13 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com
const offset = block * h_len;
const block_len = if (block != blocks_count - 1) h_len else r;
const dk_block: []u8 = dk[offset..][0..block_len];
mem.copy(u8, dk_block, prev_block[0..dk_block.len]);
@memcpy(dk_block, prev_block[0..dk_block.len]);
var i: u32 = 1;
while (i < rounds) : (i += 1) {
// U_c = PRF (P, U_{c-1})
Prf.create(&new_block, prev_block[0..], password);
mem.copy(u8, prev_block[0..], new_block[0..]);
prev_block = new_block;
// F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c
for (dk_block, 0..) |_, j| {

View File

@ -228,8 +228,8 @@ pub fn Field(comptime params: FieldParams) type {
}
if (iterations % 2 != 0) {
fiat.divstep(&out1, &out2, &out3, &out4, &out5, d, f, g, v, r);
mem.copy(Word, &v, &out4);
mem.copy(Word, &f, &out2);
v = out4;
f = out2;
}
var v_opp: Limbs = undefined;
fiat.opp(&v_opp, v);

View File

@ -105,7 +105,7 @@ pub const P256 = struct {
var out: [33]u8 = undefined;
const xy = p.affineCoordinates();
out[0] = if (xy.y.isOdd()) 3 else 2;
mem.copy(u8, out[1..], &xy.x.toBytes(.Big));
out[1..].* = xy.x.toBytes(.Big);
return out;
}
@ -114,8 +114,8 @@ pub const P256 = struct {
var out: [65]u8 = undefined;
out[0] = 4;
const xy = p.affineCoordinates();
mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));
mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));
out[1..33].* = xy.x.toBytes(.Big);
out[33..65].* = xy.y.toBytes(.Big);
return out;
}

View File

@ -192,20 +192,20 @@ const ScalarDouble = struct {
var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
{
var b = [_]u8{0} ** encoded_length;
const len = math.min(s.len, 24);
mem.copy(u8, b[0..len], s[0..len]);
const len = @min(s.len, 24);
b[0..len].* = s[0..len].*;
t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
}
if (s_.len >= 24) {
var b = [_]u8{0} ** encoded_length;
const len = math.min(s.len - 24, 24);
mem.copy(u8, b[0..len], s[24..][0..len]);
const len = @min(s.len - 24, 24);
b[0..len].* = s[24..][0..len].*;
t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
}
if (s_.len >= 48) {
var b = [_]u8{0} ** encoded_length;
const len = s.len - 48;
mem.copy(u8, b[0..len], s[48..][0..len]);
b[0..len].* = s[48..][0..len].*;
t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
}
return t;

View File

@ -105,7 +105,7 @@ pub const P384 = struct {
var out: [49]u8 = undefined;
const xy = p.affineCoordinates();
out[0] = if (xy.y.isOdd()) 3 else 2;
mem.copy(u8, out[1..], &xy.x.toBytes(.Big));
out[1..].* = xy.x.toBytes(.Big);
return out;
}
@ -114,8 +114,8 @@ pub const P384 = struct {
var out: [97]u8 = undefined;
out[0] = 4;
const xy = p.affineCoordinates();
mem.copy(u8, out[1..49], &xy.x.toBytes(.Big));
mem.copy(u8, out[49..97], &xy.y.toBytes(.Big));
out[1..49].* = xy.x.toBytes(.Big);
out[49..97].* = xy.y.toBytes(.Big);
return out;
}

View File

@ -180,14 +180,14 @@ const ScalarDouble = struct {
var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };
{
var b = [_]u8{0} ** encoded_length;
const len = math.min(s.len, 32);
mem.copy(u8, b[0..len], s[0..len]);
const len = @min(s.len, 32);
b[0..len].* = s[0..len].*;
t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
}
if (s_.len >= 32) {
var b = [_]u8{0} ** encoded_length;
const len = math.min(s.len - 32, 32);
mem.copy(u8, b[0..len], s[32..][0..len]);
const len = @min(s.len - 32, 32);
b[0..len].* = s[32..][0..len].*;
t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
}
return t;

View File

@ -158,7 +158,7 @@ pub const Secp256k1 = struct {
var out: [33]u8 = undefined;
const xy = p.affineCoordinates();
out[0] = if (xy.y.isOdd()) 3 else 2;
mem.copy(u8, out[1..], &xy.x.toBytes(.Big));
out[1..].* = xy.x.toBytes(.Big);
return out;
}
@ -167,8 +167,8 @@ pub const Secp256k1 = struct {
var out: [65]u8 = undefined;
out[0] = 4;
const xy = p.affineCoordinates();
mem.copy(u8, out[1..33], &xy.x.toBytes(.Big));
mem.copy(u8, out[33..65], &xy.y.toBytes(.Big));
out[1..33].* = xy.x.toBytes(.Big);
out[33..65].* = xy.y.toBytes(.Big);
return out;
}

View File

@ -192,20 +192,20 @@ const ScalarDouble = struct {
var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
{
var b = [_]u8{0} ** encoded_length;
const len = math.min(s.len, 24);
mem.copy(u8, b[0..len], s[0..len]);
const len = @min(s.len, 24);
b[0..len].* = s[0..len].*;
t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
}
if (s_.len >= 24) {
var b = [_]u8{0} ** encoded_length;
const len = math.min(s.len - 24, 24);
mem.copy(u8, b[0..len], s[24..][0..len]);
const len = @min(s.len - 24, 24);
b[0..len].* = s[24..][0..len].*;
t.x2 = Fe.fromBytes(b, .Little) catch unreachable;
}
if (s_.len >= 48) {
var b = [_]u8{0} ** encoded_length;
const len = s.len - 48;
mem.copy(u8, b[0..len], s[48..][0..len]);
b[0..len].* = s[48..][0..len].*;
t.x3 = Fe.fromBytes(b, .Little) catch unreachable;
}
return t;

View File

@ -35,7 +35,7 @@ pub fn BinValue(comptime max_len: usize) type {
pub fn fromSlice(slice: []const u8) Error!Self {
if (slice.len > capacity) return Error.NoSpaceLeft;
var bin_value: Self = undefined;
mem.copy(u8, &bin_value.buf, slice);
@memcpy(bin_value.buf[0..slice.len], slice);
bin_value.len = slice.len;
return bin_value;
}

View File

@ -383,10 +383,10 @@ pub const XSalsa20Poly1305 = struct {
debug.assert(c.len == m.len);
const extended = extend(rounds, k, npub);
var block0 = [_]u8{0} ** 64;
const mlen0 = math.min(32, m.len);
mem.copy(u8, block0[32..][0..mlen0], m[0..mlen0]);
const mlen0 = @min(32, m.len);
@memcpy(block0[32..][0..mlen0], m[0..mlen0]);
Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
mem.copy(u8, c[0..mlen0], block0[32..][0..mlen0]);
@memcpy(c[0..mlen0], block0[32..][0..mlen0]);
Salsa20.xor(c[mlen0..], m[mlen0..], 1, extended.key, extended.nonce);
var mac = Poly1305.init(block0[0..32]);
mac.update(ad);
@ -405,7 +405,7 @@ pub const XSalsa20Poly1305 = struct {
const extended = extend(rounds, k, npub);
var block0 = [_]u8{0} ** 64;
const mlen0 = math.min(32, c.len);
mem.copy(u8, block0[32..][0..mlen0], c[0..mlen0]);
@memcpy(block0[32..][0..mlen0], c[0..mlen0]);
Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
var mac = Poly1305.init(block0[0..32]);
mac.update(ad);
@ -420,7 +420,7 @@ pub const XSalsa20Poly1305 = struct {
utils.secureZero(u8, &computedTag);
return error.AuthenticationFailed;
}
mem.copy(u8, m[0..mlen0], block0[32..][0..mlen0]);
@memcpy(m[0..mlen0], block0[32..][0..mlen0]);
Salsa20.xor(m[mlen0..], c[mlen0..], 1, extended.key, extended.nonce);
}
};
@ -533,7 +533,7 @@ pub const SealedBox = struct {
debug.assert(c.len == m.len + seal_length);
var ekp = try KeyPair.create(null);
const nonce = createNonce(ekp.public_key, public_key);
mem.copy(u8, c[0..public_length], ekp.public_key[0..]);
c[0..public_length].* = ekp.public_key;
try Box.seal(c[Box.public_length..], m, nonce, public_key, ekp.secret_key);
utils.secureZero(u8, ekp.secret_key[0..]);
}

View File

@ -27,7 +27,7 @@ const max_salt_len = 64;
const max_hash_len = 64;
fn blockCopy(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {
mem.copy(u32, dst, src[0 .. n * 16]);
@memcpy(dst[0 .. n * 16], src[0 .. n * 16]);
}
fn blockXor(dst: []align(16) u32, src: []align(16) const u32, n: usize) void {
@ -242,7 +242,7 @@ const crypt_format = struct {
pub fn fromSlice(slice: []const u8) EncodingError!Self {
if (slice.len > capacity) return EncodingError.NoSpaceLeft;
var bin_value: Self = undefined;
mem.copy(u8, &bin_value.buf, slice);
@memcpy(bin_value.buf[0..slice.len], slice);
bin_value.len = slice.len;
return bin_value;
}
@ -314,7 +314,7 @@ const crypt_format = struct {
fn serializeTo(params: anytype, out: anytype) !void {
var header: [14]u8 = undefined;
mem.copy(u8, header[0..3], prefix);
header[0..3].* = prefix.*;
Codec.intEncode(header[3..4], params.ln);
Codec.intEncode(header[4..9], params.r);
Codec.intEncode(header[9..14], params.p);

View File

@ -62,7 +62,7 @@ pub const Sha1 = struct {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
off += 64 - d.buf_len;
mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
@memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.round(d.buf[0..]);
d.buf_len = 0;
@ -74,7 +74,7 @@ pub const Sha1 = struct {
}
// Copy any remainder for next pass.
mem.copy(u8, d.buf[d.buf_len..], b[off..]);
@memcpy(d.buf[d.buf_len..][0 .. b.len - off], b[off..]);
d.buf_len += @intCast(u8, b[off..].len);
d.total_len += b.len;
@ -82,7 +82,7 @@ pub const Sha1 = struct {
pub fn final(d: *Self, out: *[digest_length]u8) void {
// The buffer here will never be completely full.
mem.set(u8, d.buf[d.buf_len..], 0);
@memset(d.buf[d.buf_len..], 0);
// Append padding bits.
d.buf[d.buf_len] = 0x80;
@ -91,7 +91,7 @@ pub const Sha1 = struct {
// > 448 mod 512 so need to add an extra round to wrap around.
if (64 - d.buf_len < 8) {
d.round(d.buf[0..]);
mem.set(u8, d.buf[0..], 0);
@memset(d.buf[0..], 0);
}
// Append message length.

View File

@ -118,7 +118,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
off += 64 - d.buf_len;
mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
@memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.round(&d.buf);
d.buf_len = 0;
@ -130,7 +130,8 @@ fn Sha2x32(comptime params: Sha2Params32) type {
}
// Copy any remainder for next pass.
mem.copy(u8, d.buf[d.buf_len..], b[off..]);
const b_slice = b[off..];
@memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
d.buf_len += @intCast(u8, b[off..].len);
d.total_len += b.len;
@ -143,7 +144,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
pub fn final(d: *Self, out: *[digest_length]u8) void {
// The buffer here will never be completely full.
mem.set(u8, d.buf[d.buf_len..], 0);
@memset(d.buf[d.buf_len..], 0);
// Append padding bits.
d.buf[d.buf_len] = 0x80;
@ -152,7 +153,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
// > 448 mod 512 so need to add an extra round to wrap around.
if (64 - d.buf_len < 8) {
d.round(&d.buf);
mem.set(u8, d.buf[0..], 0);
@memset(d.buf[0..], 0);
}
// Append message length.
@ -609,7 +610,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
// Partial buffer exists from previous update. Copy into buffer then hash.
if (d.buf_len != 0 and d.buf_len + b.len >= 128) {
off += 128 - d.buf_len;
mem.copy(u8, d.buf[d.buf_len..], b[0..off]);
@memcpy(d.buf[d.buf_len..][0..off], b[0..off]);
d.round(&d.buf);
d.buf_len = 0;
@ -621,7 +622,8 @@ fn Sha2x64(comptime params: Sha2Params64) type {
}
// Copy any remainder for next pass.
mem.copy(u8, d.buf[d.buf_len..], b[off..]);
const b_slice = b[off..];
@memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice);
d.buf_len += @intCast(u8, b[off..].len);
d.total_len += b.len;
@ -634,7 +636,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
pub fn final(d: *Self, out: *[digest_length]u8) void {
// The buffer here will never be completely full.
mem.set(u8, d.buf[d.buf_len..], 0);
@memset(d.buf[d.buf_len..], 0);
// Append padding bits.
d.buf[d.buf_len] = 0x80;
@ -643,7 +645,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
// > 896 mod 1024 so need to add an extra round to wrap around.
if (128 - d.buf_len < 16) {
d.round(d.buf[0..]);
mem.set(u8, d.buf[0..], 0);
@memset(d.buf[0..], 0);
}
// Append message length.

View File

@ -149,7 +149,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
const left = self.buf.len - self.offset;
if (left > 0) {
const n = math.min(left, out.len);
mem.copy(u8, out[0..n], self.buf[self.offset..][0..n]);
@memcpy(out[0..n], self.buf[self.offset..][0..n]);
out = out[n..];
self.offset += n;
if (out.len == 0) {
@ -164,7 +164,7 @@ fn ShakeLike(comptime security_level: u11, comptime delim: u8, comptime rounds:
}
if (out.len > 0) {
self.st.squeeze(self.buf[0..]);
mem.copy(u8, out[0..], self.buf[0..out.len]);
@memcpy(out[0..], self.buf[0..out.len]);
self.offset = out.len;
}
}

View File

@ -98,7 +98,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
self.msg_len +%= @truncate(u8, b.len);
var buf = [_]u8{0} ** 8;
mem.copy(u8, buf[0..], b[0..]);
@memcpy(buf[0..b.len], b);
buf[7] = self.msg_len;
self.round(buf);
@ -203,7 +203,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
if (self.buf_len != 0 and self.buf_len + b.len >= 8) {
off += 8 - self.buf_len;
mem.copy(u8, self.buf[self.buf_len..], b[0..off]);
@memcpy(self.buf[self.buf_len..][0..off], b[0..off]);
self.state.update(self.buf[0..]);
self.buf_len = 0;
}
@ -212,8 +212,9 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
const aligned_len = remain_len - (remain_len % 8);
self.state.update(b[off .. off + aligned_len]);
mem.copy(u8, self.buf[self.buf_len..], b[off + aligned_len ..]);
self.buf_len += @intCast(u8, b[off + aligned_len ..].len);
const b_slice = b[off + aligned_len ..];
@memcpy(self.buf[self.buf_len..][0..b_slice.len], b_slice);
self.buf_len += @intCast(u8, b_slice.len);
}
pub fn peek(self: Self) [mac_length]u8 {

View File

@ -312,11 +312,11 @@ pub fn hkdfExpandLabel(
buf[2] = @intCast(u8, tls13.len + label.len);
buf[3..][0..tls13.len].* = tls13.*;
var i: usize = 3 + tls13.len;
mem.copy(u8, buf[i..], label);
@memcpy(buf[i..][0..label.len], label);
i += label.len;
buf[i] = @intCast(u8, context.len);
i += 1;
mem.copy(u8, buf[i..], context);
@memcpy(buf[i..][0..context.len], context);
i += context.len;
var result: [len]u8 = undefined;

View File

@ -685,7 +685,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
.application_cipher = app_cipher,
.partially_read_buffer = undefined,
};
mem.copy(u8, &client.partially_read_buffer, leftover);
@memcpy(client.partially_read_buffer[0..leftover.len], leftover);
return client;
},
else => {
@ -809,7 +809,7 @@ fn prepareCiphertextRecord(
.overhead_len = overhead_len,
};
mem.copy(u8, &cleartext_buf, bytes[bytes_i..][0..encrypted_content_len]);
@memcpy(cleartext_buf[0..encrypted_content_len], bytes[bytes_i..][0..encrypted_content_len]);
cleartext_buf[encrypted_content_len] = @enumToInt(inner_content_type);
bytes_i += encrypted_content_len;
const ciphertext_len = encrypted_content_len + 1;
@ -1029,8 +1029,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
if (frag1.len < second_len)
return finishRead2(c, first, frag1, vp.total);
mem.copy(u8, frag[0..in], first);
mem.copy(u8, frag[first.len..], frag1[0..second_len]);
@memcpy(frag[0..in], first);
@memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
frag = frag[0..full_record_len];
frag1 = frag1[second_len..];
in = 0;
@ -1059,8 +1059,8 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
if (frag1.len < second_len)
return finishRead2(c, first, frag1, vp.total);
mem.copy(u8, frag[0..in], first);
mem.copy(u8, frag[first.len..], frag1[0..second_len]);
@memcpy(frag[0..in], first);
@memcpy(frag[first.len..][0..second_len], frag1[0..second_len]);
frag = frag[0..full_record_len];
frag1 = frag1[second_len..];
in = 0;
@ -1177,7 +1177,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
// We have already run out of room in iovecs. Continue
// appending to `partially_read_buffer`.
const dest = c.partially_read_buffer[c.partial_ciphertext_idx..];
mem.copy(u8, dest, msg);
@memcpy(dest[0..msg.len], msg);
c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), c.partial_ciphertext_idx + msg.len);
} else {
const amt = vp.put(msg);
@ -1185,7 +1185,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
const rest = msg[amt..];
c.partial_cleartext_idx = 0;
c.partial_ciphertext_idx = @intCast(@TypeOf(c.partial_ciphertext_idx), rest.len);
mem.copy(u8, &c.partially_read_buffer, rest);
@memcpy(c.partially_read_buffer[0..rest.len], rest);
}
}
} else {
@ -1213,12 +1213,12 @@ fn finishRead(c: *Client, frag: []const u8, in: usize, out: usize) usize {
if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
// There is cleartext at the beginning already which we need to preserve.
c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + saved_buf.len);
mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx..], saved_buf);
@memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..saved_buf.len], saved_buf);
} else {
c.partial_cleartext_idx = 0;
c.partial_ciphertext_idx = 0;
c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), saved_buf.len);
mem.copy(u8, &c.partially_read_buffer, saved_buf);
@memcpy(c.partially_read_buffer[0..saved_buf.len], saved_buf);
}
return out;
}
@ -1227,14 +1227,14 @@ fn finishRead2(c: *Client, first: []const u8, frag1: []const u8, out: usize) usi
if (c.partial_ciphertext_idx > c.partial_cleartext_idx) {
// There is cleartext at the beginning already which we need to preserve.
c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), c.partial_ciphertext_idx + first.len + frag1.len);
mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx..], first);
mem.copy(u8, c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..], frag1);
@memcpy(c.partially_read_buffer[c.partial_ciphertext_idx..][0..first.len], first);
@memcpy(c.partially_read_buffer[c.partial_ciphertext_idx + first.len ..][0..frag1.len], frag1);
} else {
c.partial_cleartext_idx = 0;
c.partial_ciphertext_idx = 0;
c.partial_ciphertext_end = @intCast(@TypeOf(c.partial_ciphertext_end), first.len + frag1.len);
mem.copy(u8, &c.partially_read_buffer, first);
mem.copy(u8, c.partially_read_buffer[first.len..], frag1);
@memcpy(c.partially_read_buffer[0..first.len], first);
@memcpy(c.partially_read_buffer[first.len..][0..frag1.len], frag1);
}
return out;
}
@ -1282,7 +1282,7 @@ const VecPut = struct {
const v = vp.iovecs[vp.idx];
const dest = v.iov_base[vp.off..v.iov_len];
const src = bytes[bytes_i..][0..@min(dest.len, bytes.len - bytes_i)];
mem.copy(u8, dest, src);
@memcpy(dest[0..src.len], src);
bytes_i += src.len;
vp.off += src.len;
if (vp.off >= v.iov_len) {

View File

@ -134,12 +134,8 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T,
/// Sets a slice to zeroes.
/// Prevents the store from being optimized out.
pub fn secureZero(comptime T: type, s: []T) void {
// TODO: implement `@memset` for non-byte-sized element type in the llvm backend
//@memset(@as([]volatile T, s), 0);
const ptr = @ptrCast([*]volatile u8, s.ptr);
const length = s.len * @sizeOf(T);
@memset(ptr[0..length], 0);
pub inline fn secureZero(comptime T: type, s: []T) void {
@memset(@as([]volatile T, s), 0);
}
test "crypto.utils.timingSafeEql" {
@ -148,7 +144,7 @@ test "crypto.utils.timingSafeEql" {
random.bytes(a[0..]);
random.bytes(b[0..]);
try testing.expect(!timingSafeEql([100]u8, a, b));
mem.copy(u8, a[0..], b[0..]);
a = b;
try testing.expect(timingSafeEql([100]u8, a, b));
}
@ -201,7 +197,7 @@ test "crypto.utils.secureZero" {
var a = [_]u8{0xfe} ** 8;
var b = [_]u8{0xfe} ** 8;
mem.set(u8, a[0..], 0);
@memset(a[0..], 0);
secureZero(u8, b[0..]);
try testing.expectEqualSlices(u8, a[0..], b[0..]);

View File

@ -34,7 +34,7 @@ fn testCStrFnsImpl() !void {
/// Caller owns the returned memory.
pub fn addNullByte(allocator: mem.Allocator, slice: []const u8) ![:0]u8 {
const result = try allocator.alloc(u8, slice.len + 1);
mem.copy(u8, result, slice);
@memcpy(result[0..slice.len], slice);
result[slice.len] = 0;
return result[0..slice.len :0];
}
@ -78,7 +78,7 @@ pub const NullTerminated2DArray = struct {
for (slice) |inner| {
index_buf[i] = buf.ptr + write_index;
i += 1;
mem.copy(u8, buf[write_index..], inner);
@memcpy(buf[write_index..][0..inner.len], inner);
write_index += inner.len;
buf[write_index] = 0;
write_index += 1;

View File

@ -309,8 +309,8 @@ pub fn panicExtra(
// error being part of the @panic stack trace (but that error should
// only happen rarely)
const msg = std.fmt.bufPrint(buf[0..size], format, args) catch |err| switch (err) {
std.fmt.BufPrintError.NoSpaceLeft => blk: {
std.mem.copy(u8, buf[size..], trunc_msg);
error.NoSpaceLeft => blk: {
@memcpy(buf[size..], trunc_msg);
break :blk &buf;
},
};

View File

@ -210,7 +210,7 @@ pub const ElfDynLib = struct {
-1,
0,
);
mem.copy(u8, sect_mem, file_bytes[0..ph.p_filesz]);
@memcpy(sect_mem[0..ph.p_filesz], file_bytes[0..ph.p_filesz]);
}
},
else => {},

View File

@ -275,7 +275,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
.bits = Self.BitSet.initFull(),
.values = undefined,
};
std.mem.set(V, &result.values, value);
@memset(&result.values, value);
return result;
}
/// Initializes a full mapping with supplied values.
@ -1175,7 +1175,7 @@ pub fn IndexedArray(comptime I: type, comptime V: type, comptime Ext: fn (type)
pub fn initFill(v: Value) Self {
var self: Self = undefined;
std.mem.set(Value, &self.values, v);
@memset(&self.values, v);
return self;
}

View File

@ -86,19 +86,17 @@ pub fn LinearFifo(
pub fn realign(self: *Self) void {
if (self.buf.len - self.head >= self.count) {
// this copy overlaps
mem.copy(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
mem.copyForwards(T, self.buf[0..self.count], self.buf[self.head..][0..self.count]);
self.head = 0;
} else {
var tmp: [mem.page_size / 2 / @sizeOf(T)]T = undefined;
while (self.head != 0) {
const n = math.min(self.head, tmp.len);
const n = @min(self.head, tmp.len);
const m = self.buf.len - n;
mem.copy(T, tmp[0..n], self.buf[0..n]);
// this middle copy overlaps; the others here don't
mem.copy(T, self.buf[0..m], self.buf[n..][0..m]);
mem.copy(T, self.buf[m..], tmp[0..n]);
@memcpy(tmp[0..n], self.buf[0..n]);
mem.copyForwards(T, self.buf[0..m], self.buf[n..][0..m]);
@memcpy(self.buf[m..][0..n], tmp[0..n]);
self.head -= n;
}
}
@ -223,8 +221,8 @@ pub fn LinearFifo(
while (dst_left.len > 0) {
const slice = self.readableSlice(0);
if (slice.len == 0) break;
const n = math.min(slice.len, dst_left.len);
mem.copy(T, dst_left, slice[0..n]);
const n = @min(slice.len, dst_left.len);
@memcpy(dst_left[0..n], slice[0..n]);
self.discard(n);
dst_left = dst_left[n..];
}
@ -289,8 +287,8 @@ pub fn LinearFifo(
while (src_left.len > 0) {
const writable_slice = self.writableSlice(0);
assert(writable_slice.len != 0);
const n = math.min(writable_slice.len, src_left.len);
mem.copy(T, writable_slice, src_left[0..n]);
const n = @min(writable_slice.len, src_left.len);
@memcpy(writable_slice[0..n], src_left[0..n]);
self.update(n);
src_left = src_left[n..];
}
@ -354,11 +352,11 @@ pub fn LinearFifo(
const slice = self.readableSliceMut(0);
if (src.len < slice.len) {
mem.copy(T, slice, src);
@memcpy(slice[0..src.len], src);
} else {
mem.copy(T, slice, src[0..slice.len]);
@memcpy(slice, src[0..slice.len]);
const slice2 = self.readableSliceMut(slice.len);
mem.copy(T, slice2, src[slice.len..]);
@memcpy(slice2[0 .. src.len - slice.len], src[slice.len..]);
}
}

View File

@ -84,8 +84,8 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
const i = tableLowerBound(bits);
if (i < enum3.len and enum3[i] == bits) {
const data = enum3_data[i];
const digits = buffer[1 .. data.str.len + 1];
mem.copy(u8, digits, data.str);
const digits = buffer[1..][0..data.str.len];
@memcpy(digits, data.str);
return FloatDecimal{
.digits = digits,
.exp = data.exp,

View File

@ -106,7 +106,7 @@ pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path:
var rand_buf: [AtomicFile.RANDOM_BYTES]u8 = undefined;
const tmp_path = try allocator.alloc(u8, dirname.len + 1 + base64_encoder.calcSize(rand_buf.len));
defer allocator.free(tmp_path);
mem.copy(u8, tmp_path[0..], dirname);
@memcpy(tmp_path[0..dirname.len], dirname);
tmp_path[dirname.len] = path.sep;
while (true) {
crypto.random.bytes(rand_buf[0..]);
@ -1541,9 +1541,9 @@ pub const Dir = struct {
return error.NameTooLong;
}
mem.copy(u8, out_buffer, out_path);
return out_buffer[0..out_path.len];
const result = out_buffer[0..out_path.len];
@memcpy(result, out_path);
return result;
}
/// Windows-only. Same as `Dir.realpath` except `pathname` is WTF16 encoded.
@ -1593,9 +1593,9 @@ pub const Dir = struct {
return error.NameTooLong;
}
mem.copy(u8, out_buffer, out_path);
return out_buffer[0..out_path.len];
const result = out_buffer[0..out_path.len];
@memcpy(result, out_path);
return result;
}
/// Same as `Dir.realpath` except caller must free the returned memory.
@ -2346,8 +2346,9 @@ pub const Dir = struct {
if (cleanup_dir_parent) |*d| d.close();
cleanup_dir_parent = iterable_dir;
iterable_dir = new_dir;
mem.copy(u8, &dir_name_buf, entry.name);
dir_name = dir_name_buf[0..entry.name.len];
const result = dir_name_buf[0..entry.name.len];
@memcpy(result, entry.name);
dir_name = result;
continue :scan_dir;
} else {
if (iterable_dir.dir.deleteFile(entry.name)) {
@ -2974,8 +2975,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;
const real_path = try std.os.realpathZ(&symlink_path_buf, &real_path_buf);
if (real_path.len > out_buffer.len) return error.NameTooLong;
std.mem.copy(u8, out_buffer, real_path);
return out_buffer[0..real_path.len];
const result = out_buffer[0..real_path.len];
@memcpy(result, real_path);
return result;
}
switch (builtin.os.tag) {
.linux => return os.readlinkZ("/proc/self/exe", out_buffer),
@ -3014,8 +3016,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
const real_path = try os.realpathZ(os.argv[0], &real_path_buf);
if (real_path.len > out_buffer.len)
return error.NameTooLong;
mem.copy(u8, out_buffer, real_path);
return out_buffer[0..real_path.len];
const result = out_buffer[0..real_path.len];
@memcpy(result, real_path);
return result;
} else if (argv0.len != 0) {
// argv[0] is not empty (and not a path): search it inside PATH
const PATH = std.os.getenvZ("PATH") orelse return error.FileNotFound;
@ -3032,8 +3035,9 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
// found a file, and hope it is the right file
if (real_path.len > out_buffer.len)
return error.NameTooLong;
mem.copy(u8, out_buffer, real_path);
return out_buffer[0..real_path.len];
const result = out_buffer[0..real_path.len];
@memcpy(result, real_path);
return result;
} else |_| continue;
}
}

View File

@ -79,7 +79,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
const buf = try allocator.alloc(u8, total_len);
errdefer allocator.free(buf);
mem.copy(u8, buf, paths[first_path_index]);
@memcpy(buf[0..paths[first_path_index].len], paths[first_path_index]);
var buf_index: usize = paths[first_path_index].len;
var prev_path = paths[first_path_index];
assert(prev_path.len > 0);
@ -94,7 +94,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn
buf_index += 1;
}
const adjusted_path = if (prev_sep and this_sep) this_path[1..] else this_path;
mem.copy(u8, buf[buf_index..], adjusted_path);
@memcpy(buf[buf_index..][0..adjusted_path.len], adjusted_path);
buf_index += adjusted_path.len;
prev_path = this_path;
}
@ -631,7 +631,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
real_result[i..][0..3].* = "..\\".*;
i += 3;
}
mem.copy(u8, real_result[i..], result.items);
@memcpy(real_result[i..][0..result.items.len], result.items);
return real_result;
}
}
@ -710,7 +710,7 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E
real_result[i..][0..3].* = "../".*;
i += 3;
}
mem.copy(u8, real_result[i..], result.items);
@memcpy(real_result[i..][0..result.items.len], result.items);
return real_result;
}
}
@ -1106,7 +1106,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
while (rest_it.next()) |to_component| {
result[result_index] = '\\';
result_index += 1;
mem.copy(u8, result[result_index..], to_component);
@memcpy(result[result_index..][0..to_component.len], to_component);
result_index += to_component.len;
}
@ -1151,7 +1151,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
return allocator.realloc(result, result_index - 1);
}
mem.copy(u8, result[result_index..], to_rest);
@memcpy(result[result_index..][0..to_rest.len], to_rest);
return result;
}

View File

@ -348,8 +348,8 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
var key: [256]u8 = undefined;
var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;
std.mem.set(u8, &key, 0);
std.mem.set(u8, &hashes_bytes, 0);
@memset(&key, 0);
@memset(&hashes_bytes, 0);
var i: u32 = 0;
while (i < 256) : (i += 1) {

View File

@ -147,7 +147,7 @@ pub const Wyhash = struct {
if (self.buf_len != 0 and self.buf_len + b.len >= 32) {
off += 32 - self.buf_len;
mem.copy(u8, self.buf[self.buf_len..], b[0..off]);
@memcpy(self.buf[self.buf_len..][0..off], b[0..off]);
self.state.update(self.buf[0..]);
self.buf_len = 0;
}
@ -156,7 +156,8 @@ pub const Wyhash = struct {
const aligned_len = remain_len - (remain_len % 32);
self.state.update(b[off .. off + aligned_len]);
mem.copy(u8, self.buf[self.buf_len..], b[off + aligned_len ..]);
const src = b[off + aligned_len ..];
@memcpy(self.buf[self.buf_len..][0..src.len], src);
self.buf_len += @intCast(u8, b[off + aligned_len ..].len);
}

View File

@ -36,7 +36,7 @@ pub const XxHash64 = struct {
pub fn update(self: *XxHash64, input: []const u8) void {
if (input.len < 32 - self.buf_len) {
mem.copy(u8, self.buf[self.buf_len..], input);
@memcpy(self.buf[self.buf_len..][0..input.len], input);
self.buf_len += input.len;
return;
}
@ -45,7 +45,7 @@ pub const XxHash64 = struct {
if (self.buf_len > 0) {
i = 32 - self.buf_len;
mem.copy(u8, self.buf[self.buf_len..], input[0..i]);
@memcpy(self.buf[self.buf_len..][0..i], input[0..i]);
self.processStripe(&self.buf);
self.buf_len = 0;
}
@ -55,7 +55,7 @@ pub const XxHash64 = struct {
}
const remaining_bytes = input[i..];
mem.copy(u8, &self.buf, remaining_bytes);
@memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
self.buf_len = remaining_bytes.len;
}
@ -165,7 +165,7 @@ pub const XxHash32 = struct {
pub fn update(self: *XxHash32, input: []const u8) void {
if (input.len < 16 - self.buf_len) {
mem.copy(u8, self.buf[self.buf_len..], input);
@memcpy(self.buf[self.buf_len..][0..input.len], input);
self.buf_len += input.len;
return;
}
@ -174,7 +174,7 @@ pub const XxHash32 = struct {
if (self.buf_len > 0) {
i = 16 - self.buf_len;
mem.copy(u8, self.buf[self.buf_len..], input[0..i]);
@memcpy(self.buf[self.buf_len..][0..i], input[0..i]);
self.processStripe(&self.buf);
self.buf_len = 0;
}
@ -184,7 +184,7 @@ pub const XxHash32 = struct {
}
const remaining_bytes = input[i..];
mem.copy(u8, &self.buf, remaining_bytes);
@memcpy(self.buf[0..remaining_bytes.len], remaining_bytes);
self.buf_len = remaining_bytes.len;
}

View File

@ -230,7 +230,7 @@ test "shrink" {
var slice = try test_ally.alloc(u8, 20);
defer test_ally.free(slice);
mem.set(u8, slice, 0x11);
@memset(slice, 0x11);
try std.testing.expect(test_ally.resize(slice, 17));
slice = slice[0..17];

View File

@ -153,7 +153,7 @@ fn freePages(start: usize, end: usize) void {
extended.data = @intToPtr([*]u128, new_end * mem.page_size)[0 .. mem.page_size / @sizeOf(u128)];
// Since this is the first page being freed and we consume it, assume *nothing* is free.
mem.set(u128, extended.data, PageStatus.none_free);
@memset(extended.data, PageStatus.none_free);
}
const clamped_start = @max(extendedOffset(), start);
extended.recycle(clamped_start - extendedOffset(), new_end - clamped_start);

View File

@ -448,7 +448,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
fn collectStackTrace(first_trace_addr: usize, addresses: *[stack_n]usize) void {
if (stack_n == 0) return;
mem.set(usize, addresses, 0);
@memset(addresses, 0);
var stack_trace = StackTrace{
.instruction_addresses = addresses,
.index = 0,
@ -1113,7 +1113,7 @@ test "shrink" {
var slice = try allocator.alloc(u8, 20);
defer allocator.free(slice);
mem.set(u8, slice, 0x11);
@memset(slice, 0x11);
try std.testing.expect(allocator.resize(slice, 17));
slice = slice[0..17];

View File

@ -284,7 +284,7 @@ pub const BufferedConnection = struct {
if (available > 0) {
const can_read = @truncate(u16, @min(available, left));
std.mem.copy(u8, buffer[out_index..], bconn.buf[bconn.start..][0..can_read]);
@memcpy(buffer[out_index..][0..can_read], bconn.buf[bconn.start..][0..can_read]);
out_index += can_read;
bconn.start += can_read;

View File

@ -38,7 +38,8 @@ pub const Field = struct {
pub fn modify(entry: *Field, allocator: Allocator, new_value: []const u8) !void {
if (entry.value.len <= new_value.len) {
std.mem.copy(u8, @constCast(entry.value), new_value);
// TODO: eliminate this use of `@constCast`.
@memcpy(@constCast(entry.value)[0..new_value.len], new_value);
} else {
allocator.free(entry.value);

View File

@ -128,7 +128,7 @@ pub const BufferedConnection = struct {
if (available > 0) {
const can_read = @truncate(u16, @min(available, left));
std.mem.copy(u8, buffer[out_index..], bconn.buf[bconn.start..][0..can_read]);
@memcpy(buffer[out_index..][0..can_read], bconn.buf[bconn.start..][0..can_read]);
out_index += can_read;
bconn.start += can_read;

View File

@ -654,7 +654,7 @@ const MockBufferedConnection = struct {
if (available > 0) {
const can_read = @truncate(u16, @min(available, left));
std.mem.copy(u8, buffer[out_index..], bconn.buf[bconn.start..][0..can_read]);
@memcpy(buffer[out_index..][0..can_read], bconn.buf[bconn.start..][0..can_read]);
out_index += can_read;
bconn.start += can_read;

View File

@ -20,8 +20,8 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty
var dest_index: usize = 0;
while (dest_index < dest.len) {
const written = std.math.min(dest.len - dest_index, self.end - self.start);
std.mem.copy(u8, dest[dest_index..], self.buf[self.start .. self.start + written]);
const written = @min(dest.len - dest_index, self.end - self.start);
@memcpy(dest[dest_index..][0..written], self.buf[self.start..][0..written]);
if (written == 0) {
// buf empty, fill it
const n = try self.unbuffered_reader.read(self.buf[0..]);
@ -115,11 +115,8 @@ test "io.BufferedReader Block" {
}
fn read(self: *Self, dest: []u8) Error!usize {
if (self.curr_read >= self.reads_allowed) {
return 0;
}
std.debug.assert(dest.len >= self.block.len);
std.mem.copy(u8, dest, self.block);
if (self.curr_read >= self.reads_allowed) return 0;
@memcpy(dest[0..self.block.len], self.block);
self.curr_read += 1;
return self.block.len;

View File

@ -30,8 +30,9 @@ pub fn BufferedWriter(comptime buffer_size: usize, comptime WriterType: type) ty
return self.unbuffered_writer.write(bytes);
}
mem.copy(u8, self.buf[self.end..], bytes);
self.end += bytes.len;
const new_end = self.end + bytes.len;
@memcpy(self.buf[self.end..new_end], bytes);
self.end = new_end;
return bytes.len;
}
};

View File

@ -45,10 +45,10 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
}
pub fn read(self: *Self, dest: []u8) ReadError!usize {
const size = std.math.min(dest.len, self.buffer.len - self.pos);
const size = @min(dest.len, self.buffer.len - self.pos);
const end = self.pos + size;
mem.copy(u8, dest[0..size], self.buffer[self.pos..end]);
@memcpy(dest[0..size], self.buffer[self.pos..end]);
self.pos = end;
return size;
@ -67,7 +67,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
else
self.buffer.len - self.pos;
mem.copy(u8, self.buffer[self.pos .. self.pos + n], bytes[0..n]);
@memcpy(self.buffer[self.pos..][0..n], bytes[0..n]);
self.pos += n;
if (n == 0) return error.NoSpaceLeft;

View File

@ -35,7 +35,7 @@ pub fn Writer(
pub fn writeByteNTimes(self: Self, byte: u8, n: usize) Error!void {
var bytes: [256]u8 = undefined;
mem.set(u8, bytes[0..], byte);
@memset(bytes[0..], byte);
var remaining: usize = n;
while (remaining > 0) {

View File

@ -1667,7 +1667,7 @@ fn parseInternal(
const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
if (r.len != stringToken.decodedLength()) return error.LengthMismatch;
switch (stringToken.escapes) {
.None => mem.copy(u8, &r, source_slice),
.None => @memcpy(r[0..source_slice.len], source_slice),
.Some => try unescapeValidString(&r, source_slice),
}
return r;
@ -1733,7 +1733,7 @@ fn parseInternal(
try allocator.alloc(u8, len);
errdefer allocator.free(output);
switch (stringToken.escapes) {
.None => mem.copy(u8, output, source_slice),
.None => @memcpy(output[0..source_slice.len], source_slice),
.Some => try unescapeValidString(output, source_slice),
}

View File

@ -2811,7 +2811,7 @@ test "json.serialize issue #5959" {
// StreamingParser has multiple internal fields set to undefined. This causes issues when using
// expectEqual so these are zeroed. We are testing for equality here only because this is a
// known small test reproduction which hits the relevant LLVM issue.
std.mem.set(u8, @ptrCast([*]u8, &parser)[0..@sizeOf(StreamingParser)], 0);
@memset(@ptrCast([*]u8, &parser)[0..@sizeOf(StreamingParser)], 0);
try std.testing.expectEqual(parser, parser);
}

View File

@ -176,7 +176,7 @@ pub const Mutable = struct {
/// Asserts the value fits in the limbs buffer.
pub fn copy(self: *Mutable, other: Const) void {
if (self.limbs.ptr != other.limbs.ptr) {
mem.copy(Limb, self.limbs[0..], other.limbs[0..other.limbs.len]);
@memcpy(self.limbs[0..other.limbs.len], other.limbs[0..other.limbs.len]);
}
self.positive = other.positive;
self.len = other.limbs.len;
@ -199,7 +199,7 @@ pub const Mutable = struct {
/// can be modified separately from the original.
/// Asserts that limbs is big enough to store the value.
pub fn clone(other: Mutable, limbs: []Limb) Mutable {
mem.copy(Limb, limbs, other.limbs[0..other.len]);
@memcpy(limbs[0..other.len], other.limbs[0..other.len]);
return .{
.limbs = limbs,
.len = other.len,
@ -344,7 +344,7 @@ pub const Mutable = struct {
.min => {
// Negative bound, signed = -0x80.
r.len = req_limbs;
mem.set(Limb, r.limbs[0 .. r.len - 1], 0);
@memset(r.limbs[0 .. r.len - 1], 0);
r.limbs[r.len - 1] = signmask;
r.positive = false;
},
@ -363,7 +363,7 @@ pub const Mutable = struct {
const new_mask = (new_signmask << 1) -% 1; // 0b0..001..1 where the rightmost 0 is the sign bit.
r.len = new_req_limbs;
std.mem.set(Limb, r.limbs[0 .. r.len - 1], maxInt(Limb));
@memset(r.limbs[0 .. r.len - 1], maxInt(Limb));
r.limbs[r.len - 1] = new_mask;
}
},
@ -376,7 +376,7 @@ pub const Mutable = struct {
.max => {
// Max bound, unsigned = 0xFF
r.len = req_limbs;
std.mem.set(Limb, r.limbs[0 .. r.len - 1], maxInt(Limb));
@memset(r.limbs[0 .. r.len - 1], maxInt(Limb));
r.limbs[r.len - 1] = mask;
},
},
@ -489,7 +489,7 @@ pub const Mutable = struct {
if (msl < req_limbs) {
r.limbs[msl] = 1;
r.len = req_limbs;
mem.set(Limb, r.limbs[msl + 1 .. req_limbs], 0);
@memset(r.limbs[msl + 1 .. req_limbs], 0);
} else {
carry_truncated = true;
}
@ -637,14 +637,14 @@ pub const Mutable = struct {
const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
const start = buf_index;
mem.copy(Limb, limbs_buffer[buf_index..], a.limbs);
@memcpy(limbs_buffer[buf_index..][0..a.limbs.len], a.limbs);
buf_index += a.limbs.len;
break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
} else a;
const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
const start = buf_index;
mem.copy(Limb, limbs_buffer[buf_index..], b.limbs);
@memcpy(limbs_buffer[buf_index..][0..b.limbs.len], b.limbs);
buf_index += b.limbs.len;
break :blk b.toMutable(limbs_buffer[start..buf_index]).toConst();
} else b;
@ -676,7 +676,7 @@ pub const Mutable = struct {
}
}
mem.set(Limb, rma.limbs[0 .. a.limbs.len + b.limbs.len], 0);
@memset(rma.limbs[0 .. a.limbs.len + b.limbs.len], 0);
llmulacc(.add, allocator, rma.limbs, a.limbs, b.limbs);
@ -708,7 +708,7 @@ pub const Mutable = struct {
const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: {
const start = buf_index;
const a_len = math.min(req_limbs, a.limbs.len);
mem.copy(Limb, limbs_buffer[buf_index..], a.limbs[0..a_len]);
@memcpy(limbs_buffer[buf_index..][0..a_len], a.limbs[0..a_len]);
buf_index += a_len;
break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
} else a;
@ -716,7 +716,7 @@ pub const Mutable = struct {
const b_copy = if (rma.limbs.ptr == b.limbs.ptr) blk: {
const start = buf_index;
const b_len = math.min(req_limbs, b.limbs.len);
mem.copy(Limb, limbs_buffer[buf_index..], b.limbs[0..b_len]);
@memcpy(limbs_buffer[buf_index..][0..b_len], b.limbs[0..b_len]);
buf_index += b_len;
break :blk a.toMutable(limbs_buffer[start..buf_index]).toConst();
} else b;
@ -751,7 +751,7 @@ pub const Mutable = struct {
const a_limbs = a.limbs[0..math.min(req_limbs, a.limbs.len)];
const b_limbs = b.limbs[0..math.min(req_limbs, b.limbs.len)];
mem.set(Limb, rma.limbs[0..req_limbs], 0);
@memset(rma.limbs[0..req_limbs], 0);
llmulacc(.add, allocator, rma.limbs, a_limbs, b_limbs);
rma.normalize(math.min(req_limbs, a.limbs.len + b.limbs.len));
@ -919,7 +919,7 @@ pub const Mutable = struct {
_ = opt_allocator;
assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing
mem.set(Limb, rma.limbs, 0);
@memset(rma.limbs, 0);
llsquareBasecase(rma.limbs, a.limbs);
@ -1522,7 +1522,7 @@ pub const Mutable = struct {
if (xy_trailing != 0) {
// Manually shift here since we know its limb aligned.
mem.copyBackwards(Limb, r.limbs[xy_trailing..], r.limbs[0..r.len]);
mem.set(Limb, r.limbs[0..xy_trailing], 0);
@memset(r.limbs[0..xy_trailing], 0);
r.len += xy_trailing;
}
}
@ -1556,7 +1556,7 @@ pub const Mutable = struct {
// for 0 <= j <= n - t, set q[j] to 0
q.len = shift + 1;
q.positive = true;
mem.set(Limb, q.limbs[0..q.len], 0);
@memset(q.limbs[0..q.len], 0);
// 2.
// while x >= y * b^(n - t):
@ -1691,7 +1691,7 @@ pub const Mutable = struct {
r.addScalar(a.abs(), -1);
if (req_limbs > r.len) {
mem.set(Limb, r.limbs[r.len..req_limbs], 0);
@memset(r.limbs[r.len..req_limbs], 0);
}
assert(r.limbs.len >= req_limbs);
@ -1730,7 +1730,7 @@ pub const Mutable = struct {
// Zero-extend the result
if (req_limbs > r.len) {
mem.set(Limb, r.limbs[r.len..req_limbs], 0);
@memset(r.limbs[r.len..req_limbs], 0);
}
// Truncate to required number of limbs.
@ -1921,8 +1921,8 @@ pub const Const = struct {
/// The result is an independent resource which is managed by the caller.
pub fn toManaged(self: Const, allocator: Allocator) Allocator.Error!Managed {
const limbs = try allocator.alloc(Limb, math.max(Managed.default_capacity, self.limbs.len));
mem.copy(Limb, limbs, self.limbs);
const limbs = try allocator.alloc(Limb, @max(Managed.default_capacity, self.limbs.len));
@memcpy(limbs[0..self.limbs.len], self.limbs);
return Managed{
.allocator = allocator,
.limbs = limbs,
@ -1935,7 +1935,7 @@ pub const Const = struct {
/// Asserts `limbs` is big enough to store the value.
pub fn toMutable(self: Const, limbs: []Limb) Mutable {
mem.copy(Limb, limbs, self.limbs[0..self.limbs.len]);
@memcpy(limbs[0..self.limbs.len], self.limbs[0..self.limbs.len]);
return .{
.limbs = limbs,
.positive = self.positive,
@ -2253,7 +2253,7 @@ pub const Const = struct {
.positive = true, // Make absolute by ignoring self.positive.
.len = self.limbs.len,
};
mem.copy(Limb, q.limbs, self.limbs);
@memcpy(q.limbs[0..self.limbs.len], self.limbs);
var r: Mutable = .{
.limbs = limbs_buffer[q.limbs.len..][0..self.limbs.len],
@ -2587,8 +2587,8 @@ pub const Managed = struct {
.allocator = allocator,
.metadata = other.metadata,
.limbs = block: {
var limbs = try allocator.alloc(Limb, other.len());
mem.copy(Limb, limbs[0..], other.limbs[0..other.len()]);
const limbs = try allocator.alloc(Limb, other.len());
@memcpy(limbs, other.limbs[0..other.len()]);
break :block limbs;
},
};
@ -2600,7 +2600,7 @@ pub const Managed = struct {
if (self.limbs.ptr == other.limbs.ptr) return;
try self.ensureCapacity(other.limbs.len);
mem.copy(Limb, self.limbs[0..], other.limbs[0..other.limbs.len]);
@memcpy(self.limbs[0..other.limbs.len], other.limbs[0..other.limbs.len]);
self.setMetadata(other.positive, other.limbs.len);
}
@ -3302,7 +3302,7 @@ fn llmulaccKaratsuba(
// Note, we don't need to compute all of p2, just enough limbs to satisfy r.
const p2_limbs = math.min(limbs_after_split, a1.len + b1.len);
mem.set(Limb, tmp[0..p2_limbs], 0);
@memset(tmp[0..p2_limbs], 0);
llmulacc(.add, allocator, tmp[0..p2_limbs], a1[0..math.min(a1.len, p2_limbs)], b1[0..math.min(b1.len, p2_limbs)]);
const p2 = tmp[0..llnormalize(tmp[0..p2_limbs])];
@ -3317,7 +3317,7 @@ fn llmulaccKaratsuba(
// Compute p0.
// Since a0.len, b0.len <= split and r.len >= split * 2, the full width of p0 needs to be computed.
const p0_limbs = a0.len + b0.len;
mem.set(Limb, tmp[0..p0_limbs], 0);
@memset(tmp[0..p0_limbs], 0);
llmulacc(.add, allocator, tmp[0..p0_limbs], a0, b0);
const p0 = tmp[0..llnormalize(tmp[0..p0_limbs])];
@ -3341,7 +3341,7 @@ fn llmulaccKaratsuba(
return;
}
mem.set(Limb, tmp, 0);
@memset(tmp, 0);
// p1 is nonzero, so compute the intermediary terms j0 = a0 - a1 and j1 = b1 - b0.
// 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 {
}
r[limb_shift - 1] = carry;
mem.set(Limb, r[0 .. limb_shift - 1], 0);
@memset(r[0 .. limb_shift - 1], 0);
}
fn 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 {
tmp2 = tmp_limbs;
}
mem.copy(Limb, tmp1, a);
mem.set(Limb, tmp1[a.len..], 0);
@memcpy(tmp1[0..a.len], a);
@memset(tmp1[a.len..], 0);
// Scan the exponent as a binary number, from left to right, dropping the
// most significant bit set.
@ -4074,14 +4074,14 @@ fn llpow(r: []Limb, a: []const Limb, b: u32, tmp_limbs: []Limb) void {
var i: usize = 0;
while (i < exp_bits) : (i += 1) {
// Square
mem.set(Limb, tmp2, 0);
@memset(tmp2, 0);
llsquareBasecase(tmp2, tmp1[0..llnormalize(tmp1)]);
mem.swap([]Limb, &tmp1, &tmp2);
// Multiply by a
const ov = @shlWithOverflow(exp, 1);
exp = ov[0];
if (ov[1] != 0) {
mem.set(Limb, tmp2, 0);
@memset(tmp2, 0);
llmulacc(.add, null, tmp2, tmp1[0..llnormalize(tmp1)], a);
mem.swap([]Limb, &tmp1, &tmp2);
}

View File

@ -192,12 +192,15 @@ test "Allocator.resize" {
}
}
/// Deprecated: use `@memcpy` if the arguments do not overlap, or
/// `copyForwards` if they do.
pub const copy = copyForwards;
/// Copy all of source into dest at position 0.
/// dest.len must be >= source.len.
/// If the slices overlap, dest.ptr must be <= src.ptr.
pub fn copy(comptime T: type, dest: []T, source: []const T) void {
for (dest[0..source.len], source) |*d, s|
d.* = s;
pub fn copyForwards(comptime T: type, dest: []T, source: []const T) void {
for (dest[0..source.len], source) |*d, s| d.* = s;
}
/// Copy all of source into dest at position 0.
@ -216,11 +219,7 @@ pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void {
}
}
/// Sets all elements of `dest` to `value`.
pub fn set(comptime T: type, dest: []T, value: T) void {
for (dest) |*d|
d.* = value;
}
pub const set = @compileError("deprecated; use @memset instead");
/// Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
/// However, it is recognized that there are sometimes use cases for initializing all fields to a "zero" value. For example, when
@ -249,7 +248,7 @@ pub fn zeroes(comptime T: type) T {
if (@sizeOf(T) == 0) return undefined;
if (struct_info.layout == .Extern) {
var item: T = undefined;
set(u8, asBytes(&item), 0);
@memset(asBytes(&item), 0);
return item;
} else {
var structure: T = undefined;
@ -1667,9 +1666,9 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
if (@typeInfo(T).Int.bits == 0) {
return set(u8, buffer, 0);
return @memset(buffer, 0);
} else if (@typeInfo(T).Int.bits == 8) {
set(u8, buffer, 0);
@memset(buffer, 0);
buffer[0] = @bitCast(u8, value);
return;
}
@ -1691,9 +1690,9 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
if (@typeInfo(T).Int.bits == 0) {
return set(u8, buffer, 0);
return @memset(buffer, 0);
} else if (@typeInfo(T).Int.bits == 8) {
set(u8, buffer, 0);
@memset(buffer, 0);
buffer[buffer.len - 1] = @bitCast(u8, value);
return;
}
@ -2706,7 +2705,7 @@ fn testReadIntImpl() !void {
}
}
test "writeIntSlice" {
test writeIntSlice {
try testWriteIntImpl();
comptime try testWriteIntImpl();
}
@ -3124,7 +3123,7 @@ pub fn replace(comptime T: type, input: []const T, needle: []const T, replacemen
var replacements: usize = 0;
while (slide < input.len) {
if (mem.startsWith(T, input[slide..], needle)) {
mem.copy(T, output[i .. i + replacement.len], replacement);
@memcpy(output[i..][0..replacement.len], replacement);
i += replacement.len;
slide += needle.len;
replacements += 1;

View File

@ -307,14 +307,14 @@ pub fn free(self: Allocator, memory: anytype) void {
/// Copies `m` to newly allocated memory. Caller owns the memory.
pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T {
const new_buf = try allocator.alloc(T, m.len);
mem.copy(T, new_buf, m);
@memcpy(new_buf, m);
return new_buf;
}
/// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.
pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T {
const new_buf = try allocator.alloc(T, m.len + 1);
mem.copy(T, new_buf, m);
@memcpy(new_buf[0..m.len], m);
new_buf[m.len] = 0;
return new_buf[0..m.len :0];
}

View File

@ -380,7 +380,7 @@ pub fn MultiArrayList(comptime T: type) type {
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
mem.copy(field_info.type, other_slice.items(field), self_slice.items(field));
@memcpy(other_slice.items(field), self_slice.items(field));
}
}
gpa.free(self.allocatedBytes());
@ -441,7 +441,7 @@ pub fn MultiArrayList(comptime T: type) type {
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
mem.copy(field_info.type, other_slice.items(field), self_slice.items(field));
@memcpy(other_slice.items(field), self_slice.items(field));
}
}
gpa.free(self.allocatedBytes());
@ -460,7 +460,7 @@ pub fn MultiArrayList(comptime T: type) type {
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
const field = @intToEnum(Field, i);
mem.copy(field_info.type, result_slice.items(field), self_slice.items(field));
@memcpy(result_slice.items(field), self_slice.items(field));
}
}
return result;

View File

@ -106,8 +106,8 @@ pub const Address = extern union {
// Add 1 to ensure a terminating 0 is present in the path array for maximum portability.
if (path.len + 1 > sock_addr.path.len) return error.NameTooLong;
mem.set(u8, &sock_addr.path, 0);
mem.copy(u8, &sock_addr.path, path);
@memset(&sock_addr.path, 0);
@memcpy(sock_addr.path[0..path.len], path);
return Address{ .un = sock_addr };
}
@ -346,7 +346,7 @@ pub const Ip6Address = extern struct {
if (!saw_any_digits) {
if (abbrv) return error.InvalidCharacter; // ':::'
if (i != 0) abbrv = true;
mem.set(u8, ip_slice[index..], 0);
@memset(ip_slice[index..], 0);
ip_slice = tail[0..];
index = 0;
continue;
@ -416,7 +416,7 @@ pub const Ip6Address = extern struct {
index += 1;
ip_slice[index] = @truncate(u8, x);
index += 1;
mem.copy(u8, result.sa.addr[16 - index ..], ip_slice[0..index]);
@memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);
return result;
}
}
@ -465,7 +465,7 @@ pub const Ip6Address = extern struct {
if (!saw_any_digits) {
if (abbrv) return error.InvalidCharacter; // ':::'
if (i != 0) abbrv = true;
mem.set(u8, ip_slice[index..], 0);
@memset(ip_slice[index..], 0);
ip_slice = tail[0..];
index = 0;
continue;
@ -550,7 +550,7 @@ pub const Ip6Address = extern struct {
index += 1;
ip_slice[index] = @truncate(u8, x);
index += 1;
mem.copy(u8, result.sa.addr[16 - index ..], ip_slice[0..index]);
@memcpy(result.sa.addr[16 - index ..][0..index], ip_slice[0..index]);
return result;
}
}
@ -662,7 +662,7 @@ fn if_nametoindex(name: []const u8) !u32 {
var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
defer os.closeSocket(sockfd);
std.mem.copy(u8, &ifr.ifrn.name, name);
@memcpy(ifr.ifrn.name[0..name.len], name);
ifr.ifrn.name[name.len] = 0;
// TODO investigate if this needs to be integrated with evented I/O.
@ -676,7 +676,7 @@ fn if_nametoindex(name: []const u8) !u32 {
return error.NameTooLong;
var if_name: [os.IFNAMESIZE:0]u8 = undefined;
std.mem.copy(u8, &if_name, name);
@memcpy(if_name[0..name.len], name);
if_name[name.len] = 0;
const if_slice = if_name[0..name.len :0];
const index = os.system.if_nametoindex(if_slice);
@ -1041,14 +1041,14 @@ fn linuxLookupName(
var salen: os.socklen_t = undefined;
var dalen: os.socklen_t = undefined;
if (addr.addr.any.family == os.AF.INET6) {
mem.copy(u8, &da6.addr, &addr.addr.in6.sa.addr);
da6.addr = addr.addr.in6.sa.addr;
da = @ptrCast(*os.sockaddr, &da6);
dalen = @sizeOf(os.sockaddr.in6);
sa = @ptrCast(*os.sockaddr, &sa6);
salen = @sizeOf(os.sockaddr.in6);
} else {
mem.copy(u8, &sa6.addr, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");
mem.copy(u8, &da6.addr, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");
sa6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
da6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);
da4.addr = addr.addr.in.sa.addr;
da = @ptrCast(*os.sockaddr, &da4);
@ -1343,7 +1343,7 @@ fn linuxLookupNameFromDnsSearch(
// name is not a CNAME record) and serves as a buffer for passing
// the full requested name to name_from_dns.
try canon.resize(canon_name.len);
mem.copy(u8, canon.items, canon_name);
@memcpy(canon.items, canon_name);
try canon.append('.');
var tok_it = mem.tokenize(u8, search, " \t");
@ -1567,7 +1567,7 @@ fn resMSendRc(
for (0..ns.len) |i| {
if (ns[i].any.family != os.AF.INET) continue;
mem.writeIntNative(u32, ns[i].in6.sa.addr[12..], ns[i].in.sa.addr);
mem.copy(u8, ns[i].in6.sa.addr[0..12], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");
ns[i].in6.sa.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
ns[i].any.family = os.AF.INET6;
ns[i].in6.sa.flowinfo = 0;
ns[i].in6.sa.scope_id = 0;
@ -1665,7 +1665,7 @@ fn resMSendRc(
if (i == next) {
while (next < queries.len and answers[next].len != 0) : (next += 1) {}
} else {
mem.copy(u8, answer_bufs[i], answer_bufs[next][0..rlen]);
@memcpy(answer_bufs[i][0..rlen], answer_bufs[next][0..rlen]);
}
if (next == queries.len) break :outer;

View File

@ -1881,9 +1881,9 @@ pub fn execvpeZ_expandArg0(
while (it.next()) |search_path| {
const path_len = search_path.len + file_slice.len + 1;
if (path_buf.len < path_len + 1) return error.NameTooLong;
mem.copy(u8, &path_buf, search_path);
@memcpy(path_buf[0..search_path.len], search_path);
path_buf[search_path.len] = '/';
mem.copy(u8, path_buf[search_path.len + 1 ..], file_slice);
@memcpy(path_buf[search_path.len + 1 ..][0..file_slice.len], file_slice);
path_buf[path_len] = 0;
const full_path = path_buf[0..path_len :0].ptr;
switch (arg0_expand) {
@ -1917,7 +1917,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {
if (builtin.link_libc) {
var small_key_buf: [64]u8 = undefined;
if (key.len < small_key_buf.len) {
mem.copy(u8, &small_key_buf, key);
@memcpy(small_key_buf[0..key.len], key);
small_key_buf[key.len] = 0;
const key0 = small_key_buf[0..key.len :0];
return getenvZ(key0);
@ -2022,8 +2022,9 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
} else if (builtin.os.tag == .wasi and !builtin.link_libc) {
const path = ".";
if (out_buffer.len < path.len) return error.NameTooLong;
std.mem.copy(u8, out_buffer, path);
return out_buffer[0..path.len];
const result = out_buffer[0..path.len];
@memcpy(result, path);
return result;
}
const err = if (builtin.link_libc) blk: {
@ -2673,7 +2674,7 @@ pub fn renameatW(
.FileNameLength = @intCast(u32, new_path_w.len * 2), // already checked error.NameTooLong
.FileName = undefined,
};
std.mem.copy(u16, @as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);
@memcpy(@as([*]u16, &rename_info.FileName)[0..new_path_w.len], new_path_w);
var io_status_block: windows.IO_STATUS_BLOCK = undefined;
@ -5264,8 +5265,9 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
}
const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse MAX_PATH_BYTES;
if (len == 0) return error.NameTooLong;
mem.copy(u8, out_buffer, kfile.path[0..len]);
return out_buffer[0..len];
const result = out_buffer[0..len];
@memcpy(result, kfile.path[0..len]);
return result;
} else {
// This fallback implementation reimplements libutil's `kinfo_getfile()`.
// 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 {
if (kf.fd == fd) {
len = mem.indexOfScalar(u8, &kf.path, 0) orelse MAX_PATH_BYTES;
if (len == 0) return error.NameTooLong;
mem.copy(u8, out_buffer, kf.path[0..len]);
return out_buffer[0..len];
const result = out_buffer[0..len];
@memcpy(result, kf.path[0..len]);
return result;
}
i += @intCast(usize, kf.structsize);
}
@ -5686,8 +5689,9 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
if (builtin.os.tag == .linux) {
const uts = uname();
const hostname = mem.sliceTo(&uts.nodename, 0);
mem.copy(u8, name_buffer, hostname);
return name_buffer[0..hostname.len];
const result = name_buffer[0..hostname.len];
@memcpy(result, hostname);
return result;
}
@compileError("TODO implement gethostname for this OS");
@ -5725,7 +5729,7 @@ pub fn res_mkquery(
@memset(q[0..n], 0);
q[2] = @as(u8, op) * 8 + 1;
q[5] = 1;
mem.copy(u8, q[13..], name);
@memcpy(q[13..][0..name.len], name);
var i: usize = 13;
var j: usize = undefined;
while (q[i] != 0) : (i = j + 1) {
@ -5748,7 +5752,7 @@ pub fn res_mkquery(
q[0] = @truncate(u8, id / 256);
q[1] = @truncate(u8, id);
mem.copy(u8, buf, q[0..n]);
@memcpy(buf[0..n], q[0..n]);
return n;
}
@ -6755,7 +6759,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
var path_with_null: [MFD_MAX_NAME_LEN:0]u8 = undefined;
// >= rather than > to make room for the null byte
if (name.len >= MFD_MAX_NAME_LEN) return error.NameTooLong;
mem.copy(u8, &path_with_null, name);
@memcpy(path_with_null[0..name.len], name);
path_with_null[name.len] = 0;
return path_with_null;
}

View File

@ -1631,7 +1631,7 @@ test "map lookup, update, and delete" {
const status = try map_get_next_key(map, &lookup_key, &next_key);
try expectEqual(status, true);
try expectEqual(next_key, key);
std.mem.copy(u8, &lookup_key, &next_key);
lookup_key = next_key;
const status2 = try map_get_next_key(map, &lookup_key, &next_key);
try expectEqual(status2, false);

View File

@ -1855,8 +1855,8 @@ test "write_fixed/read_fixed" {
var raw_buffers: [2][11]u8 = undefined;
// First buffer will be written to the file.
std.mem.set(u8, &raw_buffers[0], 'z');
std.mem.copy(u8, &raw_buffers[0], "foobar");
@memset(&raw_buffers[0], 'z');
raw_buffers[0][0.."foobar".len].* = "foobar".*;
var buffers = [2]os.iovec{
.{ .iov_base = &raw_buffers[0], .iov_len = raw_buffers[0].len },
@ -2966,7 +2966,7 @@ test "provide_buffers: read" {
// Provide 1 buffer again
// Deliberately put something we don't expect in the buffers
mem.set(u8, mem.sliceAsBytes(&buffers), 42);
@memset(mem.sliceAsBytes(&buffers), 42);
const reprovided_buffer_id = 2;
@ -3155,7 +3155,7 @@ test "provide_buffers: accept/connect/send/recv" {
// Do 4 recv which should consume all buffers
// Deliberately put something we don't expect in the buffers
mem.set(u8, mem.sliceAsBytes(&buffers), 1);
@memset(mem.sliceAsBytes(&buffers), 1);
var i: usize = 0;
while (i < buffers.len) : (i += 1) {
@ -3235,7 +3235,7 @@ test "provide_buffers: accept/connect/send/recv" {
// Final recv which should work
// Deliberately put something we don't expect in the buffers
mem.set(u8, mem.sliceAsBytes(&buffers), 1);
@memset(mem.sliceAsBytes(&buffers), 1);
{
var sqe = try ring.recv(0xdfdfdfdf, socket_test_harness.client, .{ .buffer_selection = .{ .group_id = group_id, .len = buffer_len } }, 0);

Some files were not shown because too many files have changed in this diff Show More