- fix: short option help missing string terminator.
authorjbj <devnull@localhost>
Tue, 18 Mar 2003 17:48:19 +0000 (17:48 +0000)
committerjbj <devnull@localhost>
Tue, 18 Mar 2003 17:48:19 +0000 (17:48 +0000)
CVS patchset: 6704
CVS date: 2003/03/18 17:48:19

CHANGES
popt/popthelp.c
rpm.spec.in

diff --git a/CHANGES b/CHANGES
index 1a95350..2687518 100644 (file)
--- 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.
index 4d8f0ef..14b07b2 100644 (file)
@@ -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)
index ecfb959..891f817 100644 (file)
@@ -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.