# New Ticket Created by  Jeff Clites 
# Please include the string:  [perl #31928]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=31928 >


This patch makes scan_paths() copy the passed-in string, since strsep 
will modify it and ultimately this (seemingly) would chew up a couple 
of environment variables; this also gets rid of a compiler warning 
about casting away the constness of libpath, which we shouldn't have 
been doing (since in fact it was being modified).

JEff


Index: config/gen/platform/darwin/dl.c
===================================================================
RCS file: /cvs/public/parrot/config/gen/platform/darwin/dl.c,v
retrieving revision 1.4
diff -u -b -r1.4 dl.c
--- config/gen/platform/darwin/dl.c     31 Aug 2004 16:54:22 -0000      
1.4
+++ config/gen/platform/darwin/dl.c     11 Oct 2004 02:42:51 -0000
@@ -12,25 +12,32 @@
   */

  /* Simple routine to walk a colon separated list of directories in a 
string
-   and check for a file in each one, returning the first match. */
+   and check for a file in each one, returning the first match.
+   Note that this returns a static buffer, and so is not thread-safe. 
*/
  static const char *
  scan_paths(const char *filename, const char *libpath)
  {
      static char buf[PATH_MAX];
      struct stat st;
+       char *path_list;
      const char *path;

      if(!libpath)
        return NULL;

-    path = strsep((char**)&libpath, ":");
+       path_list = strdup(libpath);
+
+    path = strsep(&path_list, ":");

      while(path) {
          snprintf(buf, PATH_MAX, "%s/%s", path, filename);
-        if(stat(buf, &st) == 0)
+        if(stat(buf, &st) == 0) {
+                 free(path_list);
            return buf;
-        path = strsep((char**)&libpath, ":");
      }
+        path = strsep(&path_list, ":");
+    }
+       free(path_list);
      return NULL;
  }

Reply via email to