commit 3e9810266bf9ce8aa79cfa330efedb1c550ad721 (tree)
parent f154cd1fdc748c3f9c1c499347c7c0b26f0d3e19
Author: mlugg <mlugg@mlugg.co.uk>
Date: Sun, 15 Dec 2024 15:10:51 +0000
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!
Diffstat:
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig
@@ -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;
defer idx.* += 1;
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 {
std.debug.print("expected argument after '{s}'\n access the help menu with 'zig build -h'\n", .{args[idx.* - 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;
return args[idx..];
}
diff --git a/src/clang.zig b/src/clang.zig
@@ -2224,8 +2224,8 @@ pub const ErrorMsg = extern struct {
pub const LoadFromCommandLine = ZigClangLoadFromCommandLine;
extern fn ZigClangLoadFromCommandLine(
- args_begin: [*]?[*]const u8,
- args_end: [*]?[*]const u8,
+ args_begin: [*]?[*:0]const u8,
+ args_end: [*]?[*:0]const u8,
errors_ptr: *[*]ErrorMsg,
errors_len: *usize,
resources_path: [*:0]const u8,
diff --git a/src/link/Coff.zig b/src/link/Coff.zig
@@ -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)});
for (relocs) |reloc| {
reloc.resolve(atom_index, code, image_base, coff);
diff --git a/src/translate_c.zig b/src/translate_c.zig
@@ -79,8 +79,8 @@ pub const Context = struct {
pub fn translate(
gpa: mem.Allocator,
- args_begin: [*]?[*]const u8,
- args_end: [*]?[*]const u8,
+ args_begin: [*]?[*:0]const u8,
+ args_end: [*]?[*:0]const u8,
errors: *std.zig.ErrorBundle,
resources_path: [*:0]const u8,
) !std.zig.Ast {