config: fix segfault if font-family is reset via the CLI

Fixes #4149
This commit is contained in:
Mitchell Hashimoto
2024-12-30 21:30:30 -08:00
committed by Jonathan Lopez
parent 3ba8d7f8fb
commit 4e0433f77f

View File

@ -2843,17 +2843,21 @@ pub fn loadCliArgs(self: *Config, alloc_gpa: Allocator) !void {
// replace the entire list with the new list.
inline for (fields, 0..) |field, i| {
const v = &@field(self, field);
const len = v.list.items.len - counter[i];
if (len > 0) {
// Note: we don't have to worry about freeing the memory
// that we overwrite or cut off here because its all in
// an arena.
v.list.replaceRangeAssumeCapacity(
0,
len,
v.list.items[counter[i]..],
);
v.list.items.len = len;
// The list can be empty if it was reset, i.e. --font-family=""
if (v.list.items.len > 0) {
const len = v.list.items.len - counter[i];
if (len > 0) {
// Note: we don't have to worry about freeing the memory
// that we overwrite or cut off here because its all in
// an arena.
v.list.replaceRangeAssumeCapacity(
0,
len,
v.list.items[counter[i]..],
);
v.list.items.len = len;
}
}
}
}