summaryrefslogtreecommitdiff
path: root/src/cli/args.zig
diff options
context:
space:
mode:
authorMitchell Hashimoto <m@mitchellh.com>2024-11-27 08:46:03 -0800
committerMitchell Hashimoto <m@mitchellh.com>2024-11-27 08:46:47 -0800
commit5b01cb353de47a0053c313e3bc20170cbece679e (patch)
treeca0b99796f8213c9215496500afd051413fc0757 /src/cli/args.zig
parent466d094c18729fc49501f48dc6b283aed72362af (diff)
config: need to dupe filepath for diagnostics
Fixes #2800 The source string with the filepath is not guaranteed to exist beyond the lifetime of the parse operation. We must copy it.
Diffstat (limited to 'src/cli/args.zig')
-rw-r--r--src/cli/args.zig13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/cli/args.zig b/src/cli/args.zig
index 3e378f347..454ca360e 100644
--- a/src/cli/args.zig
+++ b/src/cli/args.zig
@@ -104,7 +104,7 @@ pub fn parse(
try dst._diagnostics.append(arena_alloc, .{
.key = try arena_alloc.dupeZ(u8, arg),
.message = "invalid field",
- .location = diags.Location.fromIter(iter),
+ .location = try diags.Location.fromIter(iter, arena_alloc),
});
continue;
@@ -145,7 +145,7 @@ pub fn parse(
try dst._diagnostics.append(arena_alloc, .{
.key = try arena_alloc.dupeZ(u8, key),
.message = message,
- .location = diags.Location.fromIter(iter),
+ .location = try diags.Location.fromIter(iter, arena_alloc),
});
};
}
@@ -1140,7 +1140,7 @@ pub fn ArgsIterator(comptime Iterator: type) type {
}
/// Returns a location for a diagnostic message.
- pub fn location(self: *const Self) ?diags.Location {
+ pub fn location(self: *const Self, _: Allocator) error{}!?diags.Location {
return .{ .cli = self.index };
}
};
@@ -1262,12 +1262,15 @@ pub fn LineIterator(comptime ReaderType: type) type {
}
/// Returns a location for a diagnostic message.
- pub fn location(self: *const Self) ?diags.Location {
+ pub fn location(
+ self: *const Self,
+ alloc: Allocator,
+ ) Allocator.Error!?diags.Location {
// If we have no filepath then we have no location.
if (self.filepath.len == 0) return null;
return .{ .file = .{
- .path = self.filepath,
+ .path = try alloc.dupe(u8, self.filepath),
.line = self.line,
} };
}