diff options
author | jbj <devnull@localhost> | 2003-03-18 17:48:19 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2003-03-18 17:48:19 +0000 |
commit | d2a425e0158a0dced5bf199f229924890067c563 (patch) | |
tree | 6a1a3fcef98ca683729758d2c477976ad75f1e68 /popt | |
parent | 5fe1914a155697b4f14483a394de9b25a4af5c19 (diff) | |
download | rpm-d2a425e0158a0dced5bf199f229924890067c563.tar.gz rpm-d2a425e0158a0dced5bf199f229924890067c563.tar.bz2 rpm-d2a425e0158a0dced5bf199f229924890067c563.zip |
- fix: short option help missing string terminator.
CVS patchset: 6704
CVS date: 2003/03/18 17:48:19
Diffstat (limited to 'popt')
-rw-r--r-- | popt/popthelp.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/popt/popthelp.c b/popt/popthelp.c index 4d8f0efc2..14b07b24a 100644 --- a/popt/popthelp.c +++ b/popt/popthelp.c @@ -677,33 +677,29 @@ static int showShortOptions(const struct poptOption * opt, FILE * fp, /*@null@*/ char * str) /*@globals fileSystem @*/ /*@modifies *str, *fp, fileSystem @*/ + /*@requires maxRead(str) >= 0 @*/ { - char * s = alloca(300); /* larger then the ascii set */ - - s[0] = '\0'; - /*@-branchstate@*/ /* FIX: W2DO? */ - if (str == NULL) { - memset(s, 0, sizeof(s)); - str = s; - } - /*@=branchstate@*/ + /* bufsize larger then the ascii set, lazy alloca on top level call. */ + char * s = (str != NULL ? str : memset(alloca(300), 0, 300)); + int len = 0; /*@-boundswrite@*/ if (opt != NULL) for (; (opt->longName || opt->shortName || opt->arg); opt++) { if (opt->shortName && !(opt->argInfo & POPT_ARG_MASK)) - str[strlen(str)] = opt->shortName; + s[strlen(s)] = opt->shortName; else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) if (opt->arg) /* XXX program error */ - (void) showShortOptions(opt->arg, fp, str); + len = showShortOptions(opt->arg, fp, s); } /*@=boundswrite@*/ - if (s != str || *s != '\0') - return 0; - - fprintf(fp, " [-%s]", s); - return strlen(s) + 4; + /* On return to top level, print the short options, return print length. */ + if (s == str && *s != '\0') { + fprintf(fp, " [-%s]", s); + len = strlen(s) + sizeof(" [-]")-1; + } + return len; } void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags) |