[gcab: 1/2] gcab-list-details: avoid runtime critical warning




commit 82aab326647b33119e4c3433fdfc8293d42a2c86
Author: Dirk-Jan C. Binnema <djcb djcbsoftware nl>
Date:   Thu Apr 8 16:08:11 2021 +0300

    gcab-list-details: avoid runtime critical warning
    
    Saw some runtime errors when trying the to get some details on an fwupd
    cab file:
      https://fwupd.org/downloads/9ac1fdb3a25a79f2084c84e53d30ffa9fa93a9ed-Nitrokey-Storage-0.53.cab
    
    ,----
    | ~/Downloads % gcab -l f53060d3930a0f140a0f1c6e42b857c5cede7b85-Nitrokey-Storage-0.50.cab
    | LICENSE.txt 35823 2021-02-07 13:22:12 0x0
    | README.txt 891 2021-02-07 13:22:12 0x0
    | firmware.jcat 2960 2021-02-07 13:22:12 0x0
    |
    | (gcab:814994): GLib-CRITICAL **: 15:10:57.556: g_date_time_to_timezone: assertion 'datetime != NULL' 
failed
    |
    | (gcab:814994): GLib-CRITICAL **: 15:10:57.556: g_date_time_format: assertion 'datetime != NULL' failed
    | firmware_V0.50.0.hex 529536 (null) 0x0
    | firmware_V0.50.0.hex.asc 488 2021-02-07 13:22:12 0x0
    | storage.metainfo.xml 1914 2021-02-07 13:22:12 0x0
    `----
    
    Apparently some file without a date; let's avoid the critical warning
    when we try to turn that into something printable.

 src/gcab.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/src/gcab.c b/src/gcab.c
index cb9e374..7182c50 100644
--- a/src/gcab.c
+++ b/src/gcab.c
@@ -193,14 +193,17 @@ individual files from the archive.\
 
                 for (l = files; l != NULL; l = l->next) {
                     if (list_details) {
+                        g_autofree char *date = NULL;
                         g_autoptr(GDateTime) dt = gcab_file_get_date_time (GCAB_FILE (l->data));
-                        g_autoptr(GDateTime) dtl = g_date_time_to_local (dt);
-                        g_autofree char *date = g_date_time_format (dtl, "%Y-%m-%d %H:%M:%S");
+                        if (dt) {
+                            g_autoptr(GDateTime) dtl = g_date_time_to_local (dt);
+                            date = g_date_time_format (dtl, "%Y-%m-%d %H:%M:%S");
+                        }
 
                         g_print ("%s %u %s 0x%X\n",
                                  gcab_file_get_name (GCAB_FILE (l->data)),
                                  gcab_file_get_size (GCAB_FILE (l->data)),
-                                 date,
+                                 date ? date : _("<unknown-date>"),
                                  gcab_file_get_attributes (GCAB_FILE (l->data)));
                     } else {
                         g_print ("%s\n", gcab_file_get_name (GCAB_FILE (l->data)));


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