diff src/evalfunc.c @ 16621:7ad3fc329e08 v8.1.1313

patch 8.1.1313: warnings for using localtime() and ctime() commit https://github.com/vim/vim/commit/63d2555c9cefbbeeca3ec87fdd5d241e9488f9dd Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 10 21:28:38 2019 +0200 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().
author Bram Moolenaar <Bram@vim.org>
date Fri, 10 May 2019 21:30:07 +0200
parents 7e733046db1d
children a1ba0bd74e7d
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -13213,6 +13213,9 @@ f_str2nr(typval_T *argvars, typval_T *re
 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 *
 	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)"));