cli: avoid non-thread-safe localtime() function in nmcli

Static analysis tools flag the use of localtime() because it is not
thread safe. Of course, that was no problem here, but avoiding the
warning is simple.

Also, if we allocate 128 bytes, let strftime use it.
This commit is contained in:
Thomas Haller 2020-05-06 22:33:52 +02:00
parent 53b2297701
commit 6f0dadabd7
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -541,6 +541,8 @@ _metagen_con_show_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
if (info->info_type == NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP)
return (*out_to_free = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp));
else {
struct tm localtime_result;
if (!timestamp) {
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
return _("never");
@ -548,7 +550,7 @@ _metagen_con_show_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
}
timestamp_real = timestamp;
s_mut = g_malloc0 (128);
strftime (s_mut, 64, "%c", localtime (&timestamp_real));
strftime (s_mut, 127, "%c", localtime_r (&timestamp_real, &localtime_result));
return (*out_to_free = s_mut);
}
}