1 --- rpm-4.0.2/popt/Makefile.am.wiget Tue Apr 25 22:14:21 2000
2 +++ rpm-4.0.2/popt/Makefile.am Wed May 30 14:12:30 2001
9 + @echo $(libpopt_la_SOURCES:%=popt/%)
13 lclint ${DEFS} ${INCLUDES} ${libpopt_la_SOURCES}
14 --- rpm-4.0.2/popt/findme.c.wiget Tue Dec 19 23:25:15 2000
15 +++ rpm-4.0.2/popt/findme.c Wed May 30 14:12:30 2001
17 char * start, * chptr;
20 + if (argv0 == NULL) return NULL; /* XXX can't happen */
21 /* If there is a / in the argv[0], it has to be an absolute path */
22 if (strchr(argv0, '/'))
23 return xstrdup(argv0);
25 - if (!path) return NULL;
26 + if (path == NULL) return NULL;
28 start = pathbuf = alloca(strlen(path) + 1);
29 buf = malloc(strlen(path) + strlen(argv0) + sizeof("/"));
30 + if (buf == NULL) return NULL; /* XXX can't happen */
31 strcpy(pathbuf, path);
34 --- rpm-4.0.2/popt/findme.h.wiget Tue Jan 2 18:25:32 2001
35 +++ rpm-4.0.2/popt/findme.h Wed May 30 14:12:30 2001
37 * @param argv0 name of executable
38 * @return (malloc'd) absolute path to executable (or NULL)
40 -/*@null@*/ const char * findProgramPath(const char * argv0);
41 +/*@null@*/ const char * findProgramPath(/*@null@*/ const char * argv0);
44 --- rpm-4.0.2/popt/missing.wiget Thu Oct 8 16:23:56 1998
45 +++ rpm-4.0.2/popt/missing Wed May 30 14:12:30 2001
48 # Common stub for a few missing GNU programs while installing.
49 -# Copyright (C) 1996, 1997 Free Software Foundation, Inc.
50 -# Franc,ois Pinard <pinard@iro.umontreal.ca>, 1996.
51 +# Copyright 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
52 +# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
54 # This program is free software; you can redistribute it and/or modify
55 # it under the terms of the GNU General Public License as published by
64 + # Try to run requested program, and just exit if it succeeds.
71 +# If it does not exist, or fails to run (possibly an outdated version),
75 -h|--h|--he|--hel|--help)
78 -h, --help display this help and exit
79 -v, --version output version information and exit
80 + --run try to run the given command, and emulate it if it fails
82 Supported PROGRAM values:
83 aclocal touch file \`aclocal.m4'
85 automake touch all \`Makefile.in' files
86 bison create \`y.tab.[ch]', if possible, from existing .[ch]
87 flex create \`lex.yy.c', if possible, from existing .c
88 + help2man touch the output file
89 lex create \`lex.yy.c', if possible, from existing .c
90 makeinfo touch the output file
91 + tar try tar, gnutar, gtar, then tar without non-portable flags
92 yacc create \`y.tab.[ch]', if possible, from existing .[ch]"
95 -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
96 - echo "missing - GNU libit 0.0"
97 + echo "missing 0.3 - GNU automake"
102 you modified \`acconfig.h' or \`configure.in'. You might want
103 to install the \`Autoconf' and \`GNU m4' packages. Grab them
104 from any GNU archive site."
105 - files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER([^):]*:\([^)]*\)).*/\1/p' configure.in`
106 - if test -z "$files"; then
107 - files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^):]*\)).*/\1/p' configure.in`
108 - test -z "$files" || files="$files.in"
110 - files=`echo "$files" | sed -e 's/:/ /g'`
112 - test -z "$files" && files="config.h.in"
114 + files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' configure.in`
115 + test -z "$files" && files="config.h"
117 + for f in $files; do
119 + *:*) touch_files="$touch_files "`echo "$f" |
120 + sed -e 's/^[^:]*://' -e 's/:.*//'`;;
121 + *) touch_files="$touch_files $f.in";;
129 you modified \`Makefile.am', \`acinclude.m4' or \`configure.in'.
130 You might want to install the \`Automake' and \`Perl' packages.
131 Grab them from any GNU archive site."
132 - find . -type f -name Makefile.am -print \
133 - | sed 's/^\(.*\).am$/touch \1.in/' \
135 + find . -type f -name Makefile.am -print |
136 + sed 's/\.am$/.in/' |
137 + while read f; do touch "$f"; done
147 +WARNING: \`$1' is missing on your system. You should only need it if
148 + you modified a dependency of a manual page. You may need the
149 + \`Help2man' package in order for those modifications to take
150 + effect. You can get \`Help2man' from any GNU archive site."
152 + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
153 + if test -z "$file"; then
154 + file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
156 + if [ -f "$file" ]; then
159 + test -z "$file" || exec >$file
160 + echo ".ab help2man is required to generate this page"
167 WARNING: \`$1' is missing on your system. You should only need it if
169 file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
176 + if test -n "$run"; then
177 + echo 1>&2 "ERROR: \`tar' requires --run"
181 + # We have already tried tar in the generic part.
182 + # Look for gnutar/gtar before invocation to avoid ugly error
184 + if (gnutar --version > /dev/null 2>&1); then
185 + gnutar ${1+"$@"} && exit 0
187 + if (gtar --version > /dev/null 2>&1); then
188 + gtar ${1+"$@"} && exit 0
192 + case "$firstarg" in
194 + firstarg=`echo "$firstarg" | sed s/o//`
195 + tar "$firstarg" ${1+"$@"} && exit 0
198 + case "$firstarg" in
200 + firstarg=`echo "$firstarg" | sed s/h//`
201 + tar "$firstarg" ${1+"$@"} && exit 0
207 +WARNING: I can't seem to be able to run \`tar' with the given arguments.
208 + You may want to install GNU tar or Free paxutils, or check the
209 + command line arguments."
214 --- rpm-4.0.2/popt/popt.3.wiget Wed Feb 7 18:56:53 2001
215 +++ rpm-4.0.2/popt/popt.3 Wed May 30 14:12:34 2001
218 .BR popt.ps " is a Postscript version of the above cited book "
219 chapter. It can be found in the source archive for popt available at:
220 -ftp://ftp.redhat.com/pub/redhat/code/popt
221 +ftp://ftp.rpm.org/pub/rpm.
222 --- rpm-4.0.2/popt/popt.c.wiget Tue Jan 16 13:53:13 2001
223 +++ rpm-4.0.2/popt/popt.c Wed May 30 14:12:34 2001
228 -void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) {
229 - if (con->execPath) free((void *)con->execPath);
231 +/*@unused@*/ static void prtcon(const char *msg, poptContext con)
233 + if (msg) fprintf(stderr, "%s", msg);
234 + fprintf(stderr, "\tcon %p os %p nextCharArg \"%s\" nextArg \"%s\" argv[%d] \"%s\"\n",
236 + (con->os->nextCharArg ? con->os->nextCharArg : ""),
237 + (con->os->nextArg ? con->os->nextArg : ""),
239 + (con->os->argv && con->os->argv[con->os->next]
240 + ? con->os->argv[con->os->next] : ""));
244 +void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
246 + con->execPath = _free(con->execPath);
247 con->execPath = xstrdup(path);
248 con->execAbsolute = allowAbsolute;
251 static void invokeCallbacksPRE(poptContext con, const struct poptOption * opt)
252 + /*@modifies internalState@*/
255 for (; opt->longName || opt->shortName || opt->arg; opt++) {
256 + if (opt->arg == NULL) continue; /* XXX program error. */
257 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
258 /* Recurse on included sub-tables. */
259 invokeCallbacksPRE(con, opt->arg);
260 } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK &&
261 (opt->argInfo & POPT_CBFLAG_PRE))
262 - { poptCallbackType cb = (poptCallbackType)opt->arg;
263 + { /*@-castfcnptr@*/
264 + poptCallbackType cb = (poptCallbackType)opt->arg;
266 /* Perform callback. */
267 cb(con, POPT_CALLBACK_REASON_PRE, NULL, NULL, opt->descrip);
272 static void invokeCallbacksPOST(poptContext con, const struct poptOption * opt)
273 + /*@modifies internalState@*/
276 for (; opt->longName || opt->shortName || opt->arg; opt++) {
277 + if (opt->arg == NULL) continue; /* XXX program error. */
278 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
279 /* Recurse on included sub-tables. */
280 invokeCallbacksPOST(con, opt->arg);
281 } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK &&
282 (opt->argInfo & POPT_CBFLAG_POST))
283 - { poptCallbackType cb = (poptCallbackType)opt->arg;
284 + { /*@-castfcnptr@*/
285 + poptCallbackType cb = (poptCallbackType)opt->arg;
287 /* Perform callback. */
288 cb(con, POPT_CALLBACK_REASON_POST, NULL, NULL, opt->descrip);
291 static void invokeCallbacksOPTION(poptContext con,
292 const struct poptOption * opt,
293 const struct poptOption * myOpt,
294 - const void * myData, int shorty)
295 + /*@null@*/ const void * myData, int shorty)
296 + /*@modifies internalState@*/
298 const struct poptOption * cbopt = NULL;
301 for (; opt->longName || opt->shortName || opt->arg; opt++) {
302 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
303 /* Recurse on included sub-tables. */
304 - invokeCallbacksOPTION(con, opt->arg, myOpt, myData, shorty);
305 + if (opt->arg != NULL) /* XXX program error */
306 + invokeCallbacksOPTION(con, opt->arg, myOpt, myData, shorty);
307 } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK &&
308 !(opt->argInfo & POPT_CBFLAG_SKIPOPTION)) {
309 /* Save callback info. */
311 ((myOpt->shortName && opt->shortName && shorty &&
312 myOpt->shortName == opt->shortName) ||
313 (myOpt->longName && opt->longName &&
314 + /*@-nullpass@*/ /* LCL: opt->longName != NULL */
315 !strcmp(myOpt->longName, opt->longName)))
318 - { poptCallbackType cb = (poptCallbackType)cbopt->arg;
319 + { /*@-castfcnptr@*/
320 + poptCallbackType cb = (poptCallbackType)cbopt->arg;
322 const void * cbData = (cbopt->descrip ? cbopt->descrip : myData);
323 /* Perform callback. */
324 - cb(con, POPT_CALLBACK_REASON_OPTION, myOpt,
325 + if (cb != NULL) { /* XXX program error */
326 + cb(con, POPT_CALLBACK_REASON_OPTION, myOpt,
327 con->os->nextArg, cbData);
329 /* Terminate (unless explcitly continuing). */
330 if (!(cbopt->argInfo & POPT_CBFLAG_CONTINUE))
332 @@ -104,18 +138,23 @@
334 poptContext con = malloc(sizeof(*con));
336 + if (con == NULL) return NULL; /* XXX can't happen */
337 memset(con, 0, sizeof(*con));
339 con->os = con->optionStack;
340 con->os->argc = argc;
341 + /*@-dependenttrans@*/ /* FIX: W2DO? */
342 con->os->argv = argv;
343 + /*@=dependenttrans@*/
344 con->os->argb = NULL;
346 if (!(flags & POPT_CONTEXT_KEEP_FIRST))
347 con->os->next = 1; /* skip argv[0] */
349 con->leftovers = calloc( (argc + 1), sizeof(char *) );
350 + /*@-dependenttrans@*/ /* FIX: W2DO? */
351 con->options = options;
352 + /*@=dependenttrans@*/
356 @@ -129,40 +168,34 @@
357 if (getenv("POSIXLY_CORRECT") || getenv("POSIX_ME_HARDER"))
358 con->flags |= POPT_CONTEXT_POSIXMEHARDER;
361 - con->appName = strcpy(malloc(strlen(name) + 1), name);
363 + char * t = malloc(strlen(name) + 1);
364 + if (t) con->appName = strcpy(t, name);
367 invokeCallbacksPRE(con, con->options);
372 -static void cleanOSE(struct optionStackEntry *os)
373 +static void cleanOSE(/*@special@*/ struct optionStackEntry *os)
375 + /*@releases os->nextArg, os->argv, os->argb @*/
378 - free((void *)os->nextArg);
379 - os->nextArg = NULL;
382 - free((void *)os->argv);
386 - PBM_FREE(os->argb);
389 + os->nextArg = _free(os->nextArg);
390 + os->argv = _free(os->argv);
391 + os->argb = PBM_FREE(os->argb);
394 -void poptResetContext(poptContext con) {
395 +void poptResetContext(poptContext con)
399 + if (con == NULL) return;
400 while (con->os > con->optionStack) {
403 - if (con->os->argb) {
404 - PBM_FREE(con->os->argb);
405 - con->os->argb = NULL;
407 + con->os->argb = PBM_FREE(con->os->argb);
408 con->os->currAlias = NULL;
409 con->os->nextCharArg = NULL;
410 con->os->nextArg = NULL;
411 @@ -173,25 +206,29 @@
412 con->restLeftover = 0;
415 - for (i = 0; i < con->finalArgvCount; i++) {
416 - if (con->finalArgv[i]) {
417 - free((void *)con->finalArgv[i]);
418 - con->finalArgv[i] = NULL;
421 + if (con->finalArgv != NULL)
422 + for (i = 0; i < con->finalArgvCount; i++)
423 + /*@-unqualifiedtrans@*/ /* FIX: typedef double indirection. */
424 + con->finalArgv[i] = _free(con->finalArgv[i]);
425 + /*@=unqualifiedtrans@*/
427 con->finalArgvCount = 0;
429 - if (con->arg_strip) {
430 - PBM_FREE(con->arg_strip);
431 - con->arg_strip = NULL;
433 + con->arg_strip = PBM_FREE(con->arg_strip);
434 + /*@-nullstate@*/ /* FIX: con->finalArgv != NULL */
439 -/* Only one of longName, shortName may be set at a time */
440 -static int handleExec(poptContext con, char * longName, char shortName) {
441 +/* Only one of longName, shortName should be set, not both. */
442 +static int handleExec(/*@special@*/ poptContext con,
443 + /*@null@*/ const char * longName, char shortName)
444 + /*@uses con->execs, con->numExecs, con->flags, con->doExec,
445 + con->finalArgv, con->finalArgvAlloced, con->finalArgvCount @*/
449 + if (con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */
451 i = con->numExecs - 1;
453 while (i >= 0 && (!con->execs[i].longName ||
454 @@ -220,29 +257,44 @@
457 i = con->finalArgvCount++;
458 + if (con->finalArgv != NULL) /* XXX can't happen */
459 { char *s = malloc((longName ? strlen(longName) : 0) + 3);
461 - sprintf(s, "--%s", longName);
463 - sprintf(s, "-%c", shortName);
464 - con->finalArgv[i] = s;
465 + if (s != NULL) { /* XXX can't happen */
467 + sprintf(s, "--%s", longName);
469 + sprintf(s, "-%c", shortName);
470 + con->finalArgv[i] = s;
472 + con->finalArgv[i] = NULL;
475 + /*@-nullstate@*/ /* FIX: con->finalArgv[] == NULL */
480 /* Only one of longName, shortName may be set at a time */
481 -static int handleAlias(poptContext con, const char * longName, char shortName,
482 - /*@keep@*/ const char * nextCharArg) {
483 +static int handleAlias(/*@special@*/ poptContext con,
484 + /*@null@*/ const char * longName, char shortName,
485 + /*@keep@*/ /*@null@*/ const char * nextCharArg)
486 + /*@uses con->aliases, con->numAliases, con->optionStack,
487 + con->os, con->os->currAlias, con->os->currAlias->longName @*/
492 if (con->os->currAlias && con->os->currAlias->longName && longName &&
493 + /*@-nullpass@*/ /* LCL: con->os->currAlias->longName != NULL */
494 !strcmp(con->os->currAlias->longName, longName))
497 if (con->os->currAlias && shortName &&
498 shortName == con->os->currAlias->shortName)
501 + if (con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */
503 i = con->numAliases - 1;
505 while (i >= 0 && (!con->aliases[i].longName ||
506 @@ -266,27 +318,34 @@
507 con->os->nextArg = NULL;
508 con->os->nextCharArg = NULL;
509 con->os->currAlias = con->aliases + i;
510 - poptDupArgv(con->os->currAlias->argc, con->os->currAlias->argv,
511 + rc = poptDupArgv(con->os->currAlias->argc, con->os->currAlias->argv,
512 &con->os->argc, &con->os->argv);
513 con->os->argb = NULL;
516 + return (rc ? rc : 1);
519 -static void execCommand(poptContext con) {
520 +static int execCommand(poptContext con)
521 + /*@modifies fileSystem @*/
529 - poptParseArgvString(con->doExec->script, &sargc, &sargv);
530 + if (con->doExec == NULL || con->doExec->script == NULL) /*XXX can't happen*/
531 + return POPT_ERROR_NOARG;
532 + rc = poptParseArgvString(con->doExec->script, &sargc, &sargv);
535 if (sargv == NULL || sargc < 1 ||
536 (!con->execAbsolute && strchr(sargv[0], '/')))
538 + return POPT_ERROR_NOARG;
540 argv = malloc(sizeof(*argv) *
541 (6 + sargc + con->numLeftovers + con->finalArgvCount));
542 + if (argv == NULL) return POPT_ERROR_MALLOC; /* XXX can't happen */
544 if (!strchr(sargv[0], '/') && con->execPath) {
545 char *s = alloca(strlen(con->execPath) + strlen(sargv[0]) + sizeof("/"));
546 @@ -295,26 +354,31 @@
548 argv[argc] = findProgramPath(sargv[0]);
550 - if (argv[argc++] == NULL) return;
551 + if (argv[argc++] == NULL) return POPT_ERROR_NOARG;
554 memcpy(argv + argc, sargv + 1, sizeof(*argv) * (sargc - 1));
558 - memcpy(argv + argc, con->finalArgv, sizeof(*argv) * con->finalArgvCount);
559 - argc += con->finalArgvCount;
560 + if (con->finalArgv != NULL && con->finalArgvCount > 0) {
561 + memcpy(argv + argc, con->finalArgv,
562 + sizeof(*argv) * con->finalArgvCount);
563 + argc += con->finalArgvCount;
566 - if (con->numLeftovers) {
567 + if (con->leftovers != NULL && con->numLeftovers > 0) {
571 memcpy(argv + argc, con->leftovers, sizeof(*argv) * con->numLeftovers);
572 argc += con->numLeftovers;
575 - argv[argc++] = NULL;
579 - setresuid(getuid(), getuid(),-1);
580 + (void) setresuid(getuid(), getuid(),-1);
583 * XXX " ... on BSD systems setuid() should be preferred over setreuid()"
584 @@ -322,58 +386,68 @@
585 * XXX from Norbert Warmuth <nwarmuth@privat.circular.de>
587 #if defined(HAVE_SETUID)
589 + (void) setuid(getuid());
590 #elif defined (HAVE_SETREUID)
591 - setreuid(getuid(), getuid()); /*hlauer: not portable to hpux9.01 */
592 + (void) setreuid(getuid(), getuid()); /*hlauer: not portable to hpux9.01 */
594 ; /* Can't drop privileges */
600 + return POPT_ERROR_NOARG;
602 - { const char ** arg;
603 - fprintf(stderr, "==> execvp(%s):", argv[0]);
604 - for (arg = argv; *arg; arg++)
605 - fprintf(stderr, " %s", *arg);
606 + { const char ** avp;
607 + fprintf(stderr, "==> execvp(%s) argv[%d]:", argv[0], argc);
608 + for (avp = argv; *avp; avp++)
609 + fprintf(stderr, " '%s'", *avp);
610 fprintf(stderr, "\n");
614 - execvp(argv[0], (char *const *)argv);
615 + (void) execvp(argv[0], (char *const *)argv);
616 + return POPT_ERROR_ERRNO;
619 -/*@observer@*/ static const struct poptOption *
620 -findOption(const struct poptOption * opt, const char * longName,
622 - /*@out@*/ poptCallbackType * callback, /*@out@*/ const void ** callbackData,
624 +/*@observer@*/ /*@null@*/ static const struct poptOption *
625 +findOption(const struct poptOption * opt, /*@null@*/ const char * longName,
627 + /*@null@*/ /*@out@*/ poptCallbackType * callback,
628 + /*@null@*/ /*@out@*/ const void ** callbackData,
630 + /*@modifies *callback, *callbackData */
632 const struct poptOption * cb = NULL;
634 /* This happens when a single - is given */
635 - if (singleDash && !shortName && !*longName)
636 + if (singleDash && !shortName && (longName && *longName == '\0'))
639 for (; opt->longName || opt->shortName || opt->arg; opt++) {
641 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
642 const struct poptOption * opt2;
644 /* Recurse on included sub-tables. */
645 + if (opt->arg == NULL) continue; /* XXX program error */
646 opt2 = findOption(opt->arg, longName, shortName, callback,
647 callbackData, singleDash);
649 - /* Sub-table data will be inheirited if no data yet. */
650 - if (*callback && *callbackData == NULL)
651 - *callbackData = opt->descrip;
654 + if (opt2 == NULL) continue;
655 + /* Sub-table data will be inheirited if no data yet. */
656 + if (!(callback && *callback)) return opt2;
657 + if (!(callbackData && *callbackData == NULL)) return opt2;
658 + /*@-observertrans -dependenttrans @*/
659 + *callbackData = opt->descrip;
660 + /*@=observertrans =dependenttrans @*/
662 } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) {
664 } else if (longName && opt->longName &&
665 (!singleDash || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) &&
666 - !strcmp(longName, opt->longName)) {
667 + /*@-nullpass@*/ /* LCL: opt->longName != NULL */
668 + !strcmp(longName, opt->longName))
672 } else if (shortName && shortName == opt->shortName) {
674 @@ -382,18 +456,30 @@
676 if (!opt->longName && !opt->shortName)
678 - *callbackData = NULL;
680 + /*@-modobserver -mods @*/
681 + if (callback) *callback = NULL;
682 + if (callbackData) *callbackData = NULL;
684 - *callback = (poptCallbackType)cb->arg;
685 - if (!(cb->argInfo & POPT_CBFLAG_INC_DATA))
686 - *callbackData = cb->descrip;
689 + *callback = (poptCallbackType)cb->arg;
691 + if (!(cb->argInfo & POPT_CBFLAG_INC_DATA)) {
693 + /*@-observertrans@*/ /* FIX: typedef double indirection. */
694 + *callbackData = cb->descrip;
695 + /*@=observertrans@*/
698 + /*@=modobserver =mods @*/
703 -static const char *findNextArg(poptContext con, unsigned argx, int delete)
704 +static const char * findNextArg(/*@special@*/ poptContext con,
705 + unsigned argx, int delete)
706 + /*@uses con->optionStack, con->os,
707 + con->os->next, con->os->argb, con->os->argc, con->os->argv @*/
709 struct optionStackEntry * os = con->os;
713 while (os->next == os->argc && os > con->optionStack) os--;
714 if (os->next == os->argc && os == con->optionStack) break;
715 + if (os->argv != NULL)
716 for (i = os->next; i < os->argc; i++) {
717 if (os->argb && PBM_ISSET(i, os->argb)) continue;
718 if (*os->argv[i] == '-') continue;
722 if (os->argb == NULL) os->argb = PBM_ALLOC(os->argc);
723 + if (os->argb != NULL) /* XXX can't happen */
724 PBM_SET(i, os->argb);
727 @@ -419,15 +507,20 @@
731 -static /*@only@*/ const char * expandNextArg(poptContext con, const char * s)
732 +static /*@only@*/ /*@null@*/ const char *
733 +expandNextArg(/*@special@*/ poptContext con, const char * s)
734 + /*@uses con->optionStack, con->os,
735 + con->os->next, con->os->argb, con->os->argc, con->os->argv @*/
736 + /*@modifies con @*/
739 + const char * a = NULL;
742 size_t tn = strlen(s) + 1;
745 te = t = malloc(tn);;
746 + if (t == NULL) return NULL; /* XXX can't happen */
747 while ((c = *s++) != '\0') {
749 #if 0 /* XXX can't do this */
752 if (!(s[0] == '#' && s[1] == ':' && s[2] == '+'))
754 - if ((a = findNextArg(con, 1, 1)) == NULL)
756 + /* XXX Make sure that findNextArg deletes only next arg. */
758 + if ((a = findNextArg(con, 1, 1)) == NULL) break;
763 @@ -456,18 +551,25 @@
767 - t = realloc(t, strlen(t)+1); /* XXX memory leak, hard to plug */
768 + t = realloc(t, strlen(t) + 1); /* XXX memory leak, hard to plug */
772 static void poptStripArg(poptContext con, int which)
773 + /*@modifies con @*/
775 if (con->arg_strip == NULL)
776 con->arg_strip = PBM_ALLOC(con->optionStack[0].argc);
777 + if (con->arg_strip != NULL) /* XXX can't happen */
778 PBM_SET(which, con->arg_strip);
781 -static int poptSaveLong(const struct poptOption * opt, long aLong) {
782 +static int poptSaveLong(const struct poptOption * opt, long aLong)
783 + /*@modifies opt->arg @*/
785 + if (opt->arg == NULL)
786 + return POPT_ERROR_NULLARG;
788 if (opt->argInfo & POPT_ARGFLAG_NOT)
790 switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) {
791 @@ -485,12 +587,17 @@
794 return POPT_ERROR_BADOPERATION;
796 + /*@notreached@*/ break;
801 -static int poptSaveInt(const struct poptOption * opt, long aLong) {
802 +static int poptSaveInt(const struct poptOption * opt, long aLong)
803 + /*@modifies opt->arg @*/
805 + if (opt->arg == NULL)
806 + return POPT_ERROR_NULLARG;
808 if (opt->argInfo & POPT_ARGFLAG_NOT)
810 switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) {
811 @@ -508,31 +615,19 @@
814 return POPT_ERROR_BADOPERATION;
816 + /*@notreached@*/ break;
822 -static void prtcon(const char *msg, poptContext con)
824 - if (msg) fprintf(stderr, "%s", msg);
825 - fprintf(stderr, "\tcon %p os %p nextCharArg \"%s\" nextArg \"%s\" argv[%d] \"%s\"\n",
827 - (con->os->nextCharArg ? con->os->nextCharArg : ""),
828 - (con->os->nextArg ? con->os->nextArg : ""),
830 - (con->os->argv && con->os->argv[con->os->next]
831 - ? con->os->argv[con->os->next] : ""));
835 /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
836 int poptGetNextOpt(poptContext con)
838 const struct poptOption * opt = NULL;
844 const char * origOptString = NULL;
845 poptCallbackType cb = NULL;
848 if (!con->os->nextCharArg && con->os->next == con->os->argc) {
849 invokeCallbacksPOST(con, con->options);
850 - if (con->doExec) execCommand(con);
851 + if (con->doExec) return execCommand(con);
858 thisopt = con->os->next;
859 + if (con->os->argv != NULL) /* XXX can't happen */
860 origOptString = con->os->argv[con->os->next++];
862 + if (origOptString == NULL) /* XXX can't happen */
863 + return POPT_ERROR_BADOPT;
865 if (con->restLeftover || *origOptString != '-') {
866 + if (con->leftovers != NULL) /* XXX can't happen */
867 con->leftovers[con->numLeftovers++] = origOptString;
868 if (con->flags & POPT_CONTEXT_POSIXMEHARDER)
869 con->restLeftover = 1;
872 /* Make a copy we can hack at */
873 localOptString = optString =
874 - strcpy(alloca(strlen(origOptString) + 1),
876 + strcpy(alloca(strlen(origOptString) + 1), origOptString);
879 + if (optString[0] == '\0')
880 return POPT_ERROR_BADOPT;
882 if (optString[1] == '-' && !optString[2]) {
884 /* XXX aliases with arg substitution need "--alias=arg" */
885 if (handleAlias(con, optString, '\0', NULL))
888 if (handleExec(con, optString, '\0'))
892 con->os->nextCharArg = origOptString + 1;
894 if (con->os == con->optionStack &&
895 - opt->argInfo & POPT_ARGFLAG_STRIP) {
896 + opt->argInfo & POPT_ARGFLAG_STRIP)
899 poptStripArg(con, thisopt);
901 @@ -630,14 +731,14 @@
903 con->os->nextCharArg = NULL;
905 - if (handleAlias(con, NULL, *origOptString,
906 - origOptString + 1)) {
907 + if (handleAlias(con, NULL, *origOptString, origOptString + 1))
911 if (handleExec(con, NULL, *origOptString)) {
912 /* Restore rest of short options for further processing */
914 - if (*origOptString) con->os->nextCharArg = origOptString;
915 + if (*origOptString != '\0')
916 + con->os->nextCharArg = origOptString;
924 - if (*origOptString) con->os->nextCharArg = origOptString;
925 + /*@-branchstate@*/ /* FIX: W2DO? */
926 + if (*origOptString != '\0')
927 + con->os->nextCharArg = origOptString;
931 + if (opt == NULL) return POPT_ERROR_BADOPT; /* XXX can't happen */
932 if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) {
933 if (poptSaveInt(opt, 1L))
934 return POPT_ERROR_BADOPERATION;
935 @@ -660,14 +765,15 @@
936 return POPT_ERROR_BADOPERATION;
938 } else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) {
939 - if (con->os->nextArg) {
940 - free((void *)con->os->nextArg);
941 - con->os->nextArg = NULL;
943 + con->os->nextArg = _free(con->os->nextArg);
944 + /*@-usedef@*/ /* FIX: W2DO? */
946 - con->os->nextArg = expandNextArg(con, longArg);
948 + longArg = expandNextArg(con, longArg);
949 + con->os->nextArg = longArg;
950 } else if (con->os->nextCharArg) {
951 - con->os->nextArg = expandNextArg(con, con->os->nextCharArg);
952 + longArg = expandNextArg(con, con->os->nextCharArg);
953 + con->os->nextArg = longArg;
954 con->os->nextCharArg = NULL;
956 while (con->os->next == con->os->argc &&
957 @@ -681,17 +787,25 @@
958 return POPT_ERROR_NOARG;
961 - /* make sure this isn't part of a short arg or the
962 - result of an alias expansion */
964 + * Make sure this isn't part of a short arg or the
965 + * result of an alias expansion.
967 if (con->os == con->optionStack &&
968 - opt->argInfo & POPT_ARGFLAG_STRIP &&
969 + (opt->argInfo & POPT_ARGFLAG_STRIP) &&
971 poptStripArg(con, con->os->next);
974 - con->os->nextArg = expandNextArg(con, con->os->argv[con->os->next++]);
975 + if (con->os->argv != NULL) { /* XXX can't happen */
976 + /* XXX watchout: subtle side-effects live here. */
977 + longArg = con->os->argv[con->os->next++];
978 + longArg = expandNextArg(con, longArg);
979 + con->os->nextArg = longArg;
986 switch (opt->argInfo & POPT_ARG_MASK) {
987 @@ -731,32 +845,31 @@
990 if (con->os->nextArg) {
991 + int saveerrno = errno;
993 aDouble = strtod(con->os->nextArg, &end);
995 + if (errno == ERANGE)
996 + return POPT_ERROR_OVERFLOW;
999 return POPT_ERROR_BADNUMBER;
1002 - if (aDouble == +HUGE_VAL || aDouble == -HUGE_VAL)
1003 - return POPT_ERROR_OVERFLOW;
1004 - if (aDouble == 0.0 && errno == ERANGE)
1005 - return POPT_ERROR_OVERFLOW;
1006 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_DOUBLE) {
1007 *((double *) opt->arg) = aDouble;
1012 -#define ABS(a) (((a) < 0) ? -(a) : (a))
1013 - if (ABS(aDouble) > FLT_MAX)
1014 +#define _ABS(a) ((((a) - 0.0) < DBL_EPSILON) ? -(a) : (a))
1015 + if ((_ABS(aDouble) - FLT_MAX) > DBL_EPSILON)
1016 return POPT_ERROR_OVERFLOW;
1017 - if (ABS(aDouble) < FLT_MIN)
1018 + if ((FLT_MIN - _ABS(aDouble)) > DBL_EPSILON)
1019 return POPT_ERROR_OVERFLOW;
1020 *((float *) opt->arg) = aDouble;
1024 - fprintf(stdout, POPT_("option type (%d) not implemented in popt\n"),
1025 - opt->argInfo & POPT_ARG_MASK);
1027 + POPT_("option type (%d) not implemented in popt\n"),
1028 + (opt->argInfo & POPT_ARG_MASK));
1032 @@ -773,83 +886,107 @@
1033 sizeof(*con->finalArgv) * con->finalArgvAlloced);
1036 + if (con->finalArgv != NULL)
1037 { char *s = malloc((opt->longName ? strlen(opt->longName) : 0) + 3);
1038 - if (opt->longName)
1039 - sprintf(s, "%s%s",
1040 - ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"),
1043 - sprintf(s, "-%c", opt->shortName);
1044 - con->finalArgv[con->finalArgvCount++] = s;
1045 + if (s != NULL) { /* XXX can't happen */
1046 + if (opt->longName)
1047 + sprintf(s, "%s%s",
1048 + ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"),
1051 + sprintf(s, "-%c", opt->shortName);
1052 + con->finalArgv[con->finalArgvCount++] = s;
1054 + con->finalArgv[con->finalArgvCount++] = NULL;
1057 if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE)
1059 + /*@-ifempty@*/ ; /*@=ifempty@*/
1060 else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL)
1062 + /*@-ifempty@*/ ; /*@=ifempty@*/
1063 else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) {
1064 - if (con->os->nextArg)
1065 + if (con->finalArgv != NULL && con->os->nextArg)
1066 con->finalArgv[con->finalArgvCount++] =
1067 + /*@-nullpass@*/ /* LCL: con->os->nextArg != NULL */
1068 xstrdup(con->os->nextArg);
1074 + return (opt ? opt->val : -1); /* XXX can't happen */
1077 -const char * poptGetOptArg(poptContext con) {
1078 - const char * ret = con->os->nextArg;
1079 - con->os->nextArg = NULL;
1080 +const char * poptGetOptArg(poptContext con)
1082 + const char * ret = NULL;
1084 + ret = con->os->nextArg;
1085 + con->os->nextArg = NULL;
1090 -const char * poptGetArg(poptContext con) {
1091 - const char * ret = (con->nextLeftover < con->numLeftovers)
1092 - ? con->leftovers[con->nextLeftover++] : NULL;
1093 +const char * poptGetArg(poptContext con)
1095 + const char * ret = NULL;
1096 + if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers)
1097 + ret = con->leftovers[con->nextLeftover++];
1101 -const char * poptPeekArg(poptContext con) {
1102 - const char * ret = (con->nextLeftover < con->numLeftovers)
1103 - ? con->leftovers[con->nextLeftover] : NULL;
1104 +const char * poptPeekArg(poptContext con)
1106 + const char * ret = NULL;
1107 + if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers)
1108 + ret = con->leftovers[con->nextLeftover];
1112 -const char ** poptGetArgs(poptContext con) {
1113 - if (con->numLeftovers == con->nextLeftover) return NULL;
1114 +const char ** poptGetArgs(poptContext con)
1116 + if (con == NULL ||
1117 + con->leftovers == NULL || con->numLeftovers == con->nextLeftover)
1120 /* some apps like [like RPM ;-) ] need this NULL terminated */
1121 con->leftovers[con->numLeftovers] = NULL;
1123 + /*@-nullret -nullstate @*/ /* FIX: typedef double indirection. */
1124 return (con->leftovers + con->nextLeftover);
1125 + /*@=nullret =nullstate @*/
1128 -void poptFreeContext(poptContext con) {
1129 +poptContext poptFreeContext(poptContext con)
1133 + if (con == NULL) return con;
1134 poptResetContext(con);
1135 - if (con->os->argb) free(con->os->argb);
1136 + con->os->argb = _free(con->os->argb);
1138 + if (con->aliases != NULL)
1139 for (i = 0; i < con->numAliases; i++) {
1140 - if (con->aliases[i].longName) free((void *)con->aliases[i].longName);
1141 - free(con->aliases[i].argv);
1142 + con->aliases[i].longName = _free(con->aliases[i].longName);
1143 + con->aliases[i].argv = _free(con->aliases[i].argv);
1146 + if (con->execs != NULL)
1147 for (i = 0; i < con->numExecs; i++) {
1148 - if (con->execs[i].longName) free((void *)con->execs[i].longName);
1149 - free((void *)con->execs[i].script);
1150 + con->execs[i].longName = _free(con->execs[i].longName);
1151 + con->execs[i].script = _free(con->execs[i].script);
1153 - if (con->execs) free((void *)con->execs);
1154 + con->execs = _free(con->execs);
1156 - free(con->leftovers);
1157 - free(con->finalArgv);
1158 - if (con->appName) free((void *)con->appName);
1159 - if (con->aliases) free(con->aliases);
1160 - if (con->otherHelp) free((void *)con->otherHelp);
1161 - if (con->execPath) free((void *)con->execPath);
1162 - if (con->arg_strip) PBM_FREE(con->arg_strip);
1163 + con->leftovers = _free(con->leftovers);
1164 + con->finalArgv = _free(con->finalArgv);
1165 + con->appName = _free(con->appName);
1166 + con->aliases = _free(con->aliases);
1167 + con->otherHelp = _free(con->otherHelp);
1168 + con->execPath = _free(con->execPath);
1169 + con->arg_strip = PBM_FREE(con->arg_strip);
1176 int poptAddAlias(poptContext con, struct poptAlias newAlias,
1177 @@ -867,7 +1004,9 @@
1178 alias = con->aliases + aliasNum;
1180 alias->longName = (newAlias.longName)
1181 + /*@-nullpass@*/ /* FIX: malloc can return NULL. */
1182 ? strcpy(malloc(strlen(newAlias.longName) + 1), newAlias.longName)
1185 alias->shortName = newAlias.shortName;
1186 alias->argc = newAlias.argc;
1187 @@ -876,18 +1015,20 @@
1191 -const char * poptBadOption(poptContext con, int flags) {
1192 - struct optionStackEntry * os;
1193 +const char * poptBadOption(poptContext con, int flags)
1195 + struct optionStackEntry * os = NULL;
1197 - if (flags & POPT_BADOPTION_NOALIAS)
1198 - os = con->optionStack;
1202 + os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os;
1204 - return os->argv[os->next - 1];
1205 + /*@-nullderef@*/ /* LCL: os->argv != NULL */
1206 + return (os && os->argv ? os->argv[os->next - 1] : NULL);
1210 -const char *const poptStrerror(const int error) {
1211 +const char *const poptStrerror(const int error)
1214 case POPT_ERROR_NOARG:
1215 return POPT_("missing argument");
1216 @@ -895,6 +1036,8 @@
1217 return POPT_("unknown option");
1218 case POPT_ERROR_BADOPERATION:
1219 return POPT_("mutually exclusive logical operations requested");
1220 + case POPT_ERROR_NULLARG:
1221 + return POPT_("opt->arg should not be NULL");
1222 case POPT_ERROR_OPTSTOODEEP:
1223 return POPT_("aliases nested too deeply");
1224 case POPT_ERROR_BADQUOTE:
1225 @@ -903,6 +1046,8 @@
1226 return POPT_("invalid numeric value");
1227 case POPT_ERROR_OVERFLOW:
1228 return POPT_("number too large or too small");
1229 + case POPT_ERROR_MALLOC:
1230 + return POPT_("memory allocation failed");
1231 case POPT_ERROR_ERRNO:
1232 return strerror(errno);
1234 @@ -910,8 +1055,10 @@
1238 -int poptStuffArgs(poptContext con, const char ** argv) {
1239 +int poptStuffArgs(poptContext con, const char ** argv)
1244 if ((con->os - con->optionStack) == POPT_OPTION_DEPTH)
1245 return POPT_ERROR_OPTSTOODEEP;
1246 @@ -924,30 +1071,34 @@
1247 con->os->nextArg = NULL;
1248 con->os->nextCharArg = NULL;
1249 con->os->currAlias = NULL;
1250 - poptDupArgv(argc, argv, &con->os->argc, &con->os->argv);
1251 + rc = poptDupArgv(argc, argv, &con->os->argc, &con->os->argv);
1252 con->os->argb = NULL;
1253 con->os->stuffed = 1;
1259 -const char * poptGetInvocationName(poptContext con) {
1260 - return con->os->argv[0];
1261 +const char * poptGetInvocationName(poptContext con)
1263 + return (con->os->argv ? con->os->argv[0] : "");
1266 -int poptStrippedArgv(poptContext con, int argc, char **argv)
1267 +int poptStrippedArgv(poptContext con, int argc, char ** argv)
1269 - int i,j=1, numargs=argc;
1270 + int numargs = argc;
1274 + if (con->arg_strip)
1275 for (i = 1; i < argc; i++) {
1276 if (PBM_ISSET(i, con->arg_strip))
1280 for (i = 1; i < argc; i++) {
1281 - if (PBM_ISSET(i, con->arg_strip))
1282 + if (con->arg_strip && PBM_ISSET(i, con->arg_strip))
1284 - argv[j] = (j < numargs) ? argv[i] : '\0';
1285 + argv[j] = (j < numargs) ? argv[i] : NULL;
1289 --- rpm-4.0.2/popt/popt.h.wiget Tue Jan 2 18:25:32 2001
1290 +++ rpm-4.0.2/popt/popt.h Wed May 30 14:12:34 2001
1292 #define POPT_ERROR_BADNUMBER -17 /*!< invalid numeric value */
1293 #define POPT_ERROR_OVERFLOW -18 /*!< number too large or too small */
1294 #define POPT_ERROR_BADOPERATION -19 /*!< mutually exclusive logical operations requested */
1295 +#define POPT_ERROR_NULLARG -20 /*!< opt->arg should not be NULL */
1296 +#define POPT_ERROR_MALLOC -21 /*!< memory allocation failed */
1302 /*@shared@*/ /*@null@*/ void * arg; /*!< depends on argInfo */
1303 int val; /*!< 0 means don't return, just update flag */
1304 -/*@shared@*/ /*@null@*/ const char * descrip; /*!< description for autohelp -- may be NULL */
1305 -/*@shared@*/ /*@null@*/ const char * argDescrip; /*!< argument description for autohelp */
1306 +/*@observer@*/ /*@null@*/ const char * descrip; /*!< description for autohelp -- may be NULL */
1307 +/*@observer@*/ /*@null@*/ const char * argDescrip; /*!< argument description for autohelp */
1315 -typedef struct poptContext_s * poptContext;
1316 +typedef /*@abstract@*/ struct poptContext_s * poptContext;
1320 @@ -156,9 +158,10 @@
1321 * @param data @todo Document.
1323 typedef void (*poptCallbackType) (poptContext con,
1324 - enum poptCallbackReason reason,
1325 - const struct poptOption * opt,
1326 - const char * arg, const void * data);
1327 + enum poptCallbackReason reason,
1328 + /*@null@*/ const struct poptOption * opt,
1329 + /*@null@*/ const char * arg,
1330 + /*@null@*/ const void * data);
1333 * Initialize popt context.
1334 @@ -169,62 +172,65 @@
1335 * @param flags or'd POPT_CONTEXT_* bits
1336 * @return initialized popt context
1338 -/*@only@*/ poptContext poptGetContext(/*@keep@*/ const char * name,
1339 - int argc, /*@keep@*/ const char ** argv,
1340 - /*@keep@*/ const struct poptOption * options, int flags);
1341 +/*@only@*/ /*@null@*/ poptContext poptGetContext(
1342 + /*@dependent@*/ /*@keep@*/ const char * name,
1343 + int argc, /*@dependent@*/ /*@keep@*/ const char ** argv,
1344 + /*@dependent@*/ /*@keep@*/ const struct poptOption * options,
1348 * Reinitialize popt context.
1349 * @param con context
1351 -void poptResetContext(poptContext con);
1352 +void poptResetContext(/*@null@*/poptContext con);
1355 * Return value of next option found.
1356 * @param con context
1357 * @return next option val, -1 on last item, POPT_ERROR_* on error
1359 -int poptGetNextOpt(poptContext con);
1360 +int poptGetNextOpt(/*@null@*/poptContext con);
1361 /* returns NULL if no argument is available */
1364 * @param con context
1366 -/*@observer@*/ /*@null@*/ const char * poptGetOptArg(poptContext con);
1367 +/*@observer@*/ /*@null@*/ const char * poptGetOptArg(/*@null@*/poptContext con);
1370 * Return current option's argument.
1371 * @param con context
1372 * @return option argument, NULL if no more options are available
1374 -/*@observer@*/ /*@null@*/ const char * poptGetArg(poptContext con);
1375 +/*@observer@*/ /*@null@*/ const char * poptGetArg(/*@null@*/poptContext con);
1378 * Peek at current option's argument.
1379 * @param con context
1380 * @return option argument
1382 -/*@observer@*/ /*@null@*/ const char * poptPeekArg(poptContext con);
1383 +/*@observer@*/ /*@null@*/ const char * poptPeekArg(/*@null@*/poptContext con);
1386 * Return remaining arguments.
1387 * @param con context
1388 * @return argument array, terminated with NULL
1390 -/*@observer@*/ /*@null@*/ const char ** poptGetArgs(poptContext con);
1391 +/*@observer@*/ /*@null@*/ const char ** poptGetArgs(/*@null@*/poptContext con);
1394 * Return the option which caused the most recent error.
1395 * @param con context
1396 * @return offending option
1398 -/*@observer@*/ const char * poptBadOption(poptContext con, int flags);
1399 +/*@observer@*/ const char * poptBadOption(/*@null@*/poptContext con, int flags);
1403 * @param con context
1406 -void poptFreeContext( /*@only@*/ poptContext con);
1407 +/*@null@*/ poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con);
1410 * Add arguments to context.
1412 * @param fn file name to read
1413 * @return 0 on success, POPT_ERROR_ERRNO on failure
1415 -int poptReadConfigFile(poptContext con, const char * fn);
1416 +int poptReadConfigFile(poptContext con, const char * fn)
1417 + /*@modifies fileSystem,
1418 + con->execs, con->numExecs @*/;
1421 * Read default configuration from /etc/popt and $HOME/.popt.
1423 * @param useEnv (unused)
1424 * @return 0 on success, POPT_ERROR_ERRNO on failure
1426 -int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv);
1427 +int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv)
1428 + /*@modifies fileSystem,
1429 + con->execs, con->numExecs @*/;
1432 * Duplicate an argument array.
1433 @@ -271,8 +281,10 @@
1434 * @retval argvPtr address of returned argument array
1435 * @return 0 on success, POPT_ERROR_NOARG on failure
1437 -int poptDupArgv(int argc, const char **argv,
1438 - /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr);
1439 +int poptDupArgv(int argc, /*@null@*/ const char **argv,
1440 + /*@null@*/ /*@out@*/ int * argcPtr,
1441 + /*@null@*/ /*@out@*/ const char *** argvPtr)
1442 + /*@modifies *argcPtr, *argvPtr @*/;
1445 * Parse a string into an argument array.
1446 @@ -286,14 +298,16 @@
1447 * @retval argvPtr address of returned argument array
1449 int poptParseArgvString(const char * s,
1450 - /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr);
1451 + /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr)
1452 + /*@modifies *argcPtr, *argvPtr @*/;
1455 * Return formatted error string for popt failure.
1456 * @param error popt error
1457 * @return error string
1459 -/*@observer@*/ const char *const poptStrerror(const int error);
1460 +/*@observer@*/ const char *const poptStrerror(const int error)
1464 * Limit search for executables.
1466 * @param con context
1469 -int poptStrippedArgv(poptContext con, int argc, char **argv);
1470 +int poptStrippedArgv(poptContext con, int argc, char ** argv);
1474 --- rpm-4.0.2/popt/poptconfig.c.wiget Tue Dec 19 23:26:02 2000
1475 +++ rpm-4.0.2/popt/poptconfig.c Wed May 30 14:12:34 2001
1478 #include "poptint.h"
1480 -static void configLine(poptContext con, char * line) {
1481 +static void configLine(poptContext con, char * line)
1482 + /*@modifies *line,
1483 + con->execs, con->numExecs @*/
1485 int nameLength = strlen(con->appName);
1488 struct poptAlias alias;
1490 - char * longName = NULL;
1491 + const char * entryType;
1492 + const char * longName = NULL;
1493 char shortName = '\0';
1495 if (strncmp(line, con->appName, nameLength)) return;
1497 - if (!*line || !isspace(*line)) return;
1498 - while (*line && isspace(*line)) line++;
1499 + if (*line == '\0' || !isspace(*line)) return;
1500 + while (*line != '\0' && isspace(*line)) line++;
1503 - while (!*line || !isspace(*line)) line++;
1504 + while (*line == '\0' || !isspace(*line)) line++;
1506 - while (*line && isspace(*line)) line++;
1507 - if (!*line) return;
1508 + while (*line != '\0' && isspace(*line)) line++;
1509 + if (*line == '\0') return;
1512 - while (!*line || !isspace(*line)) line++;
1513 + while (*line == '\0' || !isspace(*line)) line++;
1515 - while (*line && isspace(*line)) line++;
1516 - if (!*line) return;
1517 + while (*line != '\0' && isspace(*line)) line++;
1518 + if (*line == '\0') return;
1520 if (opt[0] == '-' && opt[1] == '-')
1523 if (!strcmp(entryType, "alias")) {
1524 if (poptParseArgvString(line, &alias.argc, &alias.argv)) return;
1525 alias.longName = longName, alias.shortName = shortName;
1526 - poptAddAlias(con, alias, 0);
1527 + (void) poptAddAlias(con, alias, 0);
1528 } else if (!strcmp(entryType, "exec")) {
1529 con->execs = realloc(con->execs,
1530 sizeof(*con->execs) * (con->numExecs + 1));
1531 + if (con->execs == NULL) return; /* XXX can't happen */
1533 con->execs[con->numExecs].longName = xstrdup(longName);
1536 con->execs[con->numExecs].shortName = shortName;
1537 con->execs[con->numExecs].script = xstrdup(line);
1539 + /*@-noeffect@*/ /* LCL: broken? */
1545 -int poptReadConfigFile(poptContext con, const char * fn) {
1546 - char * file, * chptr, * end;
1547 - char * buf, * dst;
1548 +int poptReadConfigFile(poptContext con, const char * fn)
1550 + const char * file, * chptr, * end;
1552 +/*@dependent@*/ char * dst;
1557 fd = open(fn, O_RDONLY);
1559 - if (errno == ENOENT)
1562 - return POPT_ERROR_ERRNO;
1565 + return (errno == ENOENT ? 0 : POPT_ERROR_ERRNO);
1567 fileLength = lseek(fd, 0, SEEK_END);
1568 - (void) lseek(fd, 0, 0);
1569 + if (fileLength == -1 || lseek(fd, 0, 0) == -1) {
1573 + return POPT_ERROR_ERRNO;
1576 file = alloca(fileLength + 1);
1577 - if (read(fd, file, fileLength) != fileLength) {
1578 + if (read(fd, (char *)file, fileLength) != fileLength) {
1583 return POPT_ERROR_ERRNO;
1586 + if (close(fd) == -1)
1587 + return POPT_ERROR_ERRNO;
1589 dst = buf = alloca(fileLength + 1);
1592 end = (file + fileLength);
1593 + /*@-infloops@*/ /* LCL: can't detect chptr++ */
1594 while (chptr < end) {
1599 while (*dst && isspace(*dst)) dst++;
1600 - if (*dst && *dst != '#') {
1601 + if (*dst && *dst != '#')
1602 configLine(con, dst);
1620 --- rpm-4.0.2/popt/popthelp.c.wiget Thu Feb 22 21:36:56 2001
1621 +++ rpm-4.0.2/popt/popthelp.c Wed May 30 14:12:34 2001
1627 struct poptOption poptHelpOptions[] = {
1628 { NULL, '\0', POPT_ARG_CALLBACK, (void *)&displayArgs, '\0', NULL, NULL },
1629 { "help", '?', 0, NULL, '?', N_("Show this help message"), NULL },
1630 { "usage", '\0', 0, NULL, 'u', N_("Display brief usage message"), NULL },
1636 /*@observer@*/ /*@null@*/ static const char *const
1637 -getTableTranslationDomain(const struct poptOption *table)
1638 +getTableTranslationDomain(/*@null@*/ const struct poptOption *table)
1640 - const struct poptOption *opt;
1643 - opt->longName || opt->shortName || opt->arg;
1645 - if(opt->argInfo == POPT_ARG_INTL_DOMAIN)
1648 + const struct poptOption *opt;
1651 + if (table != NULL)
1652 + for (opt = table; opt->longName || opt->shortName || opt->arg; opt++) {
1653 + if (opt->argInfo == POPT_ARG_INTL_DOMAIN)
1659 /*@observer@*/ /*@null@*/ static const char *const
1660 -getArgDescrip(const struct poptOption * opt, const char *translation_domain)
1661 +getArgDescrip(const struct poptOption * opt,
1662 + /*@-paramuse@*/ /* FIX: wazzup? */
1663 + /*@null@*/ const char * translation_domain)
1666 if (!(opt->argInfo & POPT_ARG_MASK)) return NULL;
1671 static void singleOptionHelp(FILE * f, int maxLeftCol,
1672 - const struct poptOption * opt,
1673 - const char *translation_domain)
1674 + const struct poptOption * opt,
1675 + /*@null@*/ const char *translation_domain)
1677 int indentLength = maxLeftCol + 5;
1678 int lineLength = 79 - indentLength;
1679 @@ -173,20 +175,22 @@
1682 static int maxArgWidth(const struct poptOption * opt,
1683 - const char * translation_domain)
1684 + /*@null@*/ const char * translation_domain)
1692 while (opt->longName || opt->shortName || opt->arg) {
1693 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
1694 + if (opt->arg) /* XXX program error */
1695 this = maxArgWidth(opt->arg, translation_domain);
1696 if (this > max) max = this;
1697 } else if (!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) {
1698 this = sizeof(" ")-1;
1699 - if (opt->shortName) this += sizeof("-X")-1;
1700 - if (opt->shortName && opt->longName) this += sizeof(", ")-1;
1701 + if (opt->shortName != '\0') this += sizeof("-X")-1;
1702 + if (opt->shortName != '\0' && opt->longName) this += sizeof(", ")-1;
1703 if (opt->longName) {
1704 this += ((opt->argInfo & POPT_ARGFLAG_ONEDASH)
1705 ? sizeof("-")-1 : sizeof("--")-1);
1706 @@ -206,23 +210,25 @@
1710 -static void singleTableHelp(FILE * f, const struct poptOption * table,
1712 - const char *translation_domain)
1713 +static void singleTableHelp(FILE * f,
1714 + /*@null@*/ const struct poptOption * table, int left,
1715 + /*@null@*/ const char * translation_domain)
1717 const struct poptOption * opt;
1718 const char *sub_transdom;
1720 + if (table != NULL)
1721 for (opt = table; (opt->longName || opt->shortName || opt->arg); opt++) {
1722 if ((opt->longName || opt->shortName) &&
1723 !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN))
1724 singleOptionHelp(f, left, opt, translation_domain);
1727 + if (table != NULL)
1728 for (opt = table; (opt->longName || opt->shortName || opt->arg); opt++) {
1729 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
1730 sub_transdom = getTableTranslationDomain(opt->arg);
1732 + if (sub_transdom == NULL)
1733 sub_transdom = translation_domain;
1736 @@ -240,7 +246,10 @@
1738 fprintf(f, POPT_("Usage:"));
1739 if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) {
1740 + /*@-nullderef@*/ /* LCL: wazzup? */
1741 fn = con->optionStack->argv[0];
1743 + if (fn == NULL) return len;
1744 if (strchr(fn, '/')) fn = strrchr(fn, '/') + 1;
1745 fprintf(f, " %s", fn);
1746 len += strlen(fn) + 1;
1751 - showHelpIntro(con, f);
1752 + (void) showHelpIntro(con, f);
1754 fprintf(f, " %s\n", con->otherHelp);
1756 @@ -264,15 +273,15 @@
1759 static int singleOptionUsage(FILE * f, int cursor,
1760 - const struct poptOption * opt,
1761 - const char *translation_domain)
1762 + const struct poptOption * opt,
1763 + /*@null@*/ const char *translation_domain)
1766 char shortStr[2] = { '\0', '\0' };
1767 const char * item = shortStr;
1768 const char * argDescrip = getArgDescrip(opt, translation_domain);
1770 - if (opt->shortName) {
1771 + if (opt->shortName!= '\0' ) {
1772 if (!(opt->argInfo & POPT_ARG_MASK))
1773 return cursor; /* we did these already */
1775 @@ -296,47 +305,57 @@
1776 fprintf(f, " [-%s%s%s%s]",
1777 ((opt->shortName || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) ? "" : "-"),
1779 - (argDescrip ? (opt->shortName ? " " : "=") : ""),
1780 + (argDescrip ? (opt->shortName != '\0' ? " " : "=") : ""),
1781 (argDescrip ? argDescrip : ""));
1783 return cursor + len + 1;
1786 -static int singleTableUsage(FILE * f, int cursor,
1787 - const struct poptOption * opt, const char * translation_domain)
1788 +static int singleTableUsage(FILE * f,
1789 + int cursor, const struct poptOption * opt,
1790 + /*@null@*/ const char * translation_domain)
1792 + /*@-branchstate@*/ /* FIX: W2DO? */
1794 for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
1795 - if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN)
1796 + if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) {
1797 translation_domain = (const char *)opt->arg;
1798 - else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE)
1799 + } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
1800 + if (opt->arg) /* XXX program error */
1801 cursor = singleTableUsage(f, cursor, opt->arg, translation_domain);
1802 - else if ((opt->longName || opt->shortName) &&
1803 - !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN))
1804 + } else if ((opt->longName || opt->shortName) &&
1805 + !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) {
1806 cursor = singleOptionUsage(f, cursor, opt, translation_domain);
1809 + /*@=branchstate@*/
1814 -static int showShortOptions(const struct poptOption * opt, FILE * f, char * str)
1815 +static int showShortOptions(const struct poptOption * opt, FILE * f,
1816 + /*@null@*/ char * str)
1818 - char s[300]; /* this is larger then the ascii set, so
1819 - it should do just fine */
1820 + char * s = alloca(300); /* larger then the ascii set */
1823 + /*@-branchstate@*/ /* FIX: W2DO? */
1825 memset(s, 0, sizeof(s));
1828 + /*@=branchstate@*/
1831 for (; (opt->longName || opt->shortName || opt->arg); opt++) {
1832 if (opt->shortName && !(opt->argInfo & POPT_ARG_MASK))
1833 str[strlen(str)] = opt->shortName;
1834 else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE)
1835 - showShortOptions(opt->arg, f, str);
1836 + if (opt->arg) /* XXX program error */
1837 + (void) showShortOptions(opt->arg, f, str);
1840 - if (s != str || !*s)
1841 + if (s != str || *s != '\0')
1844 fprintf(f, " [-%s]", s);
1847 cursor = showHelpIntro(con, f);
1848 cursor += showShortOptions(con->options, f, NULL);
1849 - singleTableUsage(f, cursor, con->options, NULL);
1850 + (void) singleTableUsage(f, cursor, con->options, NULL);
1852 if (con->otherHelp) {
1853 cursor += strlen(con->otherHelp) + 1;
1854 --- rpm-4.0.2/popt/poptint.h.wiget Tue Jan 2 00:23:45 2001
1855 +++ rpm-4.0.2/popt/poptint.h Wed May 30 14:12:34 2001
1861 + * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
1862 + * @param this memory to free
1863 + * @retval NULL always
1865 +/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) {
1866 + if (this != NULL) free((void *)this);
1870 /* Bit mask macros. */
1871 typedef unsigned int __pbm_bits;
1872 #define __PBM_NBITS (8 * sizeof (__pbm_bits))
1874 #define __PBM_BITS(set) ((set)->bits)
1876 #define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits))
1877 -#define PBM_FREE(s) free(s);
1878 +#define PBM_FREE(s) _free(s);
1879 #define PBM_SET(d, s) (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d))
1880 #define PBM_CLR(d, s) (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d))
1881 #define PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0)
1883 struct optionStackEntry {
1885 -/*@only@*/ const char ** argv;
1886 -/*@only@*/ pbm_set * argb;
1887 +/*@only@*/ /*@null@*/ const char ** argv;
1888 +/*@only@*/ /*@null@*/ pbm_set * argb;
1890 -/*@only@*/ const char * nextArg;
1891 -/*@keep@*/ const char * nextCharArg;
1892 -/*@dependent@*/ struct poptAlias * currAlias;
1893 +/*@only@*/ /*@null@*/ const char * nextArg;
1894 +/*@keep@*/ /*@null@*/ const char * nextCharArg;
1895 +/*@dependent@*/ /*@null@*/ struct poptAlias * currAlias;
1900 - const char * longName;
1901 +/*@owned@*/ /*@null@*/ const char * longName;
1903 - const char * script;
1904 +/*@only@*/ /*@null@*/ const char * script;
1907 struct poptContext_s {
1908 struct optionStackEntry optionStack[POPT_OPTION_DEPTH];
1909 /*@dependent@*/ struct optionStackEntry * os;
1910 -/*@owned@*/ const char ** leftovers;
1911 +/*@owned@*/ /*@null@*/ const char ** leftovers;
1914 /*@keep@*/ const struct poptOption * options;
1916 -/*@only@*/ const char * appName;
1917 -/*@only@*/ struct poptAlias * aliases;
1918 +/*@only@*/ /*@null@*/ const char * appName;
1919 +/*@only@*/ /*@null@*/ struct poptAlias * aliases;
1922 - struct execEntry * execs;
1923 +/*@owned@*/ /*@null@*/ struct execEntry * execs;
1925 -/*@only@*/ const char ** finalArgv;
1926 +/*@only@*/ /*@null@*/ const char ** finalArgv;
1928 int finalArgvAlloced;
1929 -/*@dependent@*/ struct execEntry * doExec;
1930 +/*@dependent@*/ /*@null@*/ struct execEntry * doExec;
1931 /*@only@*/ const char * execPath;
1933 /*@only@*/ const char * otherHelp;
1934 - pbm_set * arg_strip;
1935 +/*@null@*/ pbm_set * arg_strip;
1938 #ifdef HAVE_LIBINTL_H
1939 --- rpm-4.0.2/popt/poptparse.c.wiget Tue Dec 19 23:26:19 2000
1940 +++ rpm-4.0.2/popt/poptparse.c Wed May 30 14:12:34 2001
1945 + if (argc <= 0 || argv == NULL) /* XXX can't happen */
1946 + return POPT_ERROR_NOARG;
1947 for (i = 0; i < argc; i++) {
1948 if (argv[i] == NULL)
1949 return POPT_ERROR_NOARG;
1954 + if (dst == NULL) /* XXX can't happen */
1955 + return POPT_ERROR_MALLOC;
1956 argv2 = (void *) dst;
1957 dst += (argc + 1) * sizeof(*argv);
1978 int buflen = strlen(s) + 1;
1979 char * buf = memset(alloca(buflen), 0, buflen);
1980 + int rc = POPT_ERROR_MALLOC;
1982 + if (argv == NULL) return rc;
1985 - for (src = s; *src; src++) {
1986 + for (src = s; *src != '\0'; src++) {
1987 if (quote == *src) {
1989 - } else if (quote) {
1990 + } else if (quote != '\0') {
1995 - return POPT_ERROR_BADQUOTE;
1996 + rc = POPT_ERROR_BADQUOTE;
1999 if (*src != quote) *buf++ = '\\';
2002 } else if (isspace(*src)) {
2003 - if (*argv[argc]) {
2004 + if (*argv[argc] != '\0') {
2006 if (argc == argvAlloced) {
2007 argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA;
2008 argv = realloc(argv, sizeof(*argv) * argvAlloced);
2009 + if (argv == NULL) goto exit;
2018 - return POPT_ERROR_BADQUOTE;
2019 + rc = POPT_ERROR_BADQUOTE;
2028 - (void) poptDupArgv(argc, argv, argcPtr, argvPtr);
2031 + rc = poptDupArgv(argc, argv, argcPtr, argvPtr);
2035 + if (argv) free(argv);
2038 --- rpm-4.0.2/popt/system.h.wiget Mon Oct 25 20:22:20 1999
2039 +++ rpm-4.0.2/popt/system.h Wed May 30 14:12:34 2001
2042 /*@only@*/ char * xstrdup (const char *str);
2044 +#if !defined(__LCLINT__)
2045 #if HAVE_MCHECK_H && defined(__GNUC__)
2046 #define vmefail() (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL)
2047 #define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str)))
2049 #define xstrdup(_str) strdup(_str)
2050 #endif /* HAVE_MCHECK_H && defined(__GNUC__) */
2051 +#endif /* !__LCLINT__ */
2055 --- rpm-4.0.2/popt/test1.c.wiget Sun Dec 31 20:49:44 2000
2056 +++ rpm-4.0.2/popt/test1.c Wed May 30 14:12:34 2001
2058 fprintf(stdout, "\n");
2061 - poptFreeContext(optCon);
2062 + optCon = poptFreeContext(optCon);
2063 #if HAVE_MCHECK_H && HAVE_MTRACE
2064 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
2066 --- rpm-4.0.2/popt/test2.c.wiget Wed Feb 23 18:20:20 2000
2067 +++ rpm-4.0.2/popt/test2.c Wed May 30 14:12:34 2001
2069 /* although there are no options to be parsed, check for --help */
2070 poptGetNextOpt(optCon);
2072 - poptFreeContext(optCon);
2073 + optCon = poptFreeContext(optCon);
2075 printf( "dbusername %s\tdbpassword %s\n"
2076 "txhost %s\ttxsslport %d\ttxstoreid %d\tpathofkeyfile %s\n"
2077 --- rpm-4.0.2/popt/testit.sh.wiget Fri Jan 12 17:34:29 2001
2078 +++ rpm-4.0.2/popt/testit.sh Wed May 30 14:12:34 2001
2080 run test1 "test1 - 19" "" --echo-args
2081 run test1 "test1 - 20" "--arg1" --echo-args --arg1
2082 run test1 "test1 - 21" "--arg2 something" -T something -e
2083 -run test1 "test1 - 22" "--arg2 something -- more args" -T something -a more args
2084 +run test1 "test1 - 22" "--arg2 something more args" -T something -a more args
2085 run test1 "test1 - 23" "--echo-args -a" --echo-args -e -a
2086 run test1 "test1 - 24" "arg1: 0 arg2: (none) short: 1" -shortoption
2087 run test1 "test1 - 25" "arg1: 0 arg2: (none) short: 1" --shortoption
2088 --- rpm/popt/acconfig.h.wiget Wed May 30 15:31:40 2001
2089 +++ rpm/popt/acconfig.h Wed May 30 15:32:19 2001
2091 a given entry is in the file.
2093 Leave the following blank line there!! Autoheader needs it. */
2096 /* Define to the name of the distribution. */
2099 /* Absolute path to popt top_sourcedir. */
2100 #undef POPT_SOURCE_PATH
2103 /* Leave that blank line there!! Autoheader needs it.
2104 If you're adding to this file, keep in mind:
2105 The entries are in sort -df order: alphabetical, case insensitive,