From b6938156fe1ca2ba8a7db167604618eea31282f1 Mon Sep 17 00:00:00 2001 From: Nala Ginrut
Date: Fri, 10 Oct 2014 23:54:24 +0800 Subject: [PATCH] Check argv[0] if it's NULL in scm_boot_guile According to C11, argv[argc] should be NULL. If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name. But if argc is zero, argv[0] will be NULL, so we have to check it first to avoid segfault. * libguile/init.c --- libguile/init.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libguile/init.c b/libguile/init.c index d2928bd..e11115c 100644 --- a/libguile/init.c +++ b/libguile/init.c @@ -311,8 +311,14 @@ scm_boot_guile (int argc, char ** argv, void (*main_func) (), void *closure) struct main_func_closure c; /* On Windows, convert backslashes in argv[0] to forward - slashes. */ - scm_i_mirror_backslashes (argv[0]); + slashes. + According to C11, argv[argc] should be NULL. + If the value of argc is greater than zero, the string pointed to by argv[0] + represents the program name. But if argc is zero, argv[0] will be NULL, so + we have to check it first to avoid segfault. + */ + if (argc) + scm_i_mirror_backslashes (argv[0]); c.main_func = main_func; c.closure = closure; c.argc = argc; -- 1.7.10.4