Commit cb735e38 by Janne Blomqvist

PR 51803 Avoid malloc if getcwd fails or is not available.

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
parent 725a74a5
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> 2012-01-11 Tobias Burnus <burnus@net-b.de>
* runtime/main.c (store_exe_path): Fix absolute path * runtime/main.c (store_exe_path): Fix absolute path
...@@ -5,6 +12,7 @@ ...@@ -5,6 +12,7 @@
2012-01-11 Janne Blomqvist <jb@gcc.gnu.org> 2012-01-11 Janne Blomqvist <jb@gcc.gnu.org>
Mike Stump <mikestump@comcast.net> Mike Stump <mikestump@comcast.net>
PR libfortran/51803 PR libfortran/51803
* runtime/main.c (store_exe_path): Handle getcwd failure and lack * runtime/main.c (store_exe_path): Handle getcwd failure and lack
of the function better. of the function better.
......
...@@ -124,12 +124,17 @@ store_exe_path (const char * argv0) ...@@ -124,12 +124,17 @@ store_exe_path (const char * argv0)
#ifdef HAVE_GETCWD #ifdef HAVE_GETCWD
cwd = getcwd (buf, sizeof (buf)); cwd = getcwd (buf, sizeof (buf));
if (!cwd)
cwd = ".";
#else #else
cwd = "."; cwd = NULL;
#endif #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 /* 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 if the executable is not in the cwd, but at this point we're out
of better ideas. */ of better ideas. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment