aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/runtime
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2012-01-12 09:58:34 +0000
committerJanne Blomqvist <jb@gcc.gnu.org>2012-01-12 09:58:34 +0000
commit8c63ed2559530a0ffa09e3260c2493e278411811 (patch)
treeecec08b90b14048a337d070bc48ab04deedc35ed /libgfortran/runtime
parent52b72d794512bceb3e5f5ed51892584ea76955ca (diff)
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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@183122 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r--libgfortran/runtime/main.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/libgfortran/runtime/main.c b/libgfortran/runtime/main.c
index 9ee47022cc9..79659e52bcd 100644
--- a/libgfortran/runtime/main.c
+++ b/libgfortran/runtime/main.c
@@ -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. */