bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: "Markus Mützel" <markus.muetzel@gmx.de>
To: bug-gnulib@gnu.org
Subject: Modification of environment variables on Windows
Date: Sat, 27 Apr 2024 13:55:25 +0200	[thread overview]
Message-ID: <trinity-2257452f-7718-4de6-92c8-e69ab2515566-1714218925531@3c-app-gmx-bap45> (raw)

[-- Attachment #1: Type: text/plain, Size: 1403 bytes --]

Dear gnulib developers,

We recently updated gnulib in GNU Octave to a newer revision (d4ec02b3cc70cddaaa5183cc5a45814e0afb2292). (Kudos on the impressive speedup to the bootstrap process.)

Since then, we are seeing warnings like the following when building for MinGW:

../../libgnu/tzset.c: In function 'rpl_tzset':
../../libgnu/tzset.c:68:24: warning: initialization of 'char *' from incompatible pointer type 'char **' [-Wincompatible-pointer-types]
   68 |         for (char *s = env; *s != NULL; s++)
      |                        ^~~
../../libgnu/tzset.c:68:32: warning: comparison between pointer and integer
   68 |         for (char *s = env; *s != NULL; s++)
      |                                ^~
../../libgnu/tzset.c:72:28: warning: initialization of 'wchar_t *' {aka 'short unsigned int *'} from incompatible pointer type 'wchar_t **' {aka 'short unsigned int **'} [-Wincompatible-pointer-types]
   72 |         for (wchar_t *ws = wenv; *ws != NULL; ws++)
      |                            ^~~~
../../libgnu/tzset.c:72:38: warning: comparison between pointer and integer
   72 |         for (wchar_t *ws = wenv; *ws != NULL; ws++)
                                             ^~

IIUC, these warnings might be legitimate.

The attached patch avoids those warnings.

I'm hoping this is the correct format to propose changes to gnulib.

Best,
Markus Mützel

[-- Attachment #2: 0001-ctime-localtime-tzset-wcsftime-Check-content-of-envi.patch --]
[-- Type: text/plain, Size: 4314 bytes --]

From 87b83c757f7d249f983410e85d13ba450d57b417 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Markus=20M=C3=BCtzel?= <markus.muetzel@gmx.de>
Date: Sat, 27 Apr 2024 13:44:29 +0200
Subject: [PATCH] ctime, localtime, tzset, wcsftime: Check content of
 environment.

* lib/ctime.c (rpl_ctime): Index into content of each environment variable.
* lib/localtime.c (rpl_localtime): Likewise.
* lib/tzset.c (rpl_tzset): Likewise.
* lib/wcsftime.c (rpl_wcsftime): Likewise.
---
 lib/ctime.c     | 12 ++++++------
 lib/localtime.c | 12 ++++++------
 lib/tzset.c     | 12 ++++++------
 lib/wcsftime.c  | 12 ++++++------
 4 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/lib/ctime.c b/lib/ctime.c
index 8c54ef463c..e30b7997c8 100644
--- a/lib/ctime.c
+++ b/lib/ctime.c
@@ -63,13 +63,13 @@ 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 **s = env; *s != NULL; s++)
+          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 **ws = wenv; *ws != NULL; ws++)
+          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..1c6bb9856e 100644
--- a/lib/localtime.c
+++ b/lib/localtime.c
@@ -63,13 +63,13 @@ 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 **s = env; *s != NULL; s++)
+          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 **ws = wenv; *ws != NULL; ws++)
+          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..c8d48e1afb 100644
--- a/lib/tzset.c
+++ b/lib/tzset.c
@@ -65,13 +65,13 @@ 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 **s = env; *s != NULL; s++)
+          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 **ws = wenv; *ws != NULL; ws++)
+          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..81d1762a92 100644
--- a/lib/wcsftime.c
+++ b/lib/wcsftime.c
@@ -61,13 +61,13 @@ 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 **s = env; *s != NULL; s++)
+          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 **ws = wenv; *ws != NULL; ws++)
+          if (*ws[0] == L'T' && *ws[1] == L'Z' && *ws[2] == L'=')
+            *ws[0] = L'$';
     }
 #endif

--
2.44.0.windows.1


             reply	other threads:[~2024-04-27 11:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-27 11:55 Markus Mützel [this message]
2024-04-27 14:11 ` Modification of environment variables on Windows Bruno Haible
2024-04-27 14:46   ` Markus Mützel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-2257452f-7718-4de6-92c8-e69ab2515566-1714218925531@3c-app-gmx-bap45 \
    --to=markus.muetzel@gmx.de \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).