mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
compiler: add some missing consts
The previous commit exposed some missing `const` qualifiers in a few places. These mutable slices could have been used to store invalid values into memory!
This commit is contained in:
parent
f154cd1fdc
commit
3e9810266b
@ -1364,20 +1364,20 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nextArg(args: [][:0]const u8, idx: *usize) ?[:0]const u8 {
|
fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 {
|
||||||
if (idx.* >= args.len) return null;
|
if (idx.* >= args.len) return null;
|
||||||
defer idx.* += 1;
|
defer idx.* += 1;
|
||||||
return args[idx.*];
|
return args[idx.*];
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nextArgOrFatal(args: [][:0]const u8, idx: *usize) [:0]const u8 {
|
fn nextArgOrFatal(args: []const [:0]const u8, idx: *usize) [:0]const u8 {
|
||||||
return nextArg(args, idx) orelse {
|
return nextArg(args, idx) orelse {
|
||||||
std.debug.print("expected argument after '{s}'\n access the help menu with 'zig build -h'\n", .{args[idx.* - 1]});
|
std.debug.print("expected argument after '{s}'\n access the help menu with 'zig build -h'\n", .{args[idx.* - 1]});
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn argsRest(args: [][:0]const u8, idx: usize) ?[][:0]const u8 {
|
fn argsRest(args: []const [:0]const u8, idx: usize) ?[]const [:0]const u8 {
|
||||||
if (idx >= args.len) return null;
|
if (idx >= args.len) return null;
|
||||||
return args[idx..];
|
return args[idx..];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2224,8 +2224,8 @@ pub const ErrorMsg = extern struct {
|
|||||||
|
|
||||||
pub const LoadFromCommandLine = ZigClangLoadFromCommandLine;
|
pub const LoadFromCommandLine = ZigClangLoadFromCommandLine;
|
||||||
extern fn ZigClangLoadFromCommandLine(
|
extern fn ZigClangLoadFromCommandLine(
|
||||||
args_begin: [*]?[*]const u8,
|
args_begin: [*]?[*:0]const u8,
|
||||||
args_end: [*]?[*]const u8,
|
args_end: [*]?[*:0]const u8,
|
||||||
errors_ptr: *[*]ErrorMsg,
|
errors_ptr: *[*]ErrorMsg,
|
||||||
errors_len: *usize,
|
errors_len: *usize,
|
||||||
resources_path: [*:0]const u8,
|
resources_path: [*:0]const u8,
|
||||||
|
|||||||
@ -997,7 +997,7 @@ fn markRelocsDirtyByAddress(coff: *Coff, addr: u32) void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolveRelocs(coff: *Coff, atom_index: Atom.Index, relocs: []*const Relocation, code: []u8, image_base: u64) void {
|
fn resolveRelocs(coff: *Coff, atom_index: Atom.Index, relocs: []const *const Relocation, code: []u8, image_base: u64) void {
|
||||||
log.debug("relocating '{s}'", .{coff.getAtom(atom_index).getName(coff)});
|
log.debug("relocating '{s}'", .{coff.getAtom(atom_index).getName(coff)});
|
||||||
for (relocs) |reloc| {
|
for (relocs) |reloc| {
|
||||||
reloc.resolve(atom_index, code, image_base, coff);
|
reloc.resolve(atom_index, code, image_base, coff);
|
||||||
|
|||||||
@ -79,8 +79,8 @@ pub const Context = struct {
|
|||||||
|
|
||||||
pub fn translate(
|
pub fn translate(
|
||||||
gpa: mem.Allocator,
|
gpa: mem.Allocator,
|
||||||
args_begin: [*]?[*]const u8,
|
args_begin: [*]?[*:0]const u8,
|
||||||
args_end: [*]?[*]const u8,
|
args_end: [*]?[*:0]const u8,
|
||||||
errors: *std.zig.ErrorBundle,
|
errors: *std.zig.ErrorBundle,
|
||||||
resources_path: [*:0]const u8,
|
resources_path: [*:0]const u8,
|
||||||
) !std.zig.Ast {
|
) !std.zig.Ast {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user