m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch-1_4: do not write in getenv result


From: Ralf Wildenhues
Subject: branch-1_4: do not write in getenv result
Date: Mon, 9 Oct 2006 21:59:08 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]