From 4ab4f247e4023a7c489547bcc14ebdb00470c289 Mon Sep 17 00:00:00 2001 From: Alexander Babikov <2708460+lemondrops@users.noreply.github.com> Date: Sun, 18 Sep 2022 04:29:57 +0500 Subject: [PATCH] Fix a crash when saving window dimensions and coordinates --- src/config.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index f9fa81945..6212871be 100644 --- a/src/config.c +++ b/src/config.c @@ -2050,10 +2050,13 @@ save_general(void) static void save_monitor(int monitor_index) { - char cat[sizeof("Monitor #") + 12] = { [0] = 0 }; - char temp[512]; + ini_section_t cat; + char name[sizeof("Monitor #") + 12] = { [0] = 0 }; + char temp[512]; + + snprintf(name, sizeof(name), "Monitor #%i", monitor_index + 1); + cat = ini_find_or_create_section(config, name); - snprintf(cat, sizeof(cat), "Monitor #%i", monitor_index + 1); if (window_remember) { sprintf(temp, "%i, %i, %i, %i", monitor_settings[monitor_index].mon_window_x, monitor_settings[monitor_index].mon_window_y, @@ -2069,6 +2072,8 @@ save_monitor(int monitor_index) ini_section_delete_var(cat, "window_coordinates"); ini_section_delete_var(cat, "window_maximized"); } + + ini_delete_section_if_empty(config, cat); } /* Save "Machine" section. */