diff --git a/wsutil/tempfile.c b/wsutil/tempfile.c index 5900b2bb8ac..8e1f8dc588f 100644 --- a/wsutil/tempfile.c +++ b/wsutil/tempfile.c @@ -170,6 +170,7 @@ create_tempfile(char **namebuf, const char *pfx, const char *sfx) int old_umask; int fd; time_t current_time; + struct tm *tm; char timestr[14 + 1]; gchar *tmp_file; gchar *safe_pfx; @@ -204,8 +205,11 @@ create_tempfile(char **namebuf, const char *pfx, const char *sfx) _tzset(); #endif current_time = time(NULL); - /* We trust the OS not to return a time before the Epoch. */ - strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", localtime(¤t_time)); + tm = localtime(¤t_time); + if (tm != NULL) + strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", tm); + else + g_strlcpy(timestr, "196912312359", sizeof(timestr)); /* second before the Epoch */ sep[0] = G_DIR_SEPARATOR; tmp_file = g_strconcat(tmp_dir, sep, safe_pfx, "_", timestr, "_", TMP_FILE_SUFFIX, sfx, NULL); g_free(safe_pfx);