branch-1_4: do not write in getenv result

Ralf Wildenhues <[email protected]>
Newsgroups gmane.comp.gnu.m4.patches
Organization Department of Numerical Simulation, University of Bonn
Message-ID <[email protected]>
A small POSIX nit: the result of getenv may not be modified by the
program.  This nit was uncovered with the help of `splint'.

Cheers,
Ralf

	* src/path.c (include_env_init): Copy the string returned
	by getenv before overwriting it; POSIX disallows this.

Index: src/path.c
===================================================================
RCS file: /cvsroot/m4/m4/src/Attic/path.c,v
retrieving revision 1.1.1.1.2.9
diff -u -r1.1.1.1.2.9 path.c
--- src/path.c	18 Aug 2006 23:11:37 -0000	1.1.1.1.2.9
+++ src/path.c	9 Oct 2006 19:58:35 -0000
@@ -51,14 +51,18 @@
 {
   char *path;
   char *path_end;
+  char *env_path;
 
   if (no_gnu_extensions)
     return;
 
-  path = getenv ("M4PATH");
-  if (path == NULL)
+  env_path = getenv ("M4PATH");
+  if (env_path == NULL)
     return;
 
+  env_path = xstrdup (env_path);
+  path = env_path;
+
   do
     {
       path_end = strchr (path, ':');
@@ -68,6 +72,7 @@
       path = path_end + 1;
     }
   while (path_end);
+  free (env_path);
 }
 
 void
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.