Commit 894e6299 authored by Wayne Davison's avatar Wayne Davison

Some popt improvements:

- Fixed a bug in short-opt parsing when an abutting arg has an '='.
- Allow a short-opt to be separated from its arg by an '='.
- Avoid an IBM-checker warning about an impossible case in a switch
  and a warning about a potential NULL-pointer dereference.
- Fixed a memory leak.
parent c0801903
...@@ -809,16 +809,20 @@ int poptGetNextOpt(poptContext con) ...@@ -809,16 +809,20 @@ int poptGetNextOpt(poptContext con)
*oe++ = '\0'; *oe++ = '\0';
/* XXX longArg is mapped back to persistent storage. */ /* XXX longArg is mapped back to persistent storage. */
longArg = origOptString + (oe - localOptString); longArg = origOptString + (oe - localOptString);
} } else
oe = NULL;
opt = findOption(con->options, optString, '\0', &cb, &cbData, opt = findOption(con->options, optString, '\0', &cb, &cbData,
singleDash); singleDash);
if (!opt && !singleDash) if (!opt && !singleDash)
return POPT_ERROR_BADOPT; return POPT_ERROR_BADOPT;
if (!opt && oe)
oe[-1] = '='; /* restore overwritten '=' */
} }
if (!opt) { if (!opt) {
con->os->nextCharArg = origOptString + 1; con->os->nextCharArg = origOptString + 1;
longArg = NULL;
} else { } else {
if (con->os == con->optionStack && if (con->os == con->optionStack &&
opt->argInfo & POPT_ARGFLAG_STRIP) opt->argInfo & POPT_ARGFLAG_STRIP)
...@@ -856,7 +860,7 @@ int poptGetNextOpt(poptContext con) ...@@ -856,7 +860,7 @@ int poptGetNextOpt(poptContext con)
origOptString++; origOptString++;
if (*origOptString != '\0') if (*origOptString != '\0')
con->os->nextCharArg = origOptString; con->os->nextCharArg = origOptString + (*origOptString == '=');
} }
/*@=branchstate@*/ /*@=branchstate@*/
......
...@@ -121,7 +121,7 @@ getArgDescrip(const struct poptOption * opt, ...@@ -121,7 +121,7 @@ getArgDescrip(const struct poptOption * opt,
if (opt->argDescrip) return D_(translation_domain, opt->argDescrip); if (opt->argDescrip) return D_(translation_domain, opt->argDescrip);
switch (opt->argInfo & POPT_ARG_MASK) { switch (opt->argInfo & POPT_ARG_MASK) {
case POPT_ARG_NONE: return POPT_("NONE"); /*case POPT_ARG_NONE: return POPT_("NONE");*/ /* impossible */
#ifdef DYING #ifdef DYING
case POPT_ARG_VAL: return POPT_("VAL"); case POPT_ARG_VAL: return POPT_("VAL");
#else #else
...@@ -767,6 +767,9 @@ static int showShortOptions(const struct poptOption * opt, FILE * fp, ...@@ -767,6 +767,9 @@ static int showShortOptions(const struct poptOption * opt, FILE * fp,
char * s = (str != NULL ? str : memset(alloca(300), 0, 300)); char * s = (str != NULL ? str : memset(alloca(300), 0, 300));
int len = 0; int len = 0;
if (s == NULL)
return 0;
/*@-boundswrite@*/ /*@-boundswrite@*/
if (opt != NULL) if (opt != NULL)
for (; (opt->longName || opt->shortName || opt->arg); opt++) { for (; (opt->longName || opt->shortName || opt->arg); opt++) {
......
...@@ -163,8 +163,10 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl ...@@ -163,8 +163,10 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl
p++; p++;
linelen = strlen(p); linelen = strlen(p);
if (linelen >= maxlinelen-1) if (linelen >= maxlinelen-1) {
free(argstr);
return POPT_ERROR_OVERFLOW; /* XXX line too long */ return POPT_ERROR_OVERFLOW; /* XXX line too long */
}
if (*p == '\0' || *p == '\n') continue; /* line is empty */ if (*p == '\0' || *p == '\n') continue; /* line is empty */
if (*p == '#') continue; /* comment line */ if (*p == '#') continue; /* comment line */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment