]> git.pld-linux.org Git - packages/rpm.git/blame - popt-cvs20010530.patch
- added %ifarch for PPC port of PLD :)
[packages/rpm.git] / popt-cvs20010530.patch
CommitLineData
70b78c8f
AF
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
3@@ -34,6 +34,10 @@
4
5 man_MANS = popt.3
6
7+.PHONY: sources
8+sources:
9+ @echo $(libpopt_la_SOURCES:%=popt/%)
10+
11 .PHONY: lclint
12 lclint:
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
16@@ -15,14 +15,16 @@
17 char * start, * chptr;
18 char * buf;
19
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);
24
25- if (!path) return NULL;
26+ if (path == NULL) return NULL;
27
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);
32
33 chptr = NULL;
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
36@@ -14,6 +14,6 @@
37 * @param argv0 name of executable
38 * @return (malloc'd) absolute path to executable (or NULL)
39 */
40-/*@null@*/ const char * findProgramPath(const char * argv0);
41+/*@null@*/ const char * findProgramPath(/*@null@*/ const char * argv0);
42
43 #endif
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
46@@ -1,7 +1,7 @@
47 #! /bin/sh
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.
53
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
56@@ -23,6 +23,19 @@
57 exit 1
58 fi
59
60+run=:
61+
62+case "$1" in
63+--run)
64+ # Try to run requested program, and just exit if it succeeds.
65+ run=
66+ shift
67+ "$@" && exit 0
68+ ;;
69+esac
70+
71+# If it does not exist, or fails to run (possibly an outdated version),
72+# try to emulate it.
73 case "$1" in
74
75 -h|--h|--he|--hel|--help)
76@@ -35,6 +48,7 @@
77 Options:
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
81
82 Supported PROGRAM values:
83 aclocal touch file \`aclocal.m4'
84@@ -43,13 +57,15 @@
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]"
93 ;;
94
95 -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
96- echo "missing - GNU libit 0.0"
97+ echo "missing 0.3 - GNU automake"
98 ;;
99
100 -*)
101@@ -82,15 +98,17 @@
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"
109- else
110- files=`echo "$files" | sed -e 's/:/ /g'`
111- fi
112- test -z "$files" && files="config.h.in"
113- touch $files
114+ files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' configure.in`
115+ test -z "$files" && files="config.h"
116+ touch_files=
117+ for f in $files; do
118+ case "$f" in
119+ *:*) touch_files="$touch_files "`echo "$f" |
120+ sed -e 's/^[^:]*://' -e 's/:.*//'`;;
121+ *) touch_files="$touch_files $f.in";;
122+ esac
123+ done
124+ touch $touch_files
125 ;;
126
127 automake)
128@@ -99,9 +117,9 @@
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/' \
134- | sh
135+ find . -type f -name Makefile.am -print |
136+ sed 's/\.am$/.in/' |
137+ while read f; do touch "$f"; done
138 ;;
139
140 bison|yacc)
141@@ -157,6 +175,26 @@
142 fi
143 ;;
144
145+ help2man)
146+ echo 1>&2 "\
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."
151+
152+ file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
153+ if test -z "$file"; then
154+ file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
155+ fi
156+ if [ -f "$file" ]; then
157+ touch $file
158+ else
159+ test -z "$file" || exec >$file
160+ echo ".ab help2man is required to generate this page"
161+ exit 1
162+ fi
163+ ;;
164+
165 makeinfo)
166 echo 1>&2 "\
167 WARNING: \`$1' is missing on your system. You should only need it if
168@@ -171,6 +209,45 @@
169 file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
170 fi
171 touch $file
172+ ;;
173+
174+ tar)
175+ shift
176+ if test -n "$run"; then
177+ echo 1>&2 "ERROR: \`tar' requires --run"
178+ exit 1
179+ fi
180+
181+ # We have already tried tar in the generic part.
182+ # Look for gnutar/gtar before invocation to avoid ugly error
183+ # messages.
184+ if (gnutar --version > /dev/null 2>&1); then
185+ gnutar ${1+"$@"} && exit 0
186+ fi
187+ if (gtar --version > /dev/null 2>&1); then
188+ gtar ${1+"$@"} && exit 0
189+ fi
190+ firstarg="$1"
191+ if shift; then
192+ case "$firstarg" in
193+ *o*)
194+ firstarg=`echo "$firstarg" | sed s/o//`
195+ tar "$firstarg" ${1+"$@"} && exit 0
196+ ;;
197+ esac
198+ case "$firstarg" in
199+ *h*)
200+ firstarg=`echo "$firstarg" | sed s/h//`
201+ tar "$firstarg" ${1+"$@"} && exit 0
202+ ;;
203+ esac
204+ fi
205+
206+ echo 1>&2 "\
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."
210+ exit 1
211 ;;
212
213 *)
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
216@@ -757,4 +757,4 @@
217 .sp
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
224@@ -30,21 +30,41 @@
225 }
226 #endif
227
228-void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) {
229- if (con->execPath) free((void *)con->execPath);
230+#ifdef MYDEBUG
231+/*@unused@*/ static void prtcon(const char *msg, poptContext con)
232+{
233+ if (msg) fprintf(stderr, "%s", msg);
234+ fprintf(stderr, "\tcon %p os %p nextCharArg \"%s\" nextArg \"%s\" argv[%d] \"%s\"\n",
235+ con, con->os,
236+ (con->os->nextCharArg ? con->os->nextCharArg : ""),
237+ (con->os->nextArg ? con->os->nextArg : ""),
238+ con->os->next,
239+ (con->os->argv && con->os->argv[con->os->next]
240+ ? con->os->argv[con->os->next] : ""));
241+}
242+#endif
243+
244+void poptSetExecPath(poptContext con, const char * path, int allowAbsolute)
245+{
246+ con->execPath = _free(con->execPath);
247 con->execPath = xstrdup(path);
248 con->execAbsolute = allowAbsolute;
249 }
250
251 static void invokeCallbacksPRE(poptContext con, const struct poptOption * opt)
252+ /*@modifies internalState@*/
253 {
254+ if (opt != NULL)
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;
265+ /*@=castfcnptr@*/
266 /* Perform callback. */
267 cb(con, POPT_CALLBACK_REASON_PRE, NULL, NULL, opt->descrip);
268 }
269@@ -52,14 +72,19 @@
270 }
271
272 static void invokeCallbacksPOST(poptContext con, const struct poptOption * opt)
273+ /*@modifies internalState@*/
274 {
275+ if (opt != NULL)
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;
286+ /*@=castfcnptr@*/
287 /* Perform callback. */
288 cb(con, POPT_CALLBACK_REASON_POST, NULL, NULL, opt->descrip);
289 }
290@@ -69,14 +94,17 @@
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@*/
297 {
298 const struct poptOption * cbopt = NULL;
299
300+ if (opt != 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. */
310@@ -85,13 +113,19 @@
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)))
316+ /*@=nullpass@*/
317 )
318- { poptCallbackType cb = (poptCallbackType)cbopt->arg;
319+ { /*@-castfcnptr@*/
320+ poptCallbackType cb = (poptCallbackType)cbopt->arg;
321+ /*@=castfcnptr@*/
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);
328+ }
329 /* Terminate (unless explcitly continuing). */
330 if (!(cbopt->argInfo & POPT_CBFLAG_CONTINUE))
331 return;
332@@ -104,18 +138,23 @@
333 {
334 poptContext con = malloc(sizeof(*con));
335
336+ if (con == NULL) return NULL; /* XXX can't happen */
337 memset(con, 0, sizeof(*con));
338
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;
345
346 if (!(flags & POPT_CONTEXT_KEEP_FIRST))
347 con->os->next = 1; /* skip argv[0] */
348
349 con->leftovers = calloc( (argc + 1), sizeof(char *) );
350+ /*@-dependenttrans@*/ /* FIX: W2DO? */
351 con->options = options;
352+ /*@=dependenttrans@*/
353 con->aliases = NULL;
354 con->numAliases = 0;
355 con->flags = flags;
356@@ -129,40 +168,34 @@
357 if (getenv("POSIXLY_CORRECT") || getenv("POSIX_ME_HARDER"))
358 con->flags |= POPT_CONTEXT_POSIXMEHARDER;
359
360- if (name)
361- con->appName = strcpy(malloc(strlen(name) + 1), name);
362+ if (name) {
363+ char * t = malloc(strlen(name) + 1);
364+ if (t) con->appName = strcpy(t, name);
365+ }
366
367 invokeCallbacksPRE(con, con->options);
368
369 return con;
370 }
371
372-static void cleanOSE(struct optionStackEntry *os)
373+static void cleanOSE(/*@special@*/ struct optionStackEntry *os)
374+ /*@uses os @*/
375+ /*@releases os->nextArg, os->argv, os->argb @*/
376 {
377- if (os->nextArg) {
378- free((void *)os->nextArg);
379- os->nextArg = NULL;
380- }
381- if (os->argv) {
382- free((void *)os->argv);
383- os->argv = NULL;
384- }
385- if (os->argb) {
386- PBM_FREE(os->argb);
387- os->argb = NULL;
388- }
389+ os->nextArg = _free(os->nextArg);
390+ os->argv = _free(os->argv);
391+ os->argb = PBM_FREE(os->argb);
392 }
393
394-void poptResetContext(poptContext con) {
395+void poptResetContext(poptContext con)
396+{
397 int i;
398
399+ if (con == NULL) return;
400 while (con->os > con->optionStack) {
401 cleanOSE(con->os--);
402 }
403- if (con->os->argb) {
404- PBM_FREE(con->os->argb);
405- con->os->argb = NULL;
406- }
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;
413 con->doExec = NULL;
414
415- for (i = 0; i < con->finalArgvCount; i++) {
416- if (con->finalArgv[i]) {
417- free((void *)con->finalArgv[i]);
418- con->finalArgv[i] = NULL;
419- }
420- }
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@*/
426
427 con->finalArgvCount = 0;
428-
429- if (con->arg_strip) {
430- PBM_FREE(con->arg_strip);
431- con->arg_strip = NULL;
432- }
433+ con->arg_strip = PBM_FREE(con->arg_strip);
434+ /*@-nullstate@*/ /* FIX: con->finalArgv != NULL */
435+ return;
436+ /*@=nullstate@*/
437 }
438
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 @*/
446+{
447 int i;
448
449+ if (con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */
450+ return 0;
451 i = con->numExecs - 1;
452 if (longName) {
453 while (i >= 0 && (!con->execs[i].longName ||
454@@ -220,29 +257,44 @@
455 }
456
457 i = con->finalArgvCount++;
458+ if (con->finalArgv != NULL) /* XXX can't happen */
459 { char *s = malloc((longName ? strlen(longName) : 0) + 3);
460- if (longName)
461- sprintf(s, "--%s", longName);
462- else
463- sprintf(s, "-%c", shortName);
464- con->finalArgv[i] = s;
465+ if (s != NULL) { /* XXX can't happen */
466+ if (longName)
467+ sprintf(s, "--%s", longName);
468+ else
469+ sprintf(s, "-%c", shortName);
470+ con->finalArgv[i] = s;
471+ } else
472+ con->finalArgv[i] = NULL;
473 }
474
475+ /*@-nullstate@*/ /* FIX: con->finalArgv[] == NULL */
476 return 1;
477+ /*@=nullstate@*/
478 }
479
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 @*/
488+{
489+ int rc;
490 int i;
491
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))
495+ /*@=nullpass@*/
496 return 0;
497 if (con->os->currAlias && shortName &&
498 shortName == con->os->currAlias->shortName)
499 return 0;
500
501+ if (con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */
502+ return 0;
503 i = con->numAliases - 1;
504 if (longName) {
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;
514
515- return 1;
516+ return (rc ? rc : 1);
517 }
518
519-static void execCommand(poptContext con) {
520+static int execCommand(poptContext con)
521+ /*@modifies fileSystem @*/
522+{
523 const char ** argv;
524 int argc = 0;
525 const char ** sargv;
526 int sargc = 0;
527+ int rc;
528
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);
533+ if (rc) return rc;
534
535 if (sargv == NULL || sargc < 1 ||
536 (!con->execAbsolute && strchr(sargv[0], '/')))
537- return;
538+ return POPT_ERROR_NOARG;
539
540 argv = malloc(sizeof(*argv) *
541 (6 + sargc + con->numLeftovers + con->finalArgvCount));
542+ if (argv == NULL) return POPT_ERROR_MALLOC; /* XXX can't happen */
543
544 if (!strchr(sargv[0], '/') && con->execPath) {
545 char *s = alloca(strlen(con->execPath) + strlen(sargv[0]) + sizeof("/"));
546@@ -295,26 +354,31 @@
547 } else {
548 argv[argc] = findProgramPath(sargv[0]);
549 }
550- if (argv[argc++] == NULL) return;
551+ if (argv[argc++] == NULL) return POPT_ERROR_NOARG;
552
553 if (sargc > 1) {
554 memcpy(argv + argc, sargv + 1, sizeof(*argv) * (sargc - 1));
555 argc += (sargc - 1);
556 }
557
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;
564+ }
565
566- if (con->numLeftovers) {
567+ if (con->leftovers != NULL && con->numLeftovers > 0) {
568+#if 0
569 argv[argc++] = "--";
570+#endif
571 memcpy(argv + argc, con->leftovers, sizeof(*argv) * con->numLeftovers);
572 argc += con->numLeftovers;
573 }
574
575- argv[argc++] = NULL;
576+ argv[argc] = NULL;
577
578 #ifdef __hpux
579- setresuid(getuid(), getuid(),-1);
580+ (void) setresuid(getuid(), getuid(),-1);
581 #else
582 /*
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>
586 */
587 #if defined(HAVE_SETUID)
588- setuid(getuid());
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 */
593 #else
594 ; /* Can't drop privileges */
595 #endif
596 #endif
597
598 if (argv[0] == NULL)
599- return;
600+ return POPT_ERROR_NOARG;
601 #ifdef MYDEBUG
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");
611 }
612 #endif
613
614- execvp(argv[0], (char *const *)argv);
615+ (void) execvp(argv[0], (char *const *)argv);
616+ return POPT_ERROR_ERRNO;
617 }
618
619-/*@observer@*/ static const struct poptOption *
620-findOption(const struct poptOption * opt, const char * longName,
621- char shortName,
622- /*@out@*/ poptCallbackType * callback, /*@out@*/ const void ** callbackData,
623- int singleDash)
624+/*@observer@*/ /*@null@*/ static const struct poptOption *
625+findOption(const struct poptOption * opt, /*@null@*/ const char * longName,
626+ char shortName,
627+ /*@null@*/ /*@out@*/ poptCallbackType * callback,
628+ /*@null@*/ /*@out@*/ const void ** callbackData,
629+ int singleDash)
630+ /*@modifies *callback, *callbackData */
631 {
632 const struct poptOption * cb = NULL;
633
634 /* This happens when a single - is given */
635- if (singleDash && !shortName && !*longName)
636+ if (singleDash && !shortName && (longName && *longName == '\0'))
637 shortName = '-';
638
639 for (; opt->longName || opt->shortName || opt->arg; opt++) {
640
641 if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) {
642 const struct poptOption * opt2;
643+
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);
648- if (opt2) {
649- /* Sub-table data will be inheirited if no data yet. */
650- if (*callback && *callbackData == NULL)
651- *callbackData = opt->descrip;
652- return opt2;
653- }
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 @*/
661+ return opt2;
662 } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) {
663 cb = opt;
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))
669+ /*@=nullpass@*/
670+ {
671 break;
672 } else if (shortName && shortName == opt->shortName) {
673 break;
674@@ -382,18 +456,30 @@
675
676 if (!opt->longName && !opt->shortName)
677 return NULL;
678- *callbackData = NULL;
679- *callback = NULL;
680+ /*@-modobserver -mods @*/
681+ if (callback) *callback = NULL;
682+ if (callbackData) *callbackData = NULL;
683 if (cb) {
684- *callback = (poptCallbackType)cb->arg;
685- if (!(cb->argInfo & POPT_CBFLAG_INC_DATA))
686- *callbackData = cb->descrip;
687+ if (callback)
688+ /*@-castfcnptr@*/
689+ *callback = (poptCallbackType)cb->arg;
690+ /*@=castfcnptr@*/
691+ if (!(cb->argInfo & POPT_CBFLAG_INC_DATA)) {
692+ if (callbackData)
693+ /*@-observertrans@*/ /* FIX: typedef double indirection. */
694+ *callbackData = cb->descrip;
695+ /*@=observertrans@*/
696+ }
697 }
698+ /*@=modobserver =mods @*/
699
700 return opt;
701 }
702
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 @*/
708 {
709 struct optionStackEntry * os = con->os;
710 const char * arg;
711@@ -403,6 +489,7 @@
712 arg = NULL;
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;
719@@ -410,6 +497,7 @@
720 arg = os->argv[i];
721 if (delete) {
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);
725 }
726 break;
727@@ -419,15 +507,20 @@
728 return arg;
729 }
730
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 @*/
737 {
738- const char *a;
739+ const char * a = NULL;
740 size_t alen;
741 char *t, *te;
742 size_t tn = strlen(s) + 1;
743 char c;
744
745 te = t = malloc(tn);;
746+ if (t == NULL) return NULL; /* XXX can't happen */
747 while ((c = *s++) != '\0') {
748 switch (c) {
749 #if 0 /* XXX can't do this */
750@@ -438,8 +531,10 @@
751 case '!':
752 if (!(s[0] == '#' && s[1] == ':' && s[2] == '+'))
753 break;
754- if ((a = findNextArg(con, 1, 1)) == NULL)
755- break;
756+ /* XXX Make sure that findNextArg deletes only next arg. */
757+ if (a == NULL) {
758+ if ((a = findNextArg(con, 1, 1)) == NULL) break;
759+ }
760 s += 3;
761
762 alen = strlen(a);
763@@ -456,18 +551,25 @@
764 *te++ = c;
765 }
766 *te = '\0';
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 */
769 return t;
770 }
771
772 static void poptStripArg(poptContext con, int which)
773+ /*@modifies con @*/
774 {
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);
779 }
780
781-static int poptSaveLong(const struct poptOption * opt, long aLong) {
782+static int poptSaveLong(const struct poptOption * opt, long aLong)
783+ /*@modifies opt->arg @*/
784+{
785+ if (opt->arg == NULL)
786+ return POPT_ERROR_NULLARG;
787+
788 if (opt->argInfo & POPT_ARGFLAG_NOT)
789 aLong = ~aLong;
790 switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) {
791@@ -485,12 +587,17 @@
792 break;
793 default:
794 return POPT_ERROR_BADOPERATION;
795- break;
796+ /*@notreached@*/ break;
797 }
798 return 0;
799 }
800
801-static int poptSaveInt(const struct poptOption * opt, long aLong) {
802+static int poptSaveInt(const struct poptOption * opt, long aLong)
803+ /*@modifies opt->arg @*/
804+{
805+ if (opt->arg == NULL)
806+ return POPT_ERROR_NULLARG;
807+
808 if (opt->argInfo & POPT_ARGFLAG_NOT)
809 aLong = ~aLong;
810 switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) {
811@@ -508,31 +615,19 @@
812 break;
813 default:
814 return POPT_ERROR_BADOPERATION;
815- break;
816+ /*@notreached@*/ break;
817 }
818 return 0;
819 }
820
821-#ifdef MYDEBUG
822-static void prtcon(const char *msg, poptContext con)
823-{
824- if (msg) fprintf(stderr, "%s", msg);
825- fprintf(stderr, "\tcon %p os %p nextCharArg \"%s\" nextArg \"%s\" argv[%d] \"%s\"\n",
826- con, con->os,
827- (con->os->nextCharArg ? con->os->nextCharArg : ""),
828- (con->os->nextArg ? con->os->nextArg : ""),
829- con->os->next,
830- (con->os->argv && con->os->argv[con->os->next]
831- ? con->os->argv[con->os->next] : ""));
832-}
833-#endif
834-
835 /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */
836 int poptGetNextOpt(poptContext con)
837 {
838 const struct poptOption * opt = NULL;
839 int done = 0;
840
841+ if (con == NULL)
842+ return -1;
843 while (!done) {
844 const char * origOptString = NULL;
845 poptCallbackType cb = NULL;
846@@ -547,7 +642,7 @@
847 }
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);
852 return -1;
853 }
854
855@@ -561,9 +656,14 @@
856 continue;
857 }
858 thisopt = con->os->next;
859+ if (con->os->argv != NULL) /* XXX can't happen */
860 origOptString = con->os->argv[con->os->next++];
861
862+ if (origOptString == NULL) /* XXX can't happen */
863+ return POPT_ERROR_BADOPT;
864+
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;
870@@ -572,10 +672,9 @@
871
872 /* Make a copy we can hack at */
873 localOptString = optString =
874- strcpy(alloca(strlen(origOptString) + 1),
875- origOptString);
876+ strcpy(alloca(strlen(origOptString) + 1), origOptString);
877
878- if (!optString[0])
879+ if (optString[0] == '\0')
880 return POPT_ERROR_BADOPT;
881
882 if (optString[1] == '-' && !optString[2]) {
883@@ -594,6 +693,7 @@
884 /* XXX aliases with arg substitution need "--alias=arg" */
885 if (handleAlias(con, optString, '\0', NULL))
886 continue;
887+
888 if (handleExec(con, optString, '\0'))
889 continue;
890
891@@ -616,7 +716,8 @@
892 con->os->nextCharArg = origOptString + 1;
893 } else {
894 if (con->os == con->optionStack &&
895- opt->argInfo & POPT_ARGFLAG_STRIP) {
896+ opt->argInfo & POPT_ARGFLAG_STRIP)
897+ {
898 canstrip = 1;
899 poptStripArg(con, thisopt);
900 }
901@@ -630,14 +731,14 @@
902
903 con->os->nextCharArg = NULL;
904
905- if (handleAlias(con, NULL, *origOptString,
906- origOptString + 1)) {
907+ if (handleAlias(con, NULL, *origOptString, origOptString + 1))
908 continue;
909- }
910+
911 if (handleExec(con, NULL, *origOptString)) {
912 /* Restore rest of short options for further processing */
913 origOptString++;
914- if (*origOptString) con->os->nextCharArg = origOptString;
915+ if (*origOptString != '\0')
916+ con->os->nextCharArg = origOptString;
917 continue;
918 }
919
920@@ -648,9 +749,13 @@
921 shorty = 1;
922
923 origOptString++;
924- if (*origOptString) con->os->nextCharArg = origOptString;
925+ /*@-branchstate@*/ /* FIX: W2DO? */
926+ if (*origOptString != '\0')
927+ con->os->nextCharArg = origOptString;
928+ /*@=branchstate@*/
929 }
930
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;
937 }
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;
942- }
943+ con->os->nextArg = _free(con->os->nextArg);
944+ /*@-usedef@*/ /* FIX: W2DO? */
945 if (longArg) {
946- con->os->nextArg = expandNextArg(con, longArg);
947+ /*@=usedef@*/
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;
955 } else {
956 while (con->os->next == con->os->argc &&
957@@ -681,17 +787,25 @@
958 return POPT_ERROR_NOARG;
959 } else {
960
961- /* make sure this isn't part of a short arg or the
962- result of an alias expansion */
963+ /*
964+ * Make sure this isn't part of a short arg or the
965+ * result of an alias expansion.
966+ */
967 if (con->os == con->optionStack &&
968- opt->argInfo & POPT_ARGFLAG_STRIP &&
969+ (opt->argInfo & POPT_ARGFLAG_STRIP) &&
970 canstrip) {
971 poptStripArg(con, con->os->next);
972 }
973
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;
980+ }
981 }
982 }
983+ longArg = NULL;
984
985 if (opt->arg) {
986 switch (opt->argInfo & POPT_ARG_MASK) {
987@@ -731,32 +845,31 @@
988 char *end;
989
990 if (con->os->nextArg) {
991+ int saveerrno = errno;
992+ errno = 0;
993 aDouble = strtod(con->os->nextArg, &end);
994- if (*end)
995+ if (errno == ERANGE)
996+ return POPT_ERROR_OVERFLOW;
997+ errno = saveerrno;
998+ if (*end != '\0')
999 return POPT_ERROR_BADNUMBER;
1000 }
1001
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;
1008 } else {
1009-#ifdef ABS
1010-#undef ABS
1011-#endif
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;
1021 }
1022 } break;
1023 default:
1024- fprintf(stdout, POPT_("option type (%d) not implemented in popt\n"),
1025- opt->argInfo & POPT_ARG_MASK);
1026+ fprintf(stdout,
1027+ POPT_("option type (%d) not implemented in popt\n"),
1028+ (opt->argInfo & POPT_ARG_MASK));
1029 exit(EXIT_FAILURE);
1030 }
1031 }
1032@@ -773,83 +886,107 @@
1033 sizeof(*con->finalArgv) * con->finalArgvAlloced);
1034 }
1035
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) ? "-" : "--"),
1041- opt->longName);
1042- else
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) ? "-" : "--"),
1049+ opt->longName);
1050+ else
1051+ sprintf(s, "-%c", opt->shortName);
1052+ con->finalArgv[con->finalArgvCount++] = s;
1053+ } else
1054+ con->finalArgv[con->finalArgvCount++] = NULL;
1055 }
1056
1057 if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE)
1058- /*@-ifempty@*/ ;
1059+ /*@-ifempty@*/ ; /*@=ifempty@*/
1060 else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL)
1061- /*@-ifempty@*/ ;
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);
1069+ /*@=nullpass@*/
1070 }
1071 }
1072
1073- return opt->val;
1074+ return (opt ? opt->val : -1); /* XXX can't happen */
1075 }
1076
1077-const char * poptGetOptArg(poptContext con) {
1078- const char * ret = con->os->nextArg;
1079- con->os->nextArg = NULL;
1080+const char * poptGetOptArg(poptContext con)
1081+{
1082+ const char * ret = NULL;
1083+ if (con) {
1084+ ret = con->os->nextArg;
1085+ con->os->nextArg = NULL;
1086+ }
1087 return ret;
1088 }
1089
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)
1094+{
1095+ const char * ret = NULL;
1096+ if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers)
1097+ ret = con->leftovers[con->nextLeftover++];
1098 return ret;
1099 }
1100
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)
1105+{
1106+ const char * ret = NULL;
1107+ if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers)
1108+ ret = con->leftovers[con->nextLeftover];
1109 return ret;
1110 }
1111
1112-const char ** poptGetArgs(poptContext con) {
1113- if (con->numLeftovers == con->nextLeftover) return NULL;
1114+const char ** poptGetArgs(poptContext con)
1115+{
1116+ if (con == NULL ||
1117+ con->leftovers == NULL || con->numLeftovers == con->nextLeftover)
1118+ return NULL;
1119
1120 /* some apps like [like RPM ;-) ] need this NULL terminated */
1121 con->leftovers[con->numLeftovers] = NULL;
1122
1123+ /*@-nullret -nullstate @*/ /* FIX: typedef double indirection. */
1124 return (con->leftovers + con->nextLeftover);
1125+ /*@=nullret =nullstate @*/
1126 }
1127
1128-void poptFreeContext(poptContext con) {
1129+poptContext poptFreeContext(poptContext con)
1130+{
1131 int i;
1132
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);
1137
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);
1144 }
1145
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);
1152 }
1153- if (con->execs) free((void *)con->execs);
1154+ con->execs = _free(con->execs);
1155
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);
1170
1171- free(con);
1172+ con = _free(con);
1173+ return con;
1174 }
1175
1176 int poptAddAlias(poptContext con, struct poptAlias newAlias,
1177@@ -867,7 +1004,9 @@
1178 alias = con->aliases + aliasNum;
1179
1180 alias->longName = (newAlias.longName)
1181+ /*@-nullpass@*/ /* FIX: malloc can return NULL. */
1182 ? strcpy(malloc(strlen(newAlias.longName) + 1), newAlias.longName)
1183+ /*@=nullpass@*/
1184 : NULL;
1185 alias->shortName = newAlias.shortName;
1186 alias->argc = newAlias.argc;
1187@@ -876,18 +1015,20 @@
1188 return 0;
1189 }
1190
1191-const char * poptBadOption(poptContext con, int flags) {
1192- struct optionStackEntry * os;
1193+const char * poptBadOption(poptContext con, int flags)
1194+{
1195+ struct optionStackEntry * os = NULL;
1196
1197- if (flags & POPT_BADOPTION_NOALIAS)
1198- os = con->optionStack;
1199- else
1200- os = con->os;
1201+ if (con != NULL)
1202+ os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os;
1203
1204- return os->argv[os->next - 1];
1205+ /*@-nullderef@*/ /* LCL: os->argv != NULL */
1206+ return (os && os->argv ? os->argv[os->next - 1] : NULL);
1207+ /*@=nullderef@*/
1208 }
1209
1210-const char *const poptStrerror(const int error) {
1211+const char *const poptStrerror(const int error)
1212+{
1213 switch (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);
1233 default:
1234@@ -910,8 +1055,10 @@
1235 }
1236 }
1237
1238-int poptStuffArgs(poptContext con, const char ** argv) {
1239+int poptStuffArgs(poptContext con, const char ** argv)
1240+{
1241 int argc;
1242+ int rc;
1243
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;
1254
1255- return 0;
1256+ return rc;
1257 }
1258
1259-const char * poptGetInvocationName(poptContext con) {
1260- return con->os->argv[0];
1261+const char * poptGetInvocationName(poptContext con)
1262+{
1263+ return (con->os->argv ? con->os->argv[0] : "");
1264 }
1265
1266-int poptStrippedArgv(poptContext con, int argc, char **argv)
1267+int poptStrippedArgv(poptContext con, int argc, char ** argv)
1268 {
1269- int i,j=1, numargs=argc;
1270+ int numargs = argc;
1271+ int j = 1;
1272+ int i;
1273
1274+ if (con->arg_strip)
1275 for (i = 1; i < argc; i++) {
1276 if (PBM_ISSET(i, con->arg_strip))
1277 numargs--;
1278 }
1279
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))
1283 continue;
1284- argv[j] = (j < numargs) ? argv[i] : '\0';
1285+ argv[j] = (j < numargs) ? argv[i] : NULL;
1286 j++;
1287 }
1288
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
1291@@ -84,6 +84,8 @@
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 */
1297 /*@}*/
1298
1299 /** \ingroup popt
1300@@ -110,8 +112,8 @@
1301 int argInfo;
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 */
1308 };
1309
1310 /** \ingroup popt
1311@@ -135,7 +137,7 @@
1312
1313 /** \ingroup popt
1314 */
1315-typedef struct poptContext_s * poptContext;
1316+typedef /*@abstract@*/ struct poptContext_s * poptContext;
1317
1318 /** \ingroup popt
1319 */
1320@@ -156,9 +158,10 @@
1321 * @param data @todo Document.
1322 */
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);
1331
1332 /** \ingroup popt
1333 * Initialize popt context.
1334@@ -169,62 +172,65 @@
1335 * @param flags or'd POPT_CONTEXT_* bits
1336 * @return initialized popt context
1337 */
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,
1345+ int flags);
1346
1347 /** \ingroup popt
1348 * Reinitialize popt context.
1349 * @param con context
1350 */
1351-void poptResetContext(poptContext con);
1352+void poptResetContext(/*@null@*/poptContext con);
1353
1354 /** \ingroup popt
1355 * Return value of next option found.
1356 * @param con context
1357 * @return next option val, -1 on last item, POPT_ERROR_* on error
1358 */
1359-int poptGetNextOpt(poptContext con);
1360+int poptGetNextOpt(/*@null@*/poptContext con);
1361 /* returns NULL if no argument is available */
1362
1363 /** \ingroup popt
1364 * @param con context
1365 */
1366-/*@observer@*/ /*@null@*/ const char * poptGetOptArg(poptContext con);
1367+/*@observer@*/ /*@null@*/ const char * poptGetOptArg(/*@null@*/poptContext con);
1368
1369 /** \ingroup popt
1370 * Return current option's argument.
1371 * @param con context
1372 * @return option argument, NULL if no more options are available
1373 */
1374-/*@observer@*/ /*@null@*/ const char * poptGetArg(poptContext con);
1375+/*@observer@*/ /*@null@*/ const char * poptGetArg(/*@null@*/poptContext con);
1376
1377 /** \ingroup popt
1378 * Peek at current option's argument.
1379 * @param con context
1380 * @return option argument
1381 */
1382-/*@observer@*/ /*@null@*/ const char * poptPeekArg(poptContext con);
1383+/*@observer@*/ /*@null@*/ const char * poptPeekArg(/*@null@*/poptContext con);
1384
1385 /** \ingroup popt
1386 * Return remaining arguments.
1387 * @param con context
1388 * @return argument array, terminated with NULL
1389 */
1390-/*@observer@*/ /*@null@*/ const char ** poptGetArgs(poptContext con);
1391+/*@observer@*/ /*@null@*/ const char ** poptGetArgs(/*@null@*/poptContext con);
1392
1393 /** \ingroup popt
1394 * Return the option which caused the most recent error.
1395 * @param con context
1396 * @return offending option
1397 */
1398-/*@observer@*/ const char * poptBadOption(poptContext con, int flags);
1399+/*@observer@*/ const char * poptBadOption(/*@null@*/poptContext con, int flags);
1400
1401 /** \ingroup popt
1402 * Destroy context.
1403 * @param con context
1404+ * @return NULL
1405 */
1406-void poptFreeContext( /*@only@*/ poptContext con);
1407+/*@null@*/ poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con);
1408
1409 /** \ingroup popt
1410 * Add arguments to context.
1411@@ -250,7 +256,9 @@
1412 * @param fn file name to read
1413 * @return 0 on success, POPT_ERROR_ERRNO on failure
1414 */
1415-int poptReadConfigFile(poptContext con, const char * fn);
1416+int poptReadConfigFile(poptContext con, const char * fn)
1417+ /*@modifies fileSystem,
1418+ con->execs, con->numExecs @*/;
1419
1420 /** \ingroup popt
1421 * Read default configuration from /etc/popt and $HOME/.popt.
1422@@ -258,7 +266,9 @@
1423 * @param useEnv (unused)
1424 * @return 0 on success, POPT_ERROR_ERRNO on failure
1425 */
1426-int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv);
1427+int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv)
1428+ /*@modifies fileSystem,
1429+ con->execs, con->numExecs @*/;
1430
1431 /** \ingroup popt
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
1436 */
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 @*/;
1443
1444 /** \ingroup popt
1445 * Parse a string into an argument array.
1446@@ -286,14 +298,16 @@
1447 * @retval argvPtr address of returned argument array
1448 */
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 @*/;
1453
1454 /** \ingroup popt
1455 * Return formatted error string for popt failure.
1456 * @param error popt error
1457 * @return error string
1458 */
1459-/*@observer@*/ const char *const poptStrerror(const int error);
1460+/*@observer@*/ const char *const poptStrerror(const int error)
1461+ /*@*/;
1462
1463 /** \ingroup popt
1464 * Limit search for executables.
1465@@ -337,7 +351,7 @@
1466 * @param con context
1467 * @return new argc
1468 */
1469-int poptStrippedArgv(poptContext con, int argc, char **argv);
1470+int poptStrippedArgv(poptContext con, int argc, char ** argv);
1471
1472 #ifdef __cplusplus
1473 }
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
1476@@ -9,30 +9,33 @@
1477 #include "system.h"
1478 #include "poptint.h"
1479
1480-static void configLine(poptContext con, char * line) {
1481+static void configLine(poptContext con, char * line)
1482+ /*@modifies *line,
1483+ con->execs, con->numExecs @*/
1484+{
1485 int nameLength = strlen(con->appName);
1486- char * opt;
1487+ const char * opt;
1488 struct poptAlias alias;
1489- char * entryType;
1490- char * longName = NULL;
1491+ const char * entryType;
1492+ const char * longName = NULL;
1493 char shortName = '\0';
1494
1495 if (strncmp(line, con->appName, nameLength)) return;
1496 line += nameLength;
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++;
1501 entryType = line;
1502
1503- while (!*line || !isspace(*line)) line++;
1504+ while (*line == '\0' || !isspace(*line)) line++;
1505 *line++ = '\0';
1506- while (*line && isspace(*line)) line++;
1507- if (!*line) return;
1508+ while (*line != '\0' && isspace(*line)) line++;
1509+ if (*line == '\0') return;
1510 opt = line;
1511
1512- while (!*line || !isspace(*line)) line++;
1513+ while (*line == '\0' || !isspace(*line)) line++;
1514 *line++ = '\0';
1515- while (*line && isspace(*line)) line++;
1516- if (!*line) return;
1517+ while (*line != '\0' && isspace(*line)) line++;
1518+ if (*line == '\0') return;
1519
1520 if (opt[0] == '-' && opt[1] == '-')
1521 longName = opt + 2;
1522@@ -42,10 +45,11 @@
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 */
1532 if (longName)
1533 con->execs[con->numExecs].longName = xstrdup(longName);
1534 else
1535@@ -54,49 +58,55 @@
1536 con->execs[con->numExecs].shortName = shortName;
1537 con->execs[con->numExecs].script = xstrdup(line);
1538
1539+ /*@-noeffect@*/ /* LCL: broken? */
1540 con->numExecs++;
1541+ /*@=noeffect@*/
1542 }
1543 }
1544
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)
1549+{
1550+ const char * file, * chptr, * end;
1551+ char * buf;
1552+/*@dependent@*/ char * dst;
1553 int fd, rc;
1554- int fileLength;
1555+ off_t fileLength;
1556
1557 fd = open(fn, O_RDONLY);
1558- if (fd < 0) {
1559- if (errno == ENOENT)
1560- return 0;
1561- else
1562- return POPT_ERROR_ERRNO;
1563- }
1564+ if (fd < 0)
1565+ return (errno == ENOENT ? 0 : POPT_ERROR_ERRNO);
1566
1567 fileLength = lseek(fd, 0, SEEK_END);
1568- (void) lseek(fd, 0, 0);
1569+ if (fileLength == -1 || lseek(fd, 0, 0) == -1) {
1570+ rc = errno;
1571+ (void) close(fd);
1572+ errno = rc;
1573+ return POPT_ERROR_ERRNO;
1574+ }
1575
1576 file = alloca(fileLength + 1);
1577- if (read(fd, file, fileLength) != fileLength) {
1578+ if (read(fd, (char *)file, fileLength) != fileLength) {
1579 rc = errno;
1580- close(fd);
1581+ (void) close(fd);
1582 errno = rc;
1583 return POPT_ERROR_ERRNO;
1584 }
1585- close(fd);
1586+ if (close(fd) == -1)
1587+ return POPT_ERROR_ERRNO;
1588
1589 dst = buf = alloca(fileLength + 1);
1590
1591 chptr = file;
1592 end = (file + fileLength);
1593+ /*@-infloops@*/ /* LCL: can't detect chptr++ */
1594 while (chptr < end) {
1595 switch (*chptr) {
1596 case '\n':
1597 *dst = '\0';
1598 dst = buf;
1599 while (*dst && isspace(*dst)) dst++;
1600- if (*dst && *dst != '#') {
1601+ if (*dst && *dst != '#')
1602 configLine(con, dst);
1603- }
1604 chptr++;
1605 break;
1606 case '\\':
1607@@ -114,6 +124,7 @@
1608 break;
1609 }
1610 }
1611+ /*@=infloops@*/
1612
1613 return 0;
1614 }
1615@@ -138,4 +149,3 @@
1616
1617 return 0;
1618 }
1619-
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
1622@@ -23,31 +23,33 @@
1623 exit(0);
1624 }
1625
1626+/*@-castfcnptr@*/
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 },
1631 POPT_TABLEEND
1632 } ;
1633-
1634+/*@=castfcnptr@*/
1635
1636 /*@observer@*/ /*@null@*/ static const char *const
1637-getTableTranslationDomain(const struct poptOption *table)
1638+getTableTranslationDomain(/*@null@*/ const struct poptOption *table)
1639 {
1640- const struct poptOption *opt;
1641-
1642- for(opt = table;
1643- opt->longName || opt->shortName || opt->arg;
1644- opt++) {
1645- if(opt->argInfo == POPT_ARG_INTL_DOMAIN)
1646- return opt->arg;
1647- }
1648+ const struct poptOption *opt;
1649
1650- return NULL;
1651+ if (table != NULL)
1652+ for (opt = table; opt->longName || opt->shortName || opt->arg; opt++) {
1653+ if (opt->argInfo == POPT_ARG_INTL_DOMAIN)
1654+ return opt->arg;
1655+ }
1656+ return NULL;
1657 }
1658
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)
1664+ /*@=paramuse@*/
1665 {
1666 if (!(opt->argInfo & POPT_ARG_MASK)) return NULL;
1667
1668@@ -69,8 +71,8 @@
1669 }
1670
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)
1676 {
1677 int indentLength = maxLeftCol + 5;
1678 int lineLength = 79 - indentLength;
1679@@ -173,20 +175,22 @@
1680 }
1681
1682 static int maxArgWidth(const struct poptOption * opt,
1683- const char * translation_domain)
1684+ /*@null@*/ const char * translation_domain)
1685 {
1686 int max = 0;
1687- int this;
1688+ int this = 0;
1689 const char * s;
1690
1691+ if (opt != NULL)
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 @@
1707 return max;
1708 }
1709
1710-static void singleTableHelp(FILE * f, const struct poptOption * table,
1711- int left,
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)
1716 {
1717 const struct poptOption * opt;
1718 const char *sub_transdom;
1719
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);
1725 }
1726
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);
1731- if(!sub_transdom)
1732+ if (sub_transdom == NULL)
1733 sub_transdom = translation_domain;
1734
1735 if (opt->descrip)
1736@@ -240,7 +246,10 @@
1737
1738 fprintf(f, POPT_("Usage:"));
1739 if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) {
1740+ /*@-nullderef@*/ /* LCL: wazzup? */
1741 fn = con->optionStack->argv[0];
1742+ /*@=nullderef@*/
1743+ if (fn == NULL) return len;
1744 if (strchr(fn, '/')) fn = strrchr(fn, '/') + 1;
1745 fprintf(f, " %s", fn);
1746 len += strlen(fn) + 1;
1747@@ -253,7 +262,7 @@
1748 {
1749 int leftColWidth;
1750
1751- showHelpIntro(con, f);
1752+ (void) showHelpIntro(con, f);
1753 if (con->otherHelp)
1754 fprintf(f, " %s\n", con->otherHelp);
1755 else
1756@@ -264,15 +273,15 @@
1757 }
1758
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)
1764 {
1765 int len = 3;
1766 char shortStr[2] = { '\0', '\0' };
1767 const char * item = shortStr;
1768 const char * argDescrip = getArgDescrip(opt, translation_domain);
1769
1770- if (opt->shortName) {
1771+ if (opt->shortName!= '\0' ) {
1772 if (!(opt->argInfo & POPT_ARG_MASK))
1773 return cursor; /* we did these already */
1774 len++;
1775@@ -296,47 +305,57 @@
1776 fprintf(f, " [-%s%s%s%s]",
1777 ((opt->shortName || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) ? "" : "-"),
1778 item,
1779- (argDescrip ? (opt->shortName ? " " : "=") : ""),
1780+ (argDescrip ? (opt->shortName != '\0' ? " " : "=") : ""),
1781 (argDescrip ? argDescrip : ""));
1782
1783 return cursor + len + 1;
1784 }
1785
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)
1791 {
1792+ /*@-branchstate@*/ /* FIX: W2DO? */
1793+ if (opt != NULL)
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);
1807+ }
1808 }
1809+ /*@=branchstate@*/
1810
1811 return cursor;
1812 }
1813
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)
1817 {
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 */
1821
1822 s[0] = '\0';
1823+ /*@-branchstate@*/ /* FIX: W2DO? */
1824 if (str == NULL) {
1825 memset(s, 0, sizeof(s));
1826 str = s;
1827 }
1828+ /*@=branchstate@*/
1829
1830+ if (opt != NULL)
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);
1838 }
1839
1840- if (s != str || !*s)
1841+ if (s != str || *s != '\0')
1842 return 0;
1843
1844 fprintf(f, " [-%s]", s);
1845@@ -349,7 +368,7 @@
1846
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);
1851
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
1856@@ -9,6 +9,16 @@
1857 #ifndef H_POPTINT
1858 #define H_POPTINT
1859
1860+/**
1861+ * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
1862+ * @param this memory to free
1863+ * @retval NULL always
1864+ */
1865+/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) {
1866+ if (this != NULL) free((void *)this);
1867+ return NULL;
1868+}
1869+
1870 /* Bit mask macros. */
1871 typedef unsigned int __pbm_bits;
1872 #define __PBM_NBITS (8 * sizeof (__pbm_bits))
1873@@ -20,50 +30,50 @@
1874 #define __PBM_BITS(set) ((set)->bits)
1875
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)
1882
1883 struct optionStackEntry {
1884 int argc;
1885-/*@only@*/ const char ** argv;
1886-/*@only@*/ pbm_set * argb;
1887+/*@only@*/ /*@null@*/ const char ** argv;
1888+/*@only@*/ /*@null@*/ pbm_set * argb;
1889 int next;
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;
1896 int stuffed;
1897 };
1898
1899 struct execEntry {
1900- const char * longName;
1901+/*@owned@*/ /*@null@*/ const char * longName;
1902 char shortName;
1903- const char * script;
1904+/*@only@*/ /*@null@*/ const char * script;
1905 };
1906
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;
1912 int numLeftovers;
1913 int nextLeftover;
1914 /*@keep@*/ const struct poptOption * options;
1915 int restLeftover;
1916-/*@only@*/ const char * appName;
1917-/*@only@*/ struct poptAlias * aliases;
1918+/*@only@*/ /*@null@*/ const char * appName;
1919+/*@only@*/ /*@null@*/ struct poptAlias * aliases;
1920 int numAliases;
1921 int flags;
1922- struct execEntry * execs;
1923+/*@owned@*/ /*@null@*/ struct execEntry * execs;
1924 int numExecs;
1925-/*@only@*/ const char ** finalArgv;
1926+/*@only@*/ /*@null@*/ const char ** finalArgv;
1927 int finalArgvCount;
1928 int finalArgvAlloced;
1929-/*@dependent@*/ struct execEntry * doExec;
1930+/*@dependent@*/ /*@null@*/ struct execEntry * doExec;
1931 /*@only@*/ const char * execPath;
1932 int execAbsolute;
1933 /*@only@*/ const char * otherHelp;
1934- pbm_set * arg_strip;
1935+/*@null@*/ pbm_set * arg_strip;
1936 };
1937
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
1941@@ -18,6 +18,8 @@
1942 char * dst;
1943 int i;
1944
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;
1950@@ -25,6 +27,8 @@
1951 }
1952
1953 dst = malloc(nb);
1954+ if (dst == NULL) /* XXX can't happen */
1955+ return POPT_ERROR_MALLOC;
1956 argv2 = (void *) dst;
1957 dst += (argc + 1) * sizeof(*argv);
1958
1959@@ -34,8 +38,14 @@
1960 }
1961 argv2[argc] = NULL;
1962
1963- *argvPtr = argv2;
1964- *argcPtr = argc;
1965+ if (argvPtr) {
1966+ *argvPtr = argv2;
1967+ } else {
1968+ free(argv2);
1969+ argv2 = NULL;
1970+ }
1971+ if (argcPtr)
1972+ *argcPtr = argc;
1973 return 0;
1974 }
1975
1976@@ -48,28 +58,31 @@
1977 int argc = 0;
1978 int buflen = strlen(s) + 1;
1979 char * buf = memset(alloca(buflen), 0, buflen);
1980+ int rc = POPT_ERROR_MALLOC;
1981
1982+ if (argv == NULL) return rc;
1983 argv[argc] = buf;
1984
1985- for (src = s; *src; src++) {
1986+ for (src = s; *src != '\0'; src++) {
1987 if (quote == *src) {
1988 quote = '\0';
1989- } else if (quote) {
1990+ } else if (quote != '\0') {
1991 if (*src == '\\') {
1992 src++;
1993 if (!*src) {
1994- free(argv);
1995- return POPT_ERROR_BADQUOTE;
1996+ rc = POPT_ERROR_BADQUOTE;
1997+ goto exit;
1998 }
1999 if (*src != quote) *buf++ = '\\';
2000 }
2001 *buf++ = *src;
2002 } else if (isspace(*src)) {
2003- if (*argv[argc]) {
2004+ if (*argv[argc] != '\0') {
2005 buf++, argc++;
2006 if (argc == argvAlloced) {
2007 argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA;
2008 argv = realloc(argv, sizeof(*argv) * argvAlloced);
2009+ if (argv == NULL) goto exit;
2010 }
2011 argv[argc] = buf;
2012 }
2013@@ -81,8 +94,8 @@
2014 case '\\':
2015 src++;
2016 if (!*src) {
2017- free(argv);
2018- return POPT_ERROR_BADQUOTE;
2019+ rc = POPT_ERROR_BADQUOTE;
2020+ goto exit;
2021 }
2022 /*@fallthrough@*/
2023 default:
2024@@ -95,9 +108,9 @@
2025 argc++, buf++;
2026 }
2027
2028- (void) poptDupArgv(argc, argv, argcPtr, argvPtr);
2029-
2030- free(argv);
2031+ rc = poptDupArgv(argc, argv, argcPtr, argvPtr);
2032
2033- return 0;
2034+exit:
2035+ if (argv) free(argv);
2036+ return rc;
2037 }
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
2040@@ -44,12 +44,14 @@
2041
2042 /*@only@*/ char * xstrdup (const char *str);
2043
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)))
2048 #else
2049 #define xstrdup(_str) strdup(_str)
2050 #endif /* HAVE_MCHECK_H && defined(__GNUC__) */
2051+#endif /* !__LCLINT__ */
2052
2053
2054 #include "popt.h"
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
2057@@ -149,7 +149,7 @@
2058 fprintf(stdout, "\n");
2059
2060 exit:
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. */
2065 #endif
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
2068@@ -133,7 +133,7 @@
2069 /* although there are no options to be parsed, check for --help */
2070 poptGetNextOpt(optCon);
2071
2072- poptFreeContext(optCon);
2073+ optCon = poptFreeContext(optCon);
2074
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
2079@@ -47,7 +47,7 @@
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
fde7adcd
AF
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
70b78c8f
AF
2090@@ -16,7 +16,6 @@
2091 a given entry is in the file.
2092
2093 Leave the following blank line there!! Autoheader needs it. */
2094-^L
2095
2096 /* Define to the name of the distribution. */
2097 #undef PACKAGE
2098@@ -45,7 +44,6 @@
2099 /* Absolute path to popt top_sourcedir. */
2100 #undef POPT_SOURCE_PATH
2101
2102-^L
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,
This page took 0.758158 seconds and 4 git commands to generate.