diff options
author | jbj <jbj> | 2008-02-17 00:53:49 +0000 |
---|---|---|
committer | jbj <jbj> | 2008-02-17 00:53:49 +0000 |
commit | aeadef4096dd6a72fa84d419c172687777dc04c4 (patch) | |
tree | 5c9965256b912a0b9c252c6bd1fab5a019ba610f /popt.c | |
parent | 3f8ebb78d75a8b1c3c1a726418bb71fe2412aee4 (diff) | |
download | libpopt-aeadef4096dd6a72fa84d419c172687777dc04c4.tar.gz |
- jbj: another pass with splint: use malloc, not alloca.
Diffstat (limited to 'popt.c')
-rw-r--r-- | popt.c | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -316,7 +316,7 @@ static int handleAlias(/*@special@*/ poptContext con, int i; if (item) { - if (longName && item->option.longName + if (longName && item->option.longName != NULL && longNameLen == strlen(item->option.longName) && !strncmp(longName, item->option.longName, longNameLen)) return 0; @@ -346,7 +346,7 @@ static int handleAlias(/*@special@*/ poptContext con, if ((con->os - con->optionStack + 1) == POPT_OPTION_DEPTH) return POPT_ERROR_OPTSTOODEEP; - if (longName == NULL && nextArg && *nextArg) + if (longName == NULL && nextArg != NULL && *nextArg != '\0') con->os->nextCharArg = nextArg; con->os++; @@ -358,16 +358,21 @@ static int handleAlias(/*@special@*/ poptContext con, { const char ** av; int ac = con->os->currAlias->argc; /* Append --foo=bar arg to alias argv array (if present). */ - if (longName && nextArg && *nextArg) { - int i; - av = alloca((ac + 1 + 1) * sizeof(*av)); - for (i = 0; i < ac; i++) - av[i] = con->os->currAlias->argv[i]; - av[ac++] = nextArg; - av[ac] = NULL; + if (longName && nextArg != NULL && *nextArg != '\0') { + av = malloc((ac + 1 + 1) * sizeof(*av)); + if (av != NULL) { /* XXX won't happen. */ + for (i = 0; i < ac; i++) { + av[i] = con->os->currAlias->argv[i]; + } + av[ac++] = nextArg; + av[ac] = NULL; + } else /* XXX revert to old popt behavior if malloc fails. */ + av = con->os->currAlias->argv; } else av = con->os->currAlias->argv; rc = poptDupArgv(ac, av, &con->os->argc, &con->os->argv); + if (av != NULL && av != con->os->currAlias->argv) + free(av); } con->os->argb = NULL; |