1
0
forked from aniani/vim

patch 8.1.1313: warnings for using localtime() and ctime()

Problem:    Warnings for using localtime() and ctime().
Solution:   Use localtime_r() if available.  Avoid using ctime().
This commit is contained in:
Bram Moolenaar
2019-05-10 21:28:38 +02:00
parent 4ca41534b7
commit 63d2555c9c
10 changed files with 83 additions and 35 deletions

View File

@@ -13213,6 +13213,9 @@ f_str2nr(typval_T *argvars, typval_T *rettv)
f_strftime(typval_T *argvars, typval_T *rettv)
{
char_u result_buf[256];
# ifdef HAVE_LOCALTIME_R
struct tm tmval;
# endif
struct tm *curtime;
time_t seconds;
char_u *p;
@@ -13224,7 +13227,11 @@ f_strftime(typval_T *argvars, typval_T *rettv)
seconds = time(NULL);
else
seconds = (time_t)tv_get_number(&argvars[1]);
# ifdef HAVE_LOCALTIME_R
curtime = localtime_r(&seconds, &tmval);
# else
curtime = localtime(&seconds);
# endif
/* MSVC returns NULL for an invalid value of seconds. */
if (curtime == NULL)
rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)"));