Terminate options when passed via env var

The C standard requires that argv be terminated with a NULL pointer
(that is, argv[argc] == NULL). There are several places in the swig
codebase that require this to check for missing arguments. However,
SWIG_merge_envopt() was not keeping the NULL terminator, resulting in
argument parsing failures (typically program aborts) when arguments were
passed via the SWIG_FEATURES environment variable.
This commit is contained in:
Joshua Watt 2017-12-04 09:23:06 -06:00
commit 7eff4e7c1d

View file

@ -125,7 +125,7 @@ void SWIG_merge_envopt(const char *env, int oargc, char *oargv[], int *nargc, ch
int argc = 1;
int arge = oargc + 1024;
char **argv = (char **) malloc(sizeof(char *) * (arge));
char **argv = (char **) malloc(sizeof(char *) * (arge + 1));
char *buffer = (char *) malloc(2048);
char *b = buffer;
char *be = b + 1023;
@ -147,6 +147,7 @@ void SWIG_merge_envopt(const char *env, int oargc, char *oargv[], int *nargc, ch
for (int i = 1; (i < oargc) && (argc < arge); ++i, ++argc) {
argv[argc] = oargv[i];
}
argv[argc] = NULL;
*nargc = argc;
*nargv = argv;