[totem-pl-parser/wip/hadess/add-ignored-extensions: 1/3] plparser: Remove use of Y2038 unsafe GTimeVal



commit 541958955d0b1ce485944695821ef0c5ace9f364
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Nov 12 11:39:42 2019 +0100

    plparser: Remove use of Y2038 unsafe GTimeVal
    
    Use GDateTime instead.
    
    g_date_time_new_from_iso8601() was added in glib 2.56, so bump the
    requirements.
    
    Note that this also changes one of the tests, as GDateTime does not
    support leap seconds as the old GTimeVal code used to do.
    
    See https://gitlab.gnome.org/GNOME/glib/issues/1938

 meson.build               |  2 +-
 plparse/tests/parser.c    |  2 +-
 plparse/totem-pl-parser.c | 21 +++++++++------------
 3 files changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/meson.build b/meson.build
index 50956b3..115726b 100644
--- a/meson.build
+++ b/meson.build
@@ -30,7 +30,7 @@ plparse_soversion   = plparse_lt_current - plparse_lt_age
 plparse_libversion  = '@0@.@1@.@2@'.format(plparse_soversion, plparse_lt_age, plparse_lt_revision)
 
 # Requirements
-glib_req    = '>= 2.36.0'
+glib_req    = '>= 2.56.0'
 gio_req     = '>= 2.24.0'
 quvi_req    = '>= 0.9.1'
 archive_req = '>= 3.0'
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index 4488a55..17d79c6 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -135,7 +135,7 @@ test_date (void)
 
        /* Atom */
        g_assert_cmpuint (totem_pl_parser_parse_date ("2003-12-13T18:30:02Z", verbose), ==, 1071340202);
-       g_assert_cmpuint (totem_pl_parser_parse_date ("1990-12-31T15:59:60-08:00", verbose), ==, 662688000);
+       g_assert_cmpuint (totem_pl_parser_parse_date ("1990-12-31T15:59:59-08:00", verbose), ==, 662687999);
 }
 
 #define READ_CHUNK_SIZE 8192
diff --git a/plparse/totem-pl-parser.c b/plparse/totem-pl-parser.c
index 49dd406..f4ad288 100644
--- a/plparse/totem-pl-parser.c
+++ b/plparse/totem-pl-parser.c
@@ -2361,27 +2361,24 @@ totem_pl_parser_parse_duration (const char *duration, gboolean debug)
 guint64
 totem_pl_parser_parse_date (const char *date_str, gboolean debug)
 {
-       GTimeVal val;
+       g_autoptr(GDateTime) date = NULL;
 
        g_return_val_if_fail (date_str != NULL, -1);
 
-       memset (&val, 0, sizeof(val));
        /* Try to parse as an ISO8601/RFC3339 date */
-       if (g_time_val_from_iso8601 (date_str, &val) != FALSE) {
+       date = g_date_time_new_from_iso8601 (date_str, NULL);
+       if (date != NULL) {
                D(g_message ("Parsed duration '%s' using the ISO8601 parser", date_str));
-               return val.tv_sec;
+               return g_date_time_to_unix (date);
        }
        D(g_message ("Failed to parse duration '%s' using the ISO8601 parser", date_str));
        /* Fall back to RFC 2822 date parsing */
-       {
-               g_autoptr(GDateTime) date = NULL;
-               date = g_mime_utils_header_decode_date (date_str);
-               if (!date || !g_date_time_to_timeval (date, &val)) {
-                       D(g_message ("Failed to parse duration '%s' using the RFC 2822 parser", date_str));
-                       return -1;
-               }
-               return val.tv_sec;
+       date = g_mime_utils_header_decode_date (date_str);
+       if (!date) {
+               D(g_message ("Failed to parse duration '%s' using the RFC 2822 parser", date_str));
+               return -1;
        }
+       return g_date_time_to_unix (date);
 }
 #endif /* !TOTEM_PL_PARSER_MINI */
 


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