summaryrefslogtreecommitdiff
path: root/popt
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2008-03-08 10:54:17 -0800
committerWayne Davison <wayned@samba.org>2008-03-08 11:02:40 -0800
commit894e6299c10e24d1745d268b465695934f4bb1a9 (patch)
tree50b7ed3efb14cfd3a7d2c0b5528775f3461b880a /popt
parentc080190365fceef2d35ee63f408bba16f09ca112 (diff)
downloadrsync-894e6299c10e24d1745d268b465695934f4bb1a9.tar.gz
rsync-894e6299c10e24d1745d268b465695934f4bb1a9.tar.bz2
rsync-894e6299c10e24d1745d268b465695934f4bb1a9.zip
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.
Diffstat (limited to 'popt')
-rw-r--r--popt/popt.c8
-rw-r--r--popt/popthelp.c5
-rw-r--r--popt/poptparse.c4
3 files changed, 13 insertions, 4 deletions
diff --git a/popt/popt.c b/popt/popt.c
index a2c24e78..a01b6b96 100644
--- a/popt/popt.c
+++ b/popt/popt.c
@@ -809,16 +809,20 @@ int poptGetNextOpt(poptContext con)
*oe++ = '\0';
/* XXX longArg is mapped back to persistent storage. */
longArg = origOptString + (oe - localOptString);
- }
+ } else
+ oe = NULL;
opt = findOption(con->options, optString, '\0', &cb, &cbData,
singleDash);
if (!opt && !singleDash)
return POPT_ERROR_BADOPT;
+ if (!opt && oe)
+ oe[-1] = '='; /* restore overwritten '=' */
}
if (!opt) {
con->os->nextCharArg = origOptString + 1;
+ longArg = NULL;
} else {
if (con->os == con->optionStack &&
opt->argInfo & POPT_ARGFLAG_STRIP)
@@ -856,7 +860,7 @@ int poptGetNextOpt(poptContext con)
origOptString++;
if (*origOptString != '\0')
- con->os->nextCharArg = origOptString;
+ con->os->nextCharArg = origOptString + (*origOptString == '=');
}
/*@=branchstate@*/
diff --git a/popt/popthelp.c b/popt/popthelp.c
index ba8d0243..6a009766 100644
--- a/popt/popthelp.c
+++ b/popt/popthelp.c
@@ -121,7 +121,7 @@ getArgDescrip(const struct poptOption * opt,
if (opt->argDescrip) return D_(translation_domain, opt->argDescrip);
switch (opt->argInfo & POPT_ARG_MASK) {
- case POPT_ARG_NONE: return POPT_("NONE");
+ /*case POPT_ARG_NONE: return POPT_("NONE");*/ /* impossible */
#ifdef DYING
case POPT_ARG_VAL: return POPT_("VAL");
#else
@@ -767,6 +767,9 @@ static int showShortOptions(const struct poptOption * opt, FILE * fp,
char * s = (str != NULL ? str : memset(alloca(300), 0, 300));
int len = 0;
+ if (s == NULL)
+ return 0;
+
/*@-boundswrite@*/
if (opt != NULL)
for (; (opt->longName || opt->shortName || opt->arg); opt++) {
diff --git a/popt/poptparse.c b/popt/poptparse.c
index bb3b69d6..e003a04a 100644
--- a/popt/poptparse.c
+++ b/popt/poptparse.c
@@ -163,8 +163,10 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl
p++;
linelen = strlen(p);
- if (linelen >= maxlinelen-1)
+ if (linelen >= maxlinelen-1) {
+ free(argstr);
return POPT_ERROR_OVERFLOW; /* XXX line too long */
+ }
if (*p == '\0' || *p == '\n') continue; /* line is empty */
if (*p == '#') continue; /* comment line */