summaryrefslogtreecommitdiff
path: root/rts/RtsFlags.c
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2012-07-02 15:55:20 +0100
committerSimon Marlow <marlowsd@gmail.com>2012-07-02 16:15:34 +0100
commit0d19922acd724991b7b97871b1404f3db5058b49 (patch)
treee5e9b47e222a3eabd49ea1c3d9cf25b860f82e01 /rts/RtsFlags.c
parent62164cf56bd91ddd9449d345f8d710fbbdbf4827 (diff)
downloadhaskell-0d19922acd724991b7b97871b1404f3db5058b49.tar.gz
don't crash if argv[0] == NULL (#7037)
Diffstat (limited to 'rts/RtsFlags.c')
-rw-r--r--rts/RtsFlags.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c
index 4e156e63d0..7c86efadb7 100644
--- a/rts/RtsFlags.c
+++ b/rts/RtsFlags.c
@@ -474,7 +474,7 @@ void setupRtsFlags (int *argc, char *argv[],
total_arg = *argc;
arg = 1;
- *argc = 1;
+ if (*argc > 1) { *argc = 1; };
rts_argc = 0;
rts_argv_size = total_arg + 1;
@@ -1677,16 +1677,22 @@ static void freeArgv(int argc, char *argv[])
void
setProgName(char *argv[])
{
+ char *last_slash;
+
+ if (argv[0] == NULL) { // #7037
+ prog_name = "";
+ return;
+ }
+
/* Remove directory from argv[0] -- default files in current directory */
#if !defined(mingw32_HOST_OS)
- char *last_slash;
if ( (last_slash = (char *) strrchr(argv[0], '/')) != NULL ) {
prog_name = last_slash+1;
} else {
prog_name = argv[0];
}
#else
- char* last_slash = argv[0] + (strlen(argv[0]) - 1);
+ last_slash = argv[0] + (strlen(argv[0]) - 1);
while ( last_slash > argv[0] ) {
if ( *last_slash == '/' || *last_slash == '\\' ) {
prog_name = last_slash+1;