PR 51803 Avoid malloc if getcwd fails or is not available.
authorJanne Blomqvist <jb@gcc.gnu.org>
Thu, 12 Jan 2012 09:58:34 +0000 (11:58 +0200)
committerJanne Blomqvist <jb@gcc.gnu.org>
Thu, 12 Jan 2012 09:58:34 +0000 (11:58 +0200)
2012-01-12  Janne Blomqvist  <jb@gcc.gnu.org>
    Tobias Burnus  <burnus@net-b.de>

PR libfortran/51803
* runtime/main.c (store_exe_path): Avoid malloc if getcwd fails or
is not available.

Co-Authored-By: Tobias Burnus <burnus@net-b.de>
From-SVN: r183122

libgfortran/ChangeLog
libgfortran/runtime/main.c

index b1e2b049b4f82c866f7c0ec2b44eed0ff2d85aad..7072e18229715b950a188d3032370cbe8d9776fb 100644 (file)
@@ -1,3 +1,10 @@
+2012-01-12  Janne Blomqvist  <jb@gcc.gnu.org>
+           Tobias Burnus  <burnus@net-b.de>
+
+       PR libfortran/51803
+       * runtime/main.c (store_exe_path): Avoid malloc if getcwd fails or
+       is not available.
+
 2012-01-11  Tobias Burnus  <burnus@net-b.de>
 
        * runtime/main.c (store_exe_path): Fix absolute path
@@ -5,6 +12,7 @@
 
 2012-01-11  Janne Blomqvist  <jb@gcc.gnu.org>
            Mike Stump  <mikestump@comcast.net>
+
        PR libfortran/51803
        * runtime/main.c (store_exe_path): Handle getcwd failure and lack
        of the function better.
index 9ee47022cc9b2336e959e7d6fc949a89ec57bfdc..79659e52bcd250be15823926b32a3cbef3b498ea 100644 (file)
@@ -124,12 +124,17 @@ store_exe_path (const char * argv0)
 
 #ifdef HAVE_GETCWD
   cwd = getcwd (buf, sizeof (buf));
-  if (!cwd)
-    cwd = ".";
 #else
-  cwd = ".";
+  cwd = NULL;
 #endif
 
+  if (!cwd)
+    {
+      exe_path = argv0;
+      please_free_exe_path_when_done = 0;
+      return;
+    }
+
   /* exe_path will be cwd + "/" + argv[0] + "\0".  This will not work
      if the executable is not in the cwd, but at this point we're out
      of better ideas.  */