From d21b73e5ffabb1bd82e01f6723c038123c5886a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Bonithon?= Date: Tue, 9 Apr 2024 23:02:10 +0200 Subject: [PATCH] process-tree-view: Reset /columns/positions at startup if invalid This can happen if from one version to the next the number of columns has changed, and of course if invalid data is somehow put into the xfconf property. --- src/process-tree-view.c | 44 ++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/process-tree-view.c b/src/process-tree-view.c index 828518a..ffa2230 100644 --- a/src/process-tree-view.c +++ b/src/process-tree-view.c @@ -320,24 +320,46 @@ columns_changed (XtmProcessTreeView *treeview) static void read_columns_positions (XtmProcessTreeView *treeview) { - gushort i; gchar *columns_positions; - gchar **columns_positions_split; + gboolean valid_setting; g_object_get (treeview->settings, "columns-positions", &columns_positions, NULL); + valid_setting = columns_positions != NULL; - if (columns_positions == NULL) + if (valid_setting) { - for (i = 0; i < N_COLUMNS; i++) - treeview->columns_positions[i] = i; - } - else - { - columns_positions_split = g_strsplit (columns_positions, ";", N_COLUMNS + 1); - for (i = 0; i < N_COLUMNS && columns_positions_split[i] != NULL; i++) - treeview->columns_positions[i] = (gushort)g_ascii_strtoll (columns_positions_split[i], NULL, 10); + gchar **columns_positions_split = g_strsplit (columns_positions, ";", -1); + valid_setting = g_strv_length (columns_positions_split) == N_COLUMNS + 1; + if (valid_setting) + { + for (gint i = 0; i < N_COLUMNS; i++) + { + gchar *end; + gushort position = g_ascii_strtoull (columns_positions_split[i], &end, 10); + if (*end != '\0' || position >= N_COLUMNS) + { + valid_setting = FALSE; + break; + } + + treeview->columns_positions[i] = position; + } + } g_strfreev (columns_positions_split); g_free (columns_positions); + + if (!valid_setting) + { + XfconfChannel *channel = xfconf_channel_get (CHANNEL); + g_warning ("Invalid list of column positions, reset Xfconf property /columns/positions"); + xfconf_channel_reset_property (channel, "/columns/positions", TRUE); + } + } + + if (!valid_setting) + { + for (gint i = 0; i < N_COLUMNS; i++) + treeview->columns_positions[i] = i; } }