https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124330

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I don't think this is correct.
putenv is documented everywhere (Linux, POSIX) to have the passed string become
part of the environment.
The https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124330#c6 reference I believe
would be about the case when the environ pointed array (or whatever other name)
needs to be reallocated.  But still the individual elements of that array
should be what putenv has been called with.
So, IMHO either you make the buffers static if those 2 functions can be called
at most once:
--- libgfortran/caf/shmem/shared_memory.c.jj    2026-03-04 09:15:13.572332552
+0100
+++ libgfortran/caf/shmem/shared_memory.c       2026-03-04 14:01:14.511957983
+0100
@@ -71,7 +71,7 @@ shared_memory_set_env (pid_t pid)
   snprintf (val, 20, "%d", pid);
   SetEnvironmentVariable (ENV_PPID, val);
 #else
-  char buffer[28];
+  static char buffer[28];
   int res;

   /* HP-UX / Legacy Fallback using putenv */
@@ -253,7 +253,7 @@ shared_memory_init (shared_memory_act *m
       snprintf (val, 20, "%p", mem->glbl.base);
       SetEnvironmentVariable (ENV_BASE, val);
 #else
-      char buffer[28];
+      static char buffer[28];
       int res;

       /* HP-UX / Legacy Fallback using putenv */
or malloc the buffers.  But I guess even if they are called multiple times, it
is fine to override the earlier one with the new one because putenv will do
that anyway.

Reply via email to