From c8ac9bbf2e9d0bb800b0353dde96fb22a7d2abdb Mon Sep 17 00:00:00 2001 From: defanor Date: Fri, 20 Nov 2020 13:37:50 +0300 Subject: Use gmtime_r instead of gmtime --- src/rexmpp.c | 6 ++++-- src/rexmpp_openpgp.c | 16 ++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/rexmpp.c b/src/rexmpp.c index c75f9b2..e9adeef 100644 --- a/src/rexmpp.c +++ b/src/rexmpp.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -684,8 +685,9 @@ xmlNodePtr rexmpp_xml_set_delay (rexmpp_t *s, xmlNodePtr node) { } char buf[42]; time_t t = time(NULL); - struct tm *utc_time = gmtime(&t); - strftime(buf, 42, "%FT%TZ", utc_time); + struct tm utc_time; + gmtime_r(&t, &utc_time); + strftime(buf, 42, "%FT%TZ", &utc_time); xmlNodePtr delay = xmlNewChild(node, NULL, "delay", NULL); xmlNewProp(delay, "stamp", buf); if (s != NULL && s->assigned_jid.full[0]) { diff --git a/src/rexmpp_openpgp.c b/src/rexmpp_openpgp.c index c7f0eff..5d4d5af 100644 --- a/src/rexmpp_openpgp.c +++ b/src/rexmpp_openpgp.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -210,8 +211,9 @@ void rexmpp_pgp_key_publish_iq (rexmpp_t *s, char time_str[42]; time_t t = time(NULL); - struct tm *utc_time = gmtime(&t); - strftime(time_str, 42, "%FT%TZ", utc_time); + struct tm utc_time; + gmtime_r(&t, &utc_time); + strftime(time_str, 42, "%FT%TZ", &utc_time); xmlNodePtr metadata = xmlNewNode(NULL, "pubkey-metadata"); xmlNewNs(metadata, "urn:xmpp:openpgp:0", NULL); @@ -292,8 +294,9 @@ rexmpp_err_t rexmpp_openpgp_publish_key (rexmpp_t *s, const char *fp) { char time_str[42]; time_t t = time(NULL); - struct tm *utc_time = gmtime(&t); - strftime(time_str, 42, "%FT%TZ", utc_time); + struct tm utc_time; + gmtime_r(&t, &utc_time); + strftime(time_str, 42, "%FT%TZ", &utc_time); xmlNodePtr item = xmlNewNode(NULL, "item"); xmlNewNs(item, "http://jabber.org/protocol/pubsub", NULL); @@ -442,8 +445,9 @@ char *rexmpp_openpgp_encrypt_sign (rexmpp_t *s, /* Add timestamp. */ char time_str[42]; time_t t = time(NULL); - struct tm *utc_time = gmtime(&t); - strftime(time_str, 42, "%FT%TZ", utc_time); + struct tm utc_time; + gmtime_r(&t, &utc_time); + strftime(time_str, 42, "%FT%TZ", &utc_time); xmlNodePtr time = xmlNewNode(NULL, "time"); xmlNewNs(time, "urn:xmpp:openpgp:0", NULL); -- cgit v1.2.3