[glib: 13/19] gmessages: Add check for a localtime function return value




commit 5a61f8b922a84c3bb82bc6eca20fa98ff810f041
Author: Egor Bychin <e bychin drweb com>
Date:   Mon Oct 11 14:10:39 2021 +0300

    gmessages: Add check for a localtime function return value

 glib/gmessages.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/glib/gmessages.c b/glib/gmessages.c
index 890751297..7affcd4d9 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -2321,7 +2321,10 @@ g_log_writer_format_fields (GLogLevelFlags   log_level,
   now = g_get_real_time ();
   now_secs = (time_t) (now / 1000000);
   now_tm = localtime (&now_secs);
-  strftime (time_buf, sizeof (time_buf), "%H:%M:%S", now_tm);
+  if (G_LIKELY (now_tm != NULL))
+    strftime (time_buf, sizeof (time_buf), "%H:%M:%S", now_tm);
+  else
+    strcpy (time_buf, "(error)");
 
   g_string_append_printf (gstring, "%s%s.%03d%s: ",
                           use_color ? "\033[34m" : "",


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