[Xfce4-commits] [xfce/xfdesktop] 19/19: Fix for extra blank lines in backdrop list (Bug #10763)

noreply at xfce.org noreply at xfce.org
Sun Nov 9 15:37:01 CET 2014


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch xfce-4.10
in repository xfce/xfdesktop.

commit 09b74b7822a60292b05f69ff86cc410a25b5724c
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Mon Nov 3 16:42:52 2014 +0300

    Fix for extra blank lines in backdrop list (Bug #10763)
    
    If xfdesktop-settings contains multiple blank lines it would cause
    an infinite loop in the loader code, this patch fixes that.
---
 common/xfdesktop-common.c |   43 ++++++++++++++++++-------------------------
 settings/main.c           |    2 ++
 2 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/common/xfdesktop-common.c b/common/xfdesktop-common.c
index 64aee8d..2b8e80b 100644
--- a/common/xfdesktop-common.c
+++ b/common/xfdesktop-common.c
@@ -81,9 +81,9 @@ xfdesktop_backdrop_list_load(const gchar *filename,
                              gint *n_items,
                              GError **error)
 {
-    gchar *contents = NULL, **files = NULL, *p, *q;
+    gchar *contents = NULL, **files = NULL;
     gsize length = 0;
-    gint arr_size = 10, count = 0;
+    gint i, items;
 
     g_return_val_if_fail(filename && (!error || !*error), NULL);
 
@@ -99,33 +99,26 @@ xfdesktop_backdrop_list_load(const gchar *filename,
         return NULL;
     }
 
-    /* i'd use g_strsplit() here, but then counting is slower.  we can
-     * also filter out blank lines */
-    files = g_malloc(sizeof(gchar *) * (arr_size+1));
-    p = contents + sizeof(LIST_TEXT);
-    while(p && *p) {
-        q = strstr(p, "\n");
-        if(q) {
-            if(p == q)  /* blank line */
-                continue;
-            *q = 0;
-        } else
-            q = contents + length;  /* assume no trailing '\n' at EOF */
-
-        if(count == arr_size) {
-            arr_size += 10;
-            files = g_realloc(files, sizeof(gchar *) * (arr_size+1));
+    items = 0;
+    files = g_strsplit(contents, "\n", -1);
+
+    /* Since the first line is the file identifier, we need to skip it.
+     * Additionally, we want to skip blank lines. */
+    for(i = 1; files[i] != NULL; i++) {
+        if(g_strcmp0(files[i], "") != 0) {
+            g_free(files[items]);
+            files[items] = g_strdup(files[i]);
+            DBG("files[items] %s", files[items]);
+            items++;
         }
-
-        files[count++] = g_strdup(p);
-        if(q != contents + length)
-            p = q + 1;
     }
-    files[count] = NULL;
-    files = g_realloc(files, sizeof(gchar *) * (count+1));
+    files[items+1] = NULL;
+
+    files = g_realloc(files, sizeof(gchar *) * (items+1));
 
+    DBG("items %d", items);
     if(n_items)
-        *n_items = count;
+        *n_items = items;
 
     g_free(contents);
 
diff --git a/settings/main.c b/settings/main.c
index 3d6166f..3d52c80 100644
--- a/settings/main.c
+++ b/settings/main.c
@@ -568,6 +568,7 @@ xfdesktop_settings_dialog_create_load_list(AppearancePanel *panel)
         gtk_main_iteration();
 
     if(!xfdesktop_settings_ensure_backdrop_list(list_file, parent)) {
+        g_warning ("backdrop list is not valid");
         g_free(list_file);
         return NULL;
     }
@@ -660,6 +661,7 @@ xfdesktop_settings_dialog_populate_image_list(AppearancePanel *panel)
 
             for(i = 0; images[i]; ++i) {
                 GtkTreeIter *iter = xfdesktop_settings_image_treeview_add(GTK_TREE_MODEL(ls), images[i]);
+                DBG("adding images[i] %s", images[i]);
                 if(iter)
                     gtk_tree_iter_free(iter);
             }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list