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 {...@@ -1364,20 +1364,20 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
1364 );1364 );
1365}1365}
13661366
1367fn nextArg(args: [][:0]const u8, idx: *usize) ?[:0]const u8 {1367fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 {
1368 if (idx.* >= args.len) return null;1368 if (idx.* >= args.len) return null;
1369 defer idx.* += 1;1369 defer idx.* += 1;
1370 return args[idx.*];1370 return args[idx.*];
1371}1371}
13721372
1373fn nextArgOrFatal(args: [][:0]const u8, idx: *usize) [:0]const u8 {1373fn nextArgOrFatal(args: []const [:0]const u8, idx: *usize) [:0]const u8 {
1374 return nextArg(args, idx) orelse {1374 return nextArg(args, idx) orelse {
1375 std.debug.print("expected argument after '{s}'\n access the help menu with 'zig build -h'\n", .{args[idx.* - 1]});1375 std.debug.print("expected argument after '{s}'\n access the help menu with 'zig build -h'\n", .{args[idx.* - 1]});
1376 process.exit(1);1376 process.exit(1);
1377 };1377 };
1378}1378}
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 {
1381 if (idx >= args.len) return null;1381 if (idx >= args.len) return null;
1382 return args[idx..];1382 return args[idx..];
1383}1383}
src/clang.zig+2-2
...@@ -2224,8 +2224,8 @@ pub const ErrorMsg = extern struct {...@@ -2224,8 +2224,8 @@ pub const ErrorMsg = extern struct {
22242224
2225pub const LoadFromCommandLine = ZigClangLoadFromCommandLine;2225pub const LoadFromCommandLine = ZigClangLoadFromCommandLine;
2226extern fn ZigClangLoadFromCommandLine(2226extern fn ZigClangLoadFromCommandLine(
2227 args_begin: [*]?[*]const u8,2227 args_begin: [*]?[*:0]const u8,
2228 args_end: [*]?[*]const u8,2228 args_end: [*]?[*:0]const u8,
2229 errors_ptr: *[*]ErrorMsg,2229 errors_ptr: *[*]ErrorMsg,
2230 errors_len: *usize,2230 errors_len: *usize,
2231 resources_path: [*:0]const u8,2231 resources_path: [*:0]const u8,
src/link/Coff.zig+1-1
...@@ -997,7 +997,7 @@ fn markRelocsDirtyByAddress(coff: *Coff, addr: u32) void {...@@ -997,7 +997,7 @@ fn markRelocsDirtyByAddress(coff: *Coff, addr: u32) void {
997 }997 }
998}998}
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 {
1001 log.debug("relocating '{s}'", .{coff.getAtom(atom_index).getName(coff)});1001 log.debug("relocating '{s}'", .{coff.getAtom(atom_index).getName(coff)});
1002 for (relocs) |reloc| {1002 for (relocs) |reloc| {
1003 reloc.resolve(atom_index, code, image_base, coff);1003 reloc.resolve(atom_index, code, image_base, coff);
src/translate_c.zig+2-2
...@@ -79,8 +79,8 @@ pub const Context = struct {...@@ -79,8 +79,8 @@ pub const Context = struct {
7979
80pub fn translate(80pub fn translate(
81 gpa: mem.Allocator,81 gpa: mem.Allocator,
82 args_begin: [*]?[*]const u8,82 args_begin: [*]?[*:0]const u8,
83 args_end: [*]?[*]const u8,83 args_end: [*]?[*:0]const u8,
84 errors: *std.zig.ErrorBundle,84 errors: *std.zig.ErrorBundle,
85 resources_path: [*:0]const u8,85 resources_path: [*:0]const u8,
86) !std.zig.Ast {86) !std.zig.Ast {