authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-15 15:10:51+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-16 14:53:54+00:00
log3e9810266bf9ce8aa79cfa330efedb1c550ad721
tree9a3a0e0fa17568b7227d5eeeb796e851ca46ec92
parentf154cd1fdc748c3f9c1c499347c7c0b26f0d3e19
signaturelock-open Commit is signed but in an unrecognized format.

compiler: add some missing `const`s

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!

4 files changed, 8 insertions(+), 8 deletions(-)

lib/compiler/build_runner.zig+3-3
......@@ -1364,20 +1364,20 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
13641364 );
13651365}
13661366
1367fn nextArg(args: [][:0]const u8, idx: *usize) ?[:0]const u8 {
1367fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 {
13681368 if (idx.* >= args.len) return null;
13691369 defer idx.* += 1;
13701370 return args[idx.*];
13711371}
13721372
1373fn nextArgOrFatal(args: [][:0]const u8, idx: *usize) [:0]const u8 {
1373fn nextArgOrFatal(args: []const [:0]const u8, idx: *usize) [:0]const u8 {
13741374 return nextArg(args, idx) orelse {
13751375 std.debug.print("expected argument after '{s}'\n access the help menu with 'zig build -h'\n", .{args[idx.* - 1]});
13761376 process.exit(1);
13771377 };
13781378}
13791379
1380fn argsRest(args: [][:0]const u8, idx: usize) ?[][:0]const u8 {
1380fn argsRest(args: []const [:0]const u8, idx: usize) ?[]const [:0]const u8 {
13811381 if (idx >= args.len) return null;
13821382 return args[idx..];
13831383}
src/clang.zig+2-2
......@@ -2224,8 +2224,8 @@ pub const ErrorMsg = extern struct {
22242224
22252225pub const LoadFromCommandLine = ZigClangLoadFromCommandLine;
22262226extern fn ZigClangLoadFromCommandLine(
2227 args_begin: [*]?[*]const u8,
2228 args_end: [*]?[*]const u8,
2227 args_begin: [*]?[*:0]const u8,
2228 args_end: [*]?[*:0]const u8,
22292229 errors_ptr: *[*]ErrorMsg,
22302230 errors_len: *usize,
22312231 resources_path: [*:0]const u8,
src/link/Coff.zig+1-1
......@@ -997,7 +997,7 @@ fn markRelocsDirtyByAddress(coff: *Coff, addr: u32) void {
997997 }
998998}
999999
1000fn resolveRelocs(coff: *Coff, atom_index: Atom.Index, relocs: []*const Relocation, code: []u8, image_base: u64) void {
1000fn resolveRelocs(coff: *Coff, atom_index: Atom.Index, relocs: []const *const Relocation, code: []u8, image_base: u64) void {
10011001 log.debug("relocating '{s}'", .{coff.getAtom(atom_index).getName(coff)});
10021002 for (relocs) |reloc| {
10031003 reloc.resolve(atom_index, code, image_base, coff);
src/translate_c.zig+2-2
......@@ -79,8 +79,8 @@ pub const Context = struct {
7979
8080pub fn translate(
8181 gpa: mem.Allocator,
82 args_begin: [*]?[*]const u8,
83 args_end: [*]?[*]const u8,
82 args_begin: [*]?[*:0]const u8,
83 args_end: [*]?[*:0]const u8,
8484 errors: *std.zig.ErrorBundle,
8585 resources_path: [*:0]const u8,
8686) !std.zig.Ast {