From 9bd8a8a1346a80cada1d311bd97bdf8ecccbf7ad Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 14 Nov 2020 21:11:33 +0100 Subject: [PATCH] libgimpbase: do not use g_snprintf() with same source and buffer. `man snprintf` clearly says (in NOTES) that when source and target overlap, the result in undefined. g_snprintf() conforms to the same standard hence would not get the expected result. In my case, the result was just tzstr (e.g. "+01:00"). (cherry picked from commit 435d5ce83a8d9d1899bff767768afc903f822687) --- libgimpbase/gimpmetadata.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/libgimpbase/gimpmetadata.c b/libgimpbase/gimpmetadata.c index 3e600c536c..e62689b5c4 100644 --- a/libgimpbase/gimpmetadata.c +++ b/libgimpbase/gimpmetadata.c @@ -285,21 +285,22 @@ void gimp_metadata_add_xmp_history (GimpMetadata *metadata, gchar *state_status) { - time_t now; - struct tm* now_tm; - char timestr[256]; - char tzstr[7]; - gchar iid_data[256]; - gchar strdata[1024]; - gchar tagstr[1024]; - gchar *uuid; - gchar *did; - gchar *odid; - gint id_count; - gint found; - gint lastfound; - gint count; - int ii; + time_t now; + struct tm *now_tm; + gchar *tmp; + char timestr[256]; + char tzstr[7]; + gchar iid_data[256]; + gchar strdata[1024]; + gchar tagstr[1024]; + gchar *uuid; + gchar *did; + gchar *odid; + gint id_count; + gint found; + gint lastfound; + gint count; + int ii; static const gchar *tags[] = { @@ -436,11 +437,10 @@ gimp_metadata_add_xmp_history (GimpMetadata *metadata, /* get current time and timezone string */ strftime (timestr, 256, "%Y-%m-%dT%H:%M:%S", now_tm); - g_snprintf (timestr, sizeof (timestr), "%s%s", - timestr, tzstr); - + tmp = g_strdup_printf ("%s%s", timestr, tzstr); gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata), - tagstr, timestr); + tagstr, tmp); + g_free (tmp); memset (tagstr, 0, sizeof (tagstr)); memset (strdata, 0, sizeof (strdata));