hs_init(): cope with argc and/or argv being NULL (#6006)
authorSimon Marlow <marlowsd@gmail.com>
Fri, 27 Apr 2012 12:20:56 +0000 (13:20 +0100)
committerPaolo Capriotti <p.capriotti@gmail.com>
Tue, 8 May 2012 14:51:58 +0000 (15:51 +0100)
MERGED from commit 4ca281829c70331571291ed3dcf813a6028cc904

rts/RtsStartup.c

index c63f85e..52728e1 100644 (file)
@@ -141,7 +141,14 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config)
     defaultsHook();
 
     /* Parse the flags, separating the RTS flags from the programs args */
-    if (argc != NULL && argv != NULL) {
+    if (argc == NULL || argv == NULL) {
+        // Use a default for argc & argv if either is not supplied
+        int my_argc = 1;
+        char *my_argv[] = { "<unknown>", NULL };
+        setFullProgArgv(my_argc,my_argv);
+        setupRtsFlags(&my_argc, my_argv,
+                      rts_config.rts_opts_enabled, rts_config.rts_opts);
+    } else {
        setFullProgArgv(*argc,*argv);
         setupRtsFlags(argc, *argv,
                       rts_config.rts_opts_enabled, rts_config.rts_opts);