Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Nov 27, 2023
1 parent 0036076 commit fd5d896
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion deps/aro/aro/Type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub const Attributed = struct {
errdefer allocator.destroy(attributed_type);

const all_attrs = try allocator.alloc(Attribute, existing_attributes.len + attributes.len);
@memcpy(all_attrs, existing_attributes);
@memcpy(all_attrs[0..existing_attributes.len], existing_attributes);
@memcpy(all_attrs[existing_attributes.len..], attributes);

attributed_type.* = .{
Expand Down
2 changes: 1 addition & 1 deletion doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -10509,7 +10509,7 @@ test "using an allocator" {

fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 {
const result = try allocator.alloc(u8, a.len + b.len);
@memcpy(result, a);
@memcpy(result[0..a.len], a);
@memcpy(result[a.len..], b);
return result;
}
Expand Down
10 changes: 4 additions & 6 deletions lib/std/mem.zig
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void {
}
}

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
/// interfacing with a C API where this practice is more common and relied upon. If you are performing code review and see this
Expand Down Expand Up @@ -2948,12 +2946,12 @@ fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []con
const buf = try allocator.alloc(u8, total_len);
errdefer allocator.free(buf);

@memcpy(buf, slices[0]);
@memcpy(buf[0..slices[0].len], slices[0]);
var buf_index: usize = slices[0].len;
for (slices[1..]) |slice| {
@memcpy(buf[buf_index..], separator);
@memcpy(buf[buf_index .. buf_index + separator.len], separator);
buf_index += separator.len;
@memcpy(buf[buf_index..], slice);
@memcpy(buf[buf_index .. buf_index + slice.len], slice);
buf_index += slice.len;
}

Expand Down Expand Up @@ -3046,7 +3044,7 @@ pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []con

var buf_index: usize = 0;
for (slices) |slice| {
@memcpy(buf[buf_index..], slice);
@memcpy(buf[buf_index .. buf_index + slice.len], slice);
buf_index += slice.len;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/std/os/windows/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn RtlDosPathNameToNtPathName_U(path: [:0]const u16) !windows.PathSpace {

var path_space: windows.PathSpace = undefined;
const out_path = out.Buffer[0 .. out.Length / 2];
@memcpy(path_space.data[0..], out_path);
@memcpy(path_space.data[0..out_path.len], out_path);
path_space.len = out.Length / 2;
path_space.data[path_space.len] = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/resinator/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub const Options = struct {
cwd.access(options.input_filename, .{}) catch |err| switch (err) {
error.FileNotFound => {
var filename_bytes = try options.allocator.alloc(u8, options.input_filename.len + 3);
@memcpy(filename_bytes, options.input_filename);
@memcpy(filename_bytes[0 .. filename_bytes.len - 3], options.input_filename);
@memcpy(filename_bytes[filename_bytes.len - 3 ..], ".rc");
options.allocator.free(options.input_filename);
options.input_filename = filename_bytes;
Expand Down
2 changes: 1 addition & 1 deletion src/resinator/lang.zig
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ test "exhaustive tagToId" {
writer.writeAll(parsed_sort.suffix.?) catch unreachable;
const expected_field_name = comptime field: {
var name_buf: [5]u8 = undefined;
@memcpy(&name_buf, parsed_sort.language_code);
@memcpy(&name_buf[0..parsed_sort.language_code.len], parsed_sort.language_code);
name_buf[2] = '_';
@memcpy(name_buf[3..], parsed_sort.country_code.?);
break :field name_buf;
Expand Down
2 changes: 1 addition & 1 deletion src/resinator/source_mapping.zig
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ pub const SourceMappings = struct {

const after_collapsed_start = line_num + num_following_lines_to_collapse;
const new_num_lines = self.mapping.items.len - num_following_lines_to_collapse;
@memcpy(self.mapping.items[line_num..new_num_lines], self.mapping.items[after_collapsed_start..]);
std.mem.copyForwards(SourceSpan, self.mapping.items[line_num..new_num_lines], self.mapping.items[after_collapsed_start..]);

self.mapping.items.len = new_num_lines;
}
Expand Down
3 changes: 2 additions & 1 deletion test/behavior/ptrcast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ test "comptime @ptrCast a subset of an array, then write through it" {
var buff: [16]u8 align(4) = undefined;
const len_bytes = @as(*u32, @ptrCast(&buff));
len_bytes.* = 16;
@memcpy(buff[4..], "abcdef");
const source = "abcdef";
@memcpy(buff[4 .. 4 + source.len], source);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/behavior/threadlocal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test "pointer to thread local array" {
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO

const s = "Hello world";
@memcpy(buffer[0..], s);
@memcpy(buffer[0..s.len], s);
try std.testing.expectEqualSlices(u8, buffer[0..], s);
}

Expand Down
4 changes: 2 additions & 2 deletions tools/update-license-headers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub fn main() !void {
const truncated_source = source[expected_header.len..];

const new_source = try arena.alloc(u8, truncated_source.len + new_header.len);
@memcpy(new_source, new_header);
@memcpy(new_source[new_header.len..], truncated_source);
@memcpy(new_source[0..new_source.len], new_header);
@memcpy(new_source[new_header.len .. new_header.len + truncated_source], truncated_source);

try dir.writeFile(entry.path, new_source);
}
Expand Down

0 comments on commit fd5d896

Please sign in to comment.