]> Savannah Git Hosting - gnulib.git/commitdiff
ctime, localtime, tzset, wcsftime: Fix env access (regr. 2024-02-09).
authorBruno Haible <bruno@clisp.org>
Sat, 27 Apr 2024 14:09:55 +0000 (16:09 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 27 Apr 2024 14:09:55 +0000 (16:09 +0200)
Reported by Markus Mützel <markus.muetzel@gmx.de> in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00457.html>.

* lib/ctime.c (rpl_ctime): Fix logic of environment traversal.
* lib/localtime.c (rpl_localtime): Likewise.
* lib/tzset.c (rpl_tzset): Likewise.
* lib/wcsftime.c (rpl_wcsftime): Likewise.

ChangeLog
lib/ctime.c
lib/localtime.c
lib/tzset.c
lib/wcsftime.c

index 3ec2b6f65ed1be07b8c403ec3dcc141b962e2ffb..b1c986eaf31d4f802b58398bacd119261af6edb7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-04-27  Bruno Haible  <bruno@clisp.org>
+
+       ctime, localtime, tzset, wcsftime: Fix env access (regr. 2024-02-09).
+       Reported by Markus Mützel <markus.muetzel@gmx.de> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00457.html>.
+       * lib/ctime.c (rpl_ctime): Fix logic of environment traversal.
+       * lib/localtime.c (rpl_localtime): Likewise.
+       * lib/tzset.c (rpl_tzset): Likewise.
+       * lib/wcsftime.c (rpl_wcsftime): Likewise.
+
 2024-04-26  Bruno Haible  <bruno@clisp.org>
 
        login_tty tests: Avoid gcc warnings.
index 8c54ef463c0065ac0080e59338538791935e030e..744b153260d7399f6ff12f1d3d76c212138db4f4 100644 (file)
@@ -63,13 +63,19 @@ rpl_ctime (const time_t *tp)
       char **env = _environ;
       wchar_t **wenv = _wenviron;
       if (env != NULL)
-        for (char *s = env; *s != NULL; s++)
-          if (s[0] == 'T' && s[1] == 'Z' && s[2] == '=')
-            s[0] = '$';
+        for (char **ep = env; *ep != NULL; ep++)
+          {
+            char *s = *ep;
+            if (s[0] == 'T' && s[1] == 'Z' && s[2] == '=')
+              s[0] = '$';
+          }
       if (wenv != NULL)
-        for (wchar_t *ws = wenv; *ws != NULL; ws++)
-          if (ws[0] == L'T' && ws[1] == L'Z' && ws[2] == L'=')
-            ws[0] = L'$';
+        for (wchar_t **wep = wenv; *wep != NULL; wep++)
+          {
+            wchar_t *ws = *wep;
+            if (ws[0] == L'T' && ws[1] == L'Z' && ws[2] == L'=')
+              ws[0] = L'$';
+          }
     }
 #endif
 
index f0e91ac6477219b1d0fb3783711aae62fd7dd906..df0278e5c2360556ed530bd750d46b4cbb2b0503 100644 (file)
@@ -63,13 +63,19 @@ rpl_localtime (const time_t *tp)
       char **env = _environ;
       wchar_t **wenv = _wenviron;
       if (env != NULL)
-        for (char *s = env; *s != NULL; s++)
-          if (s[0] == 'T' && s[1] == 'Z' && s[2] == '=')
-            s[0] = '$';
+        for (char **ep = env; *ep != NULL; ep++)
+          {
+            char *s = *ep;
+            if (s[0] == 'T' && s[1] == 'Z' && s[2] == '=')
+              s[0] = '$';
+          }
       if (wenv != NULL)
-        for (wchar_t *ws = wenv; *ws != NULL; ws++)
-          if (ws[0] == L'T' && ws[1] == L'Z' && ws[2] == L'=')
-            ws[0] = L'$';
+        for (wchar_t **wep = wenv; *wep != NULL; wep++)
+          {
+            wchar_t *ws = *wep;
+            if (ws[0] == L'T' && ws[1] == L'Z' && ws[2] == L'=')
+              ws[0] = L'$';
+          }
     }
 #endif
 
index f307f0c3d1baa0663ce8f1bc9d769b00b88d3c41..93dc52e28436b1ff9d75d912425da9f7d1e2aa00 100644 (file)
@@ -65,13 +65,19 @@ rpl_tzset (void)
       char **env = _environ;
       wchar_t **wenv = _wenviron;
       if (env != NULL)
-        for (char *s = env; *s != NULL; s++)
-          if (s[0] == 'T' && s[1] == 'Z' && s[2] == '=')
-            s[0] = '$';
+        for (char **ep = env; *ep != NULL; ep++)
+          {
+            char *s = *ep;
+            if (s[0] == 'T' && s[1] == 'Z' && s[2] == '=')
+              s[0] = '$';
+          }
       if (wenv != NULL)
-        for (wchar_t *ws = wenv; *ws != NULL; ws++)
-          if (ws[0] == L'T' && ws[1] == L'Z' && ws[2] == L'=')
-            ws[0] = L'$';
+        for (wchar_t **wep = wenv; *wep != NULL; wep++)
+          {
+            wchar_t *ws = *wep;
+            if (ws[0] == L'T' && ws[1] == L'Z' && ws[2] == L'=')
+              ws[0] = L'$';
+          }
     }
 
   /* On native Windows, tzset() is deprecated.  Use _tzset() instead.  See
index d8b471ab57dd5205668c181d9de45600a952db22..b1b3243271f8b63244debff2c88ce1b591e4c620 100644 (file)
@@ -61,13 +61,19 @@ rpl_wcsftime (wchar_t *buf, size_t bufsize, const wchar_t *format, const struct
       char **env = _environ;
       wchar_t **wenv = _wenviron;
       if (env != NULL)
-        for (char *s = env; *s != NULL; s++)
-          if (s[0] == 'T' && s[1] == 'Z' && s[2] == '=')
-            s[0] = '$';
+        for (char **ep = env; *ep != NULL; ep++)
+          {
+            char *s = *ep;
+            if (s[0] == 'T' && s[1] == 'Z' && s[2] == '=')
+              s[0] = '$';
+          }
       if (wenv != NULL)
-        for (wchar_t *ws = wenv; *ws != NULL; ws++)
-          if (ws[0] == L'T' && ws[1] == L'Z' && ws[2] == L'=')
-            ws[0] = L'$';
+        for (wchar_t **wep = wenv; *wep != NULL; wep++)
+          {
+            wchar_t *ws = *wep;
+            if (ws[0] == L'T' && ws[1] == L'Z' && ws[2] == L'=')
+              ws[0] = L'$';
+          }
     }
 #endif