From fb6228ac5fa37f3954a6825bc2b9d96914c95985 Mon Sep 17 00:00:00 2001 From: Reuben Green <reubengreen73@gmail.com> Date: Tue, 1 Sep 2020 10:05:05 +0100 Subject: [PATCH] Fix error when displaying custom date format in details view (issue #389) Fixes a bug caused by use of a shared static "struct tm" by taking a copy of the struct to pass to exo_strdup_strftime rather than passing a pointer to the shared struct. --- thunar/thunar-util.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/thunar/thunar-util.c b/thunar/thunar-util.c index 712c454b2..c2468a1ec 100644 --- a/thunar/thunar-util.c +++ b/thunar/thunar-util.c @@ -394,7 +394,7 @@ thunar_util_humanize_file_time (guint64 file_time, const gchar *date_custom_style) { const gchar *date_format; - struct tm *tfile; + struct tm tfile; time_t ftime; GDate dfile; GDate dnow; @@ -405,8 +405,8 @@ thunar_util_humanize_file_time (guint64 file_time, { ftime = (time_t) file_time; - /* determine the local file time */ - tfile = localtime (&ftime); + /* take a copy of the local file time */ + tfile = *localtime (&ftime); /* check which style to use to format the time */ if (date_style == THUNAR_DATE_STYLE_SIMPLE || date_style == THUNAR_DATE_STYLE_SHORT) @@ -427,7 +427,7 @@ thunar_util_humanize_file_time (guint64 file_time, else /* if (date_style == THUNAR_DATE_STYLE_SHORT) */ { /* TRANSLATORS: file was modified less than one day ago */ - return exo_strdup_strftime (_("Today at %X"), tfile); + return exo_strdup_strftime (_("Today at %X"), &tfile); } } else if (diff == 1) @@ -440,7 +440,7 @@ thunar_util_humanize_file_time (guint64 file_time, else /* if (date_style == THUNAR_DATE_STYLE_SHORT) */ { /* TRANSLATORS: file was modified less than two days ago */ - return exo_strdup_strftime (_("Yesterday at %X"), tfile); + return exo_strdup_strftime (_("Yesterday at %X"), &tfile); } } else @@ -457,25 +457,25 @@ thunar_util_humanize_file_time (guint64 file_time, } /* format the date string accordingly */ - return exo_strdup_strftime (date_format, tfile); + return exo_strdup_strftime (date_format, &tfile); } } else if (date_style == THUNAR_DATE_STYLE_LONG) { /* use long, date(1)-like format string */ - return exo_strdup_strftime ("%c", tfile); + return exo_strdup_strftime ("%c", &tfile); } else if (date_style == THUNAR_DATE_STYLE_YYYYMMDD) { - return exo_strdup_strftime ("%Y-%m-%d %H:%M:%S", tfile); + return exo_strdup_strftime ("%Y-%m-%d %H:%M:%S", &tfile); } else if (date_style == THUNAR_DATE_STYLE_MMDDYYYY) { - return exo_strdup_strftime ("%m-%d-%Y %H:%M:%S", tfile); + return exo_strdup_strftime ("%m-%d-%Y %H:%M:%S", &tfile); } else if (date_style == THUNAR_DATE_STYLE_DDMMYYYY) { - return exo_strdup_strftime ("%d-%m-%Y %H:%M:%S", tfile); + return exo_strdup_strftime ("%d-%m-%Y %H:%M:%S", &tfile); } else /* if (date_style == THUNAR_DATE_STYLE_CUSTOM) */ { @@ -483,7 +483,7 @@ thunar_util_humanize_file_time (guint64 file_time, return g_strdup (""); /* use custom date formatting */ - return exo_strdup_strftime (date_custom_style, tfile); + return exo_strdup_strftime (date_custom_style, &tfile); } } -- GitLab