From: Bruno Haible Date: Sat, 27 Apr 2024 14:09:55 +0000 (+0200) Subject: ctime, localtime, tzset, wcsftime: Fix env access (regr. 2024-02-09). X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=92cdf62b56462b914193c7770440e505a37c2526;p=gnulib.git ctime, localtime, tzset, wcsftime: Fix env access (regr. 2024-02-09). Reported by Markus Mützel in . * 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. --- diff --git a/ChangeLog b/ChangeLog index 3ec2b6f65e..b1c986eaf3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2024-04-27 Bruno Haible + + ctime, localtime, tzset, wcsftime: Fix env access (regr. 2024-02-09). + Reported by Markus Mützel in + . + * 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 login_tty tests: Avoid gcc warnings. diff --git a/lib/ctime.c b/lib/ctime.c index 8c54ef463c..744b153260 100644 --- a/lib/ctime.c +++ b/lib/ctime.c @@ -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 diff --git a/lib/localtime.c b/lib/localtime.c index f0e91ac647..df0278e5c2 100644 --- a/lib/localtime.c +++ b/lib/localtime.c @@ -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 diff --git a/lib/tzset.c b/lib/tzset.c index f307f0c3d1..93dc52e284 100644 --- a/lib/tzset.c +++ b/lib/tzset.c @@ -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 diff --git a/lib/wcsftime.c b/lib/wcsftime.c index d8b471ab57..b1b3243271 100644 --- a/lib/wcsftime.c +++ b/lib/wcsftime.c @@ -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