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
This commit is contained in:
Janne Blomqvist 2012-01-12 11:58:34 +02:00
parent 725a74a517
commit cb735e3800
2 changed files with 16 additions and 3 deletions

View 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> 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 @@
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.

View File

@ -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. */