From: Greg King Date: Sun, 30 Aug 2015 09:16:38 +0000 (-0400) Subject: Fixed a comparison operator; so that the NULL at the end of argv[] is copied by InitC... X-Git-Tag: V2.16~236^2~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a132bc4b28cc3ed3474586735dd2d8ad53a2caeb;p=cc65 Fixed a comparison operator; so that the NULL at the end of argv[] is copied by InitCmdLine(). Most POSIX function libraries hid that long-time bug by putting zeroes in their dynamic RAM; but, MinGW's library doesn't do it. Therefore, a command like cl65 foo.c -l would crash with a "Segmentation fault" -- it should give a nice error message about "-l"; and, quit neatly. --- diff --git a/src/common/cmdline.c b/src/common/cmdline.c index 716df1efb..ce2962780 100644 --- a/src/common/cmdline.c +++ b/src/common/cmdline.c @@ -161,7 +161,7 @@ static void ExpandFile (CmdLine* L, const char* Name) -void InitCmdLine (int* aArgCount, char** aArgVec[], const char* aProgName) +void InitCmdLine (int* aArgCount, char*** aArgVec, const char* aProgName) /* Initialize command line parsing. aArgVec is the argument array terminated by ** a NULL pointer (as usual), ArgCount is the number of valid arguments in the ** array. Both arguments are remembered in static storage. @@ -171,7 +171,7 @@ void InitCmdLine (int* aArgCount, char** aArgVec[], const char* aProgName) int I; /* Get the program name from argv[0] but strip a path */ - if (*(aArgVec)[0] == 0) { + if ((*aArgVec)[0] == 0) { /* Use the default name given */ ProgName = aProgName; } else { @@ -190,7 +190,7 @@ void InitCmdLine (int* aArgCount, char** aArgVec[], const char* aProgName) ** special handling for arguments preceeded by the '@' sign - these are ** actually files containing arguments. */ - for (I = 0; I < *aArgCount; ++I) { + for (I = 0; I <= *aArgCount; ++I) { /* Get the next argument */ char* Arg = (*aArgVec)[I]; diff --git a/src/common/cmdline.h b/src/common/cmdline.h index b18906c7a..1caf0cfb6 100644 --- a/src/common/cmdline.h +++ b/src/common/cmdline.h @@ -71,7 +71,7 @@ struct LongOpt { -void InitCmdLine (int* aArgCount, char** aArgVec[], const char* aProgName); +void InitCmdLine (int* aArgCount, char*** aArgVec, const char* aProgName); /* Initialize command line parsing. aArgVec is the argument array terminated by ** a NULL pointer (as usual), ArgCount is the number of valid arguments in the ** array. Both arguments are remembered in static storage.