From eea68481bab160e55f5e4d6e61d5a0a8d5a13d99 Mon Sep 17 00:00:00 2001 From: OBATA Akio Date: Thu, 24 Oct 2019 10:16:37 +0900 Subject: Treat time_t as gint64 to convert from/to string "time_t" may not equal with "long", especiall 32-bit platforms resolved "Year 2038 problem". There are no standard way to convert time_t from/to string, but GLib2 using gint64 type as a time internally, so it is reasonable to use gint64 for such purpose. --- libmate-desktop/mate-desktop-thumbnail.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libmate-desktop') diff --git a/libmate-desktop/mate-desktop-thumbnail.c b/libmate-desktop/mate-desktop-thumbnail.c index b874070..20da048 100644 --- a/libmate-desktop/mate-desktop-thumbnail.c +++ b/libmate-desktop/mate-desktop-thumbnail.c @@ -1398,7 +1398,7 @@ mate_desktop_thumbnail_factory_save_thumbnail (MateDesktopThumbnailFactory *fact char *tmp_path; const char *width, *height; int tmp_fd; - char mtime_str[21]; + gchar *mtime_str; gboolean saved_ok; GChecksum *checksum; guint8 digest[16]; @@ -1443,7 +1443,7 @@ mate_desktop_thumbnail_factory_save_thumbnail (MateDesktopThumbnailFactory *fact } close (tmp_fd); - g_snprintf (mtime_str, 21, "%ld", original_mtime); + mtime_str = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64)original_mtime); width = gdk_pixbuf_get_option (thumbnail, "tEXt::Thumb::Image::Width"); height = gdk_pixbuf_get_option (thumbnail, "tEXt::Thumb::Image::Height"); @@ -1481,6 +1481,7 @@ mate_desktop_thumbnail_factory_save_thumbnail (MateDesktopThumbnailFactory *fact g_clear_error (&error); } + g_free (mtime_str); g_free (path); g_free (tmp_path); } @@ -1506,7 +1507,7 @@ mate_desktop_thumbnail_factory_create_failed_thumbnail (MateDesktopThumbnailFact char *path, *file; char *tmp_path; int tmp_fd; - char mtime_str[21]; + gchar *mtime_str; gboolean saved_ok; GdkPixbuf *pixbuf; GChecksum *checksum; @@ -1549,7 +1550,7 @@ mate_desktop_thumbnail_factory_create_failed_thumbnail (MateDesktopThumbnailFact } close (tmp_fd); - g_snprintf (mtime_str, 21, "%ld", mtime); + mtime_str = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64)mtime); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); saved_ok = gdk_pixbuf_save (pixbuf, tmp_path, @@ -1559,6 +1560,7 @@ mate_desktop_thumbnail_factory_create_failed_thumbnail (MateDesktopThumbnailFact "tEXt::Software", "MATE::ThumbnailFactory", NULL); g_object_unref (pixbuf); + g_free (mtime_str); if (saved_ok) { g_chmod (tmp_path, 0600); @@ -1677,7 +1679,7 @@ mate_desktop_thumbnail_is_valid (GdkPixbuf *pixbuf, thumb_mtime_str = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::MTime"); if (!thumb_mtime_str) return FALSE; - thumb_mtime = atol (thumb_mtime_str); + thumb_mtime = (time_t)g_ascii_strtoll (thumb_mtime_str, (gchar**)NULL, 10); if (mtime != thumb_mtime) return FALSE; -- cgit v1.2.1