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:
parent
4e8c515d36
commit
7eff4e7c1d
1 changed files with 2 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue