mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
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.
This commit is contained in:
@ -104,7 +104,7 @@ pub fn parse(
|
|||||||
try dst._diagnostics.append(arena_alloc, .{
|
try dst._diagnostics.append(arena_alloc, .{
|
||||||
.key = try arena_alloc.dupeZ(u8, arg),
|
.key = try arena_alloc.dupeZ(u8, arg),
|
||||||
.message = "invalid field",
|
.message = "invalid field",
|
||||||
.location = diags.Location.fromIter(iter),
|
.location = try diags.Location.fromIter(iter, arena_alloc),
|
||||||
});
|
});
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -145,7 +145,7 @@ pub fn parse(
|
|||||||
try dst._diagnostics.append(arena_alloc, .{
|
try dst._diagnostics.append(arena_alloc, .{
|
||||||
.key = try arena_alloc.dupeZ(u8, key),
|
.key = try arena_alloc.dupeZ(u8, key),
|
||||||
.message = message,
|
.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.
|
/// 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 };
|
return .{ .cli = self.index };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1262,12 +1262,15 @@ pub fn LineIterator(comptime ReaderType: type) type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a location for a diagnostic message.
|
/// 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 we have no filepath then we have no location.
|
||||||
if (self.filepath.len == 0) return null;
|
if (self.filepath.len == 0) return null;
|
||||||
|
|
||||||
return .{ .file = .{
|
return .{ .file = .{
|
||||||
.path = self.filepath,
|
.path = try alloc.dupe(u8, self.filepath),
|
||||||
.line = self.line,
|
.line = self.line,
|
||||||
} };
|
} };
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ pub const Location = union(enum) {
|
|||||||
|
|
||||||
pub const Key = @typeInfo(Location).Union.tag_type.?;
|
pub const Key = @typeInfo(Location).Union.tag_type.?;
|
||||||
|
|
||||||
pub fn fromIter(iter: anytype) Location {
|
pub fn fromIter(iter: anytype, alloc: Allocator) Allocator.Error!Location {
|
||||||
const Iter = t: {
|
const Iter = t: {
|
||||||
const T = @TypeOf(iter);
|
const T = @TypeOf(iter);
|
||||||
break :t switch (@typeInfo(T)) {
|
break :t switch (@typeInfo(T)) {
|
||||||
@ -67,7 +67,7 @@ pub const Location = union(enum) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!@hasDecl(Iter, "location")) return .none;
|
if (!@hasDecl(Iter, "location")) return .none;
|
||||||
return iter.location() orelse .none;
|
return (try iter.location(alloc)) orelse .none;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone(self: *const Location, alloc: Allocator) Allocator.Error!Location {
|
pub fn clone(self: *const Location, alloc: Allocator) Allocator.Error!Location {
|
||||||
|
@ -2988,7 +2988,7 @@ pub fn parseManuallyHook(
|
|||||||
|
|
||||||
if (command.items.len == 0) {
|
if (command.items.len == 0) {
|
||||||
try self._diagnostics.append(alloc, .{
|
try self._diagnostics.append(alloc, .{
|
||||||
.location = cli.Location.fromIter(iter),
|
.location = try cli.Location.fromIter(iter, alloc),
|
||||||
.message = try std.fmt.allocPrintZ(
|
.message = try std.fmt.allocPrintZ(
|
||||||
alloc,
|
alloc,
|
||||||
"missing command after {s}",
|
"missing command after {s}",
|
||||||
|
Reference in New Issue
Block a user