From: jbj Date: Tue, 18 Mar 2003 17:48:19 +0000 (+0000) Subject: - fix: short option help missing string terminator. X-Git-Tag: rpm-4.4-release~647 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d2a425e0158a0dced5bf199f229924890067c563;p=platform%2Fupstream%2Frpm.git - fix: short option help missing string terminator. CVS patchset: 6704 CVS date: 2003/03/18 17:48:19 --- diff --git a/CHANGES b/CHANGES index 1a95350..2687518 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ - upgrade to zlib-1.2.beta7. - pass structure pointer, not args, through headerSprintf call chain. - add ":xml" header format modifier. + - --queryformat '[%%{*:xml}\n]' to dump header content in XML. + - fix: short option help missing string terminator. 4.1 -> 4.2: - set cachesize without a dbenv, the default is far too small. diff --git a/popt/popthelp.c b/popt/popthelp.c index 4d8f0ef..14b07b2 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) diff --git a/rpm.spec.in b/rpm.spec.in index ecfb959..891f817 100644 --- a/rpm.spec.in +++ b/rpm.spec.in @@ -475,3 +475,4 @@ exit 0 - pass structure pointer, not args, through headerSprintf call chain. - add ":xml" tag format modifier. - --queryformat '[%%{*:xml}\n]' to dump header content in XML. +- fix: short option help missing string terminator.