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:
mlugg 2024-12-15 15:10:51 +00:00
parent f154cd1fdc
commit 3e9810266b
No known key found for this signature in database
GPG key ID: 3F5B7DCCBF4AF02E
4 changed files with 8 additions and 8 deletions

View file

@ -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..];
} }

View file

@ -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,

View file

@ -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);

View file

@ -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 {