diff options
author | Thomas Haller <thaller@redhat.com> | 2023-08-18 17:24:24 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-08-21 08:54:31 +0200 |
commit | 84c9d887eeb5efb2f8297f73ef71d0f36efaef6a (patch) | |
tree | 27c7aa5763175b2c9ae4f5b8cf152ba565db5eca | |
parent | 471188abdb9b2ed15bcea512bc50f12e5cea3505 (diff) | |
download | glib-84c9d887eeb5efb2f8297f73ef71d0f36efaef6a.tar.gz |
glib: avoid non-reentrant localtime() in g_log_writer_format_fields()
-rw-r--r-- | glib/gmessages.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/glib/gmessages.c b/glib/gmessages.c index 45906a754..5460dcf4b 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -186,22 +186,23 @@ #include <sys/uio.h> #endif -#include "glib-init.h" #include "galloca.h" #include "gbacktrace.h" #include "gcharset.h" #include "gconvert.h" #include "genviron.h" +#include "glib-init.h" #include "glib-private.h" #include "gmain.h" #include "gmem.h" +#include "gpattern.h" #include "gprintfint.h" -#include "gtestutils.h" -#include "gthread.h" #include "gstrfuncs.h" #include "gstring.h" -#include "gpattern.h" +#include "gtestutils.h" +#include "gthread.h" #include "gthreadprivate.h" +#include "gutilsprivate.h" #if defined(__linux__) && !defined(__BIONIC__) #include "gjournal-private.h" @@ -2260,7 +2261,7 @@ g_log_writer_format_fields (GLogLevelFlags log_level, GString *gstring; gint64 now; time_t now_secs; - struct tm *now_tm; + struct tm now_tm; gchar time_buf[128]; /* Extract some common fields. */ @@ -2313,9 +2314,8 @@ g_log_writer_format_fields (GLogLevelFlags log_level, /* Timestamp */ now = g_get_real_time (); now_secs = (time_t) (now / 1000000); - now_tm = localtime (&now_secs); - if (G_LIKELY (now_tm != NULL)) - strftime (time_buf, sizeof (time_buf), "%H:%M:%S", now_tm); + if (_g_localtime (now_secs, &now_tm)) + strftime (time_buf, sizeof (time_buf), "%H:%M:%S", &now_tm); else strcpy (time_buf, "(error)"); |