From 4e0433f77fbcf534f7033e50b36fb13f364aa3af Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 30 Dec 2024 21:30:30 -0800 Subject: [PATCH] config: fix segfault if font-family is reset via the CLI Fixes #4149 --- src/config/Config.zig | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index 7d9c7d8cc..91c07cc78 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -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; + } } } }