From 5f604460ef26e846494522502d22cb7b56ec6b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 12 Oct 2022 15:57:48 +0200 Subject: [PATCH] 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 68618fb1c..4b57d02a2 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);