[glib: 1/4] gbookmarkfile: Do not try to write invalid modified stamp




commit 5f604460ef26e846494522502d22cb7b56ec6b56
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Wed Oct 12 15:57:48 2022 +0200

    gbookmarkfile: Do not try to write invalid modified stamp
    
    In some bookmarks that we load the modified value may be not set, while
    this may lead to a load error, we still can dump such file and this
    would fail as we try to get a string from an invalid time.
    
    Avoid this, because it would also lead to not writing a valid count
    value, given that we'd pass NULL to g_strconcat too early.

 glib/gbookmarkfile.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/glib/gbookmarkfile.c b/glib/gbookmarkfile.c
index 68618fb1c1..4b57d02a28 100644
--- a/glib/gbookmarkfile.c
+++ b/glib/gbookmarkfile.c
@@ -300,14 +300,27 @@ bookmark_app_info_dump (BookmarkAppInfo *app_info)
 
   name = g_markup_escape_text (app_info->name, -1);
   exec = g_markup_escape_text (app_info->exec, -1);
-  modified = g_date_time_format_iso8601 (app_info->stamp);
   count = g_strdup_printf ("%u", app_info->count);
 
+  if (app_info->stamp)
+    {
+      char *tmp;
+
+      tmp = g_date_time_format_iso8601 (app_info->stamp);
+      modified = g_strconcat (" " BOOKMARK_MODIFIED_ATTRIBUTE "=\"", tmp, "\"",
+                              NULL);
+      g_free (tmp);
+    }
+  else
+    {
+      modified = g_strdup ("");
+    }
+
   retval = g_strconcat ("          "
                         "<" BOOKMARK_NAMESPACE_NAME ":" BOOKMARK_APPLICATION_ELEMENT
                         " " BOOKMARK_NAME_ATTRIBUTE "=\"", name, "\""
-                        " " BOOKMARK_EXEC_ATTRIBUTE "=\"", exec, "\""
-                        " " BOOKMARK_MODIFIED_ATTRIBUTE "=\"", modified, "\""
+                        " " BOOKMARK_EXEC_ATTRIBUTE "=\"", exec, "\"",
+                        modified,
                         " " BOOKMARK_COUNT_ATTRIBUTE "=\"", count, "\"/>\n",
                         NULL);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]