diff options
author | jbj <devnull@localhost> | 2001-05-05 19:28:32 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2001-05-05 19:28:32 +0000 |
commit | 8f75bbc17dab6c334583f33c7b912fb16d2ddc4b (patch) | |
tree | 145862352d95e2d391f0d65db0027d44bf236b39 | |
parent | d78e027808deb6aef4e65338d160986d7e576a90 (diff) | |
download | librpm-tizen-8f75bbc17dab6c334583f33c7b912fb16d2ddc4b.tar.gz librpm-tizen-8f75bbc17dab6c334583f33c7b912fb16d2ddc4b.tar.bz2 librpm-tizen-8f75bbc17dab6c334583f33c7b912fb16d2ddc4b.zip |
- enough lclint annotations and fiddles already.
CVS patchset: 4741
CVS date: 2001/05/05 19:28:32
55 files changed, 772 insertions, 451 deletions
diff --git a/build/files.c b/build/files.c index 8e510512e..6f011df9d 100644 --- a/build/files.c +++ b/build/files.c @@ -22,9 +22,9 @@ #include "debug.h" /*@access Header @*/ -/*@access StringBuf @*/ /*@access TFI_t @*/ /*@access FD_t @*/ +/*@access StringBuf @*/ /* compared with NULL */ #define SKIPWHITE(_x) {while(*(_x) && (xisspace(*_x) || *(_x) == ',')) (_x)++;} #define SKIPNONWHITE(_x){while(*(_x) &&!(xisspace(*_x) || *(_x) == ',')) (_x)++;} @@ -271,6 +271,7 @@ typedef struct VFA { /** */ +/*@-exportlocal@*/ VFA_t verifyAttrs[] = { { "md5", RPMVERIFY_MD5 }, { "size", RPMVERIFY_FILESIZE }, @@ -282,6 +283,7 @@ VFA_t verifyAttrs[] = { { "rdev", RPMVERIFY_RDEV }, { NULL, 0 } }; +/*@=exportlocal@*/ /** * @param fl package file tree walk data @@ -737,6 +739,7 @@ static int parseForRegexMultiLib(const char *fileName) /*@*/ /** */ +/*@-exportlocal@*/ VFA_t virtualFileAttributes[] = { { "%dir", 0 }, /* XXX why not RPMFILE_DIR? */ { "%doc", RPMFILE_DOC }, @@ -756,6 +759,7 @@ VFA_t virtualFileAttributes[] = { { NULL, 0 } }; +/*@=exportlocal@*/ /** * @param fl package file tree walk data @@ -1253,7 +1257,9 @@ static void genCpioListAndHeader(/*@partial@*/ FileList fl, d += 2; /* skip both dirname and basename NUL's */ /* Create archive path, normally adding "./" */ + /*@-dependenttrans@*/ /* FIX: xstrdup? nah ... */ fi->apath[i] = a; + /*@=dependenttrans@*/ if (_addDotSlash) a = stpcpy(a, "./"); a = stpcpy(a, (flp->fileURL + skipLen)); a++; /* skip apath NUL */ @@ -1539,7 +1545,8 @@ exit: */ static int processPackageFiles(Spec spec, Package pkg, int installSpecialDoc, int test) - /*@modifies pkg->cpioList, pkg->specialDoc, pkg->header */ + /*@modifies spec->macros, + pkg->cpioList, pkg->specialDoc, pkg->header */ { HGE_t hge = (HGE_t)headerGetEntryMinMemory; struct FileList_s fl; @@ -1964,7 +1971,7 @@ int processSourceFiles(Spec spec) spec->sourceHeader, 1); } - freeStringBuf(sourceFiles); + sourceFiles = freeStringBuf(sourceFiles); fl.fileList = freeFileList(fl.fileList, fl.fileListRecsUsed); return fl.processingFailed; } @@ -2118,6 +2125,7 @@ typedef struct { /** */ +/*@-exportlocal@*/ DepMsg_t depMsgs[] = { { "Provides", { "%{__find_provides}", NULL, NULL, NULL }, RPMTAG_PROVIDENAME, RPMTAG_PROVIDEVERSION, RPMTAG_PROVIDEFLAGS, @@ -2157,6 +2165,7 @@ DepMsg_t depMsgs[] = { 0, -1 }, { NULL, { NULL, NULL, NULL, NULL }, 0, 0, 0, 0, 0 } }; +/*@=exportlocal@*/ /** */ @@ -2261,7 +2270,7 @@ static int generateDepends(Spec spec, Package pkg, TFI_t cpioList, int multiLib) else tagflags &= ~RPMSENSE_MULTILIB; rc = parseRCPOT(spec, pkg, getStringBuf(readBuf), tag, 0, tagflags); - freeStringBuf(readBuf); + readBuf = freeStringBuf(readBuf); if (rc) { rpmError(rc, _("Failed to find %s:\n"), dm->msg); @@ -2269,7 +2278,7 @@ static int generateDepends(Spec spec, Package pkg, TFI_t cpioList, int multiLib) } } - freeStringBuf(writeBuf); + writeBuf = freeStringBuf(writeBuf); return rc; } diff --git a/build/myftw.c b/build/myftw.c index 55ff1e822..499e26ba1 100644 --- a/build/myftw.c +++ b/build/myftw.c @@ -30,6 +30,7 @@ Cambridge, MA 02139, USA. */ #define NAMLEN(a) strlen((a)->d_name) #endif +#if !defined(__LCLINT__) #ifndef PATH_MAX #ifdef _POSIX_VERSION #define PATH_MAX _POSIX_PATH_MAX @@ -41,6 +42,7 @@ Cambridge, MA 02139, USA. */ #endif #endif #endif +#endif /* !__LCLINT */ #include "myftw.h" #include "debug.h" diff --git a/build/pack.c b/build/pack.c index e739afd31..f4a2ed031 100644 --- a/build/pack.c +++ b/build/pack.c @@ -124,7 +124,7 @@ static /*@only@*/ /*@null@*/ StringBuf addFileToTagAux(Spec spec, fd = Fopen(fn, "r.ufdio"); if (fn != buf) fn = _free(fn); if (fd == NULL || Ferror(fd)) { - freeStringBuf(sb); + sb = freeStringBuf(sb); return NULL; } if ((f = fdGetFp(fd)) != NULL) @@ -132,8 +132,7 @@ static /*@only@*/ /*@null@*/ StringBuf addFileToTagAux(Spec spec, /* XXX display fn in error msg */ if (expandMacros(spec, spec->macros, buf, sizeof(buf))) { rpmError(RPMERR_BADSPEC, _("line: %s\n"), buf); - freeStringBuf(sb); - sb = NULL; + sb = freeStringBuf(sb); break; } appendStringBuf(sb, buf); @@ -162,7 +161,7 @@ static int addFileToTag(Spec spec, const char * file, Header h, int tag) (void) headerAddEntry(h, tag, RPM_STRING_TYPE, getStringBuf(sb), 1); - freeStringBuf(sb); + sb = freeStringBuf(sb); return 0; } @@ -180,7 +179,7 @@ static int addFileToArrayTag(Spec spec, const char *file, Header h, int tag) s = getStringBuf(sb); (void) headerAddOrAppendEntry(h, tag, RPM_STRING_ARRAY_TYPE, &s, 1); - freeStringBuf(sb); + sb = freeStringBuf(sb); return 0; } diff --git a/build/parseChangelog.c b/build/parseChangelog.c index 8b9c5fa02..44515383e 100644 --- a/build/parseChangelog.c +++ b/build/parseChangelog.c @@ -203,13 +203,11 @@ static int addChangelog(Header h, StringBuf sb) int parseChangelog(Spec spec) { int nextPart, res, rc; - StringBuf sb; - - sb = newStringBuf(); + StringBuf sb = newStringBuf(); /* There are no options to %changelog */ if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) { - freeStringBuf(sb); + sb = freeStringBuf(sb); return PART_NONE; } if (rc) @@ -226,7 +224,7 @@ int parseChangelog(Spec spec) } res = addChangelog(spec->packages->header, sb); - freeStringBuf(sb); + sb = freeStringBuf(sb); return (res) ? res : nextPart; } diff --git a/build/parseDescription.c b/build/parseDescription.c index 9dad041d7..3f3ab548b 100644 --- a/build/parseDescription.c +++ b/build/parseDescription.c @@ -54,7 +54,7 @@ int parseDescription(Spec spec) poptBadOption(optCon, POPT_BADOPTION_NOALIAS), spec->line); argv = _free(argv); - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); return RPMERR_BADSPEC; } @@ -66,7 +66,7 @@ int parseDescription(Spec spec) spec->lineNum, spec->line); argv = _free(argv); - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); return RPMERR_BADSPEC; } } @@ -75,7 +75,7 @@ int parseDescription(Spec spec) rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s\n"), spec->lineNum, spec->line); argv = _free(argv); - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); return RPMERR_BADSPEC; } @@ -87,7 +87,7 @@ int parseDescription(Spec spec) rpmError(RPMERR_BADSPEC, _("line %d: Second description\n"), spec->lineNum); argv = _free(argv); - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); return RPMERR_BADSPEC; } #endif @@ -122,10 +122,10 @@ int parseDescription(Spec spec) getStringBuf(sb), lang); } - freeStringBuf(sb); + sb = freeStringBuf(sb); argv = _free(argv); - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); return nextPart; } diff --git a/build/parseFiles.c b/build/parseFiles.c index df3e8d9ec..10e6cb056 100644 --- a/build/parseFiles.c +++ b/build/parseFiles.c @@ -9,6 +9,7 @@ #include "debug.h" /*@access StringBuf @*/ /* compared with NULL */ +/*@access poptContext @*/ /* compared with NULL */ /* These have to be global scope to make up for *stupid* compilers */ /*@observer@*/ /*@null@*/ static const char *name = NULL; @@ -25,7 +26,7 @@ int parseFiles(Spec spec) Package pkg; int rc, argc; int arg; - const char **argv = NULL; + const char ** argv = NULL; int flag = PART_SUBNAME; poptContext optCon = NULL; @@ -106,8 +107,7 @@ int parseFiles(Spec spec) exit: argv = _free(argv); - if (optCon) - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); return rc; } diff --git a/build/parsePrep.c b/build/parsePrep.c index da18267e6..b7730d757 100644 --- a/build/parsePrep.c +++ b/build/parsePrep.c @@ -297,9 +297,9 @@ static int doSetupMacro(Spec spec, char *line) if (parseNum(optArg, &num)) { rpmError(RPMERR_BADSPEC, _("line %d: Bad arg to %%setup: %s\n"), spec->lineNum, (optArg ? optArg : "???")); - freeStringBuf(before); - freeStringBuf(after); - poptFreeContext(optCon); + before = freeStringBuf(before); + after = freeStringBuf(after); + optCon = poptFreeContext(optCon); argv = _free(argv); return RPMERR_BADSPEC; } @@ -317,9 +317,9 @@ static int doSetupMacro(Spec spec, char *line) spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(arg)); - freeStringBuf(before); - freeStringBuf(after); - poptFreeContext(optCon); + before = freeStringBuf(before); + after = freeStringBuf(after); + optCon = poptFreeContext(optCon); argv = _free(argv); return RPMERR_BADSPEC; } @@ -334,7 +334,7 @@ static int doSetupMacro(Spec spec, char *line) } addMacro(spec->macros, "buildsubdir", NULL, spec->buildSubdir, RMIL_SPEC); - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); argv = _free(argv); /* cd to the build dir */ @@ -369,7 +369,7 @@ static int doSetupMacro(Spec spec, char *line) } appendStringBuf(spec->prep, getStringBuf(before)); - freeStringBuf(before); + before = freeStringBuf(before); if (!createDir) { sprintf(buf, "cd %s", spec->buildSubdir); @@ -384,7 +384,7 @@ static int doSetupMacro(Spec spec, char *line) } appendStringBuf(spec->prep, getStringBuf(after)); - freeStringBuf(after); + after = freeStringBuf(after); /* XXX FIXME: owner & group fixes were conditioned on !geteuid() */ /* Fix the owner, group, and permissions of the setup build tree */ @@ -516,7 +516,7 @@ static int doPatchMacro(Spec spec, char *line) int parsePrep(Spec spec) { int nextPart, res, rc; - StringBuf buf; + StringBuf sb; char **lines, **saveLines; if (spec->prep != NULL) { @@ -533,12 +533,12 @@ int parsePrep(Spec spec) if (rc) return rc; - buf = newStringBuf(); + sb = newStringBuf(); while (! (nextPart = isPart(spec->line))) { /* Need to expand the macros inline. That way we */ /* can give good line number information on error. */ - appendStringBuf(buf, spec->line); + appendStringBuf(sb, spec->line); if ((rc = readLine(spec, STRIP_NOTHING)) > 0) { nextPart = PART_NONE; break; @@ -547,7 +547,7 @@ int parsePrep(Spec spec) return rc; } - saveLines = splitString(getStringBuf(buf), strlen(getStringBuf(buf)), '\n'); + saveLines = splitString(getStringBuf(sb), strlen(getStringBuf(sb)), '\n'); /*@-usereleased@*/ for (lines = saveLines; *lines; lines++) { res = 0; @@ -560,14 +560,14 @@ int parsePrep(Spec spec) } if (res && !spec->force) { freeSplitString(saveLines); - freeStringBuf(buf); + sb = freeStringBuf(sb); return res; } } /*@=usereleased@*/ freeSplitString(saveLines); - freeStringBuf(buf); + sb = freeStringBuf(sb); return nextPart; } diff --git a/build/parseScript.c b/build/parseScript.c index 4e2717495..070e803ab 100644 --- a/build/parseScript.c +++ b/build/parseScript.c @@ -9,6 +9,7 @@ #include "debug.h" /*@access StringBuf@*/ /* XXX compared with NULL */ +/*@access poptContext @*/ /* compared with NULL */ /** */ @@ -293,12 +294,10 @@ int parseScript(Spec spec, int parsePart) rc = nextPart; exit: - if (sb != NULL) - freeStringBuf(sb); + sb = freeStringBuf(sb); progArgv = _free(progArgv); argv = _free(argv); - if (optCon) - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); return rc; } diff --git a/build/rpmbuild.h b/build/rpmbuild.h index 73c7f50a2..7e66e395c 100644 --- a/build/rpmbuild.h +++ b/build/rpmbuild.h @@ -371,6 +371,7 @@ int rpmlibNeedsFeature(Header h, const char * feature, const char * featureEVR) */ int processBinaryFiles(Spec spec, int installSpecialDoc, int test) /*@modifies spec->packages->cpioList, spec->packages->specialDoc, + spec->macros, spec->packages->header @*/; /** \ingroup rpmbuild @@ -408,7 +409,7 @@ int processSourceFiles(Spec spec) * @return */ int parseSpec(/*@out@*/ Spec * specp, const char * specFile, - const char * rootdir, + /*@null@*/ const char * rootdir, /*@null@*/ const char * buildRoot, int inBuildArch, /*@null@*/ const char * passPhrase, diff --git a/build/rpmspec.h b/build/rpmspec.h index 2533e584e..3b660b0a9 100644 --- a/build/rpmspec.h +++ b/build/rpmspec.h @@ -207,7 +207,7 @@ struct spectag * stashSt(Spec spec, Header h, int tag, const char * lang) */ int addSource(Spec spec, Package pkg, const char * field, int tag) /*@modifies spec->sources, spec->numSources, - spec->st, + spec->st, spec->macros, pkg->icon @*/; /** \ingroup rpmbuild diff --git a/build/spec.c b/build/spec.c index 6d5c5d85f..a0f03d1e1 100644 --- a/build/spec.c +++ b/build/spec.c @@ -147,7 +147,7 @@ void freePackage(/*@only@*/ Package p) p->verifyFile = _free(p->verifyFile); headerFree(p->header); - freeStringBuf(p->fileList); + p->fileList = freeStringBuf(p->fileList); p->fileFile = _free(p->fileFile); if (p->cpioList) { TFI_t fi = p->cpioList; @@ -156,7 +156,7 @@ void freePackage(/*@only@*/ Package p) fi = _free(fi); } - freeStringBuf(p->specialDoc); + p->specialDoc = freeStringBuf(p->specialDoc); freeSources(p->icon); @@ -454,10 +454,10 @@ void freeSpec(/*@only@*/ Spec spec) freeSl(spec->sl); spec->sl = NULL; freeSt(spec->st); spec->st = NULL; - freeStringBuf(spec->prep); spec->prep = NULL; - freeStringBuf(spec->build); spec->build = NULL; - freeStringBuf(spec->install); spec->install = NULL; - freeStringBuf(spec->clean); spec->clean = NULL; + spec->prep = freeStringBuf(spec->prep); + spec->build = freeStringBuf(spec->build); + spec->install = freeStringBuf(spec->install); + spec->clean = freeStringBuf(spec->clean); spec->buildRootURL = _free(spec->buildRootURL); spec->buildSubdir = _free(spec->buildSubdir); diff --git a/lib/Makefile.am b/lib/Makefile.am index dc7aec1b7..247cb446f 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -57,9 +57,9 @@ getdate.c: getdate.y @echo expect 10 shift/reduce conflicts $(YACC) $(srcdir)/getdate.y -@if test -f y.tab.c; then \ - { echo "/*@-globstate -retvalint -unqualifiedtrans -usedef -varuse -nullderef@*/";\ + { echo "/*@-globstate -retvalint -unqualifiedtrans -usedef -varuse -nullderef -exportlocal @*/";\ cat y.tab.c ;\ - echo "/*@=globstate =retvalint =unqualifiedtrans =usedef =varuse =nullderef@*/";\ + echo "/*@=globstate =retvalint =unqualifiedtrans =usedef =varuse =nullderef =exportlocal @*/";\ } > getdate.c ;\ rm -f y.tab.c; \ else \ diff --git a/lib/dbconfig.c b/lib/dbconfig.c index 8ece273fb..26459d740 100644 --- a/lib/dbconfig.c +++ b/lib/dbconfig.c @@ -19,7 +19,9 @@ #if DB_VERSION_MAJOR == 3 #define __USE_DB3 1 +/*@-exportlocal@*/ struct _dbiIndex db3dbi; +/*@=exportlocal@*/ /** \ingroup db3 * Analogue to struct poptOption @@ -33,7 +35,7 @@ struct dbOption { #define _POPT_SET_BIT (POPT_ARG_VAL|POPT_ARGFLAG_OR) -/*@-immediatetrans@*/ +/*@-immediatetrans -exportlocal@*/ /** \ingroup db3 */ struct dbOption rdbOptions[] = { @@ -142,7 +144,7 @@ struct dbOption rdbOptions[] = { { NULL, 0, NULL, 0 } }; -/*@=immediatetrans@*/ +/*@=immediatetrans =exportlocal@*/ static int dbSaveLong(const struct dbOption * opt, long aLong) { if (opt->argInfo & POPT_ARGFLAG_NOT) diff --git a/lib/formats.c b/lib/formats.c index 97a58d4f2..018d2c59d 100644 --- a/lib/formats.c +++ b/lib/formats.c @@ -398,7 +398,9 @@ static int filenamesTag(Header h, /*@out@*/ int_32 * type, /* I18N look aside diversions */ +/*@-exportlocal@*/ int _nl_msg_cat_cntr; /* XXX GNU gettext voodoo */ +/*@=exportlocal@*/ static const char * language = "LANGUAGE"; static char * _macro_i18ndomains = "%{?_i18ndomains:%{_i18ndomains}}"; @@ -20,14 +20,17 @@ int _fsm_debug = 0; /* XXX Failure to remove is not (yet) cause for failure. */ +/*@-exportlocal@*/ int strict_erasures = 0; +/*@=exportlocal@*/ rpmTransactionSet fsmGetTs(const FSM_t fsm) { const FSMI_t iter = fsm->iter; return (iter ? iter->ts : NULL); } -TFI_t fsmGetFi(const FSM_t fsm) { +TFI_t fsmGetFi(const FSM_t fsm) +{ const FSMI_t iter = fsm->iter; return (iter ? iter->fi : NULL); } @@ -44,10 +47,12 @@ TFI_t fsmGetFi(const FSM_t fsm) { * @param suffix suffix to use (NULL disables) * @retval path to file */ -static /*@only@*//*@null@*/ const char * fsmFsPath(/*@null@*/ const FSM_t fsm, - /*@null@*/ const struct stat * st, - /*@null@*/ const char * subdir, - /*@null@*/ const char * suffix) +static /*@only@*//*@null@*/ +const char * fsmFsPath(/*@special@*/ /*@null@*/ const FSM_t fsm, + /*@null@*/ const struct stat * st, + /*@null@*/ const char * subdir, + /*@null@*/ const char * suffix) + /*@uses fsm->dirName, fsm->baseName */ { const char * s = NULL; @@ -125,6 +130,7 @@ static int mapNextIterator(void * this) { /** \ingroup payload */ static int cpioStrCmp(const void * a, const void * b) + /*@*/ { const char * afn = *(const char **)a; const char * bfn = *(const char **)b; @@ -146,7 +152,9 @@ static int cpioStrCmp(const void * a, const void * b) * @param fsmPath archive path * @return index into file info, -1 if archive path was not found */ -static int mapFind(void * this, const char * fsmPath) { +static int mapFind(void * this, const char * fsmPath) + /*@*/ +{ FSMI_t iter = this; const TFI_t fi = iter->fi; int ix = -1; @@ -154,7 +162,9 @@ static int mapFind(void * this, const char * fsmPath) { if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) { const char ** p; + /*@-nullpass@*/ /* LCL: fi->apath != NULL */ p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath), cpioStrCmp); + /*@=nullpass@*/ if (p == NULL) { fprintf(stderr, "*** not mapped %s\n", fsmPath); } else { @@ -208,7 +218,9 @@ static inline int dnlIndex(const DNLI_t dnli) { * @param reverse traverse directory names in reverse order? * @return directory name iterator */ -static /*@only@*/ void * dnlInitIterator(const FSM_t fsm, int reverse) +static /*@only@*/ void * dnlInitIterator(/*@special@*/ const FSM_t fsm, + int reverse) + /*@uses fsm->iter @*/ { TFI_t fi = fsmGetFi(fsm); DNLI_t dnli; @@ -309,7 +321,10 @@ static /*@observer@*/ const char * dnlNextIterator(/*@null@*/ DNLI_t dnli) * @return Is chain only partially filled? */ /*@-compmempass@*/ -static int saveHardLink(FSM_t fsm) +static int saveHardLink(/*@special@*/ /*@partial@*/ FSM_t fsm) + /*@uses fsm->links, fsm->ix, fsm->sb, fsm->goal, fsm->nsuffix @*/ + /*@defines fsm->li @*/ + /*@releases fsm->path @*/ { struct stat * st = &fsm->sb; int rc = 0; @@ -406,7 +421,8 @@ static /*@null@*/ void * freeHardLink(/*@only@*/ /*@null@*/ struct hardLink * li return _free(li); } -FSM_t newFSM(void) { +FSM_t newFSM(void) +{ FSM_t fsm = xcalloc(1, sizeof(*fsm)); return fsm; } @@ -467,7 +483,7 @@ int fsmSetup(FSM_t fsm, fileStage goal, rc = fsmStage(fsm, fsm->goal); - if (!rc && fsm->archiveSize) + if (fsm->archiveSize && rc == 0) *fsm->archiveSize = (fdGetCpioPos(fsm->cfd) - pos); return rc; @@ -532,12 +548,12 @@ assert(fi->type == TR_ADDED); break; case FA_SKIPNSTATE: - if (fi->type == TR_ADDED) + if (fi->fstates && fi->type == TR_ADDED) fi->fstates[i] = RPMFILE_STATE_NOTINSTALLED; break; case FA_SKIPNETSHARED: - if (fi->type == TR_ADDED) + if (fi->fstates && fi->type == TR_ADDED) fi->fstates[i] = RPMFILE_STATE_NETSHARED; break; @@ -617,8 +633,8 @@ int fsmMapAttrs(FSM_t fsm) * @param fsm file state machine data * @return 0 on success */ -static int expandRegular(FSM_t fsm) - /*@modifies fileSystem, fsm @*/ +static int expandRegular(/*@special@*/ FSM_t fsm) + /*@uses fsm->sb @*/ { const char * fmd5sum; const struct stat * st = &fsm->sb; @@ -680,9 +696,8 @@ exit: * @param writeData should data be written? * @return 0 on success */ -/*@-compmempass@*/ -static int writeFile(FSM_t fsm, int writeData) - /*@modifies fsm @*/ +static int writeFile(/*@special@*/ FSM_t fsm, int writeData) + /*@uses fsm->path, fsm->opath, fsm->sb, fsm->osb, fsm->cfd @*/ { const char * path = fsm->path; const char * opath = fsm->opath; @@ -806,15 +821,14 @@ exit: /*@=dependenttrans@*/ return rc; } -/*@=compmempass@*/ /** \ingroup payload * Write set of linked files to payload stream. * @param fsm file state machine data * @return 0 on success */ -static int writeLinkedFile(FSM_t fsm) - /*@modifies fsm @*/ +static int writeLinkedFile(/*@special@*/ FSM_t fsm) + /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->li, fsm->failedFile @*/ { const char * path = fsm->path; const char * nsuffix = fsm->nsuffix; @@ -835,7 +849,7 @@ static int writeLinkedFile(FSM_t fsm) /* Write data after last link. */ rc = writeFile(fsm, (i == 0)); - if (rc && fsm->failedFile && *fsm->failedFile == NULL) { + if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) { ec = rc; *fsm->failedFile = xstrdup(fsm->path); } @@ -855,7 +869,8 @@ static int writeLinkedFile(FSM_t fsm) * @param fsm file state machine data * @return 0 on success */ -static int fsmMakeLinks(FSM_t fsm) +static int fsmMakeLinks(/*@special@*/ FSM_t fsm) + /*@uses fsm->path, fsm->opath, fsm->nsuffix, fsm->ix, fsm->li @*/ { const char * path = fsm->path; const char * opath = fsm->opath; @@ -886,7 +901,7 @@ static int fsmMakeLinks(FSM_t fsm) /* XXX link(fsm->opath, fsm->path) */ rc = fsmStage(fsm, FSM_LINK); - if (rc && fsm->failedFile && *fsm->failedFile == NULL) { + if (fsm->failedFile && rc != 0 && *fsm->failedFile == NULL) { ec = rc; *fsm->failedFile = xstrdup(fsm->path); } @@ -907,8 +922,9 @@ static int fsmMakeLinks(FSM_t fsm) * @param fsm file state machine data * @return 0 on success */ -/*@-compmempass@*/ -static int fsmCommitLinks(FSM_t fsm) +static int fsmCommitLinks(/*@special@*/ FSM_t fsm) + /*@uses fsm->path, fsm->nsuffix, fsm->ix, fsm->sb, + fsm->li, fsm->links @*/ { const char * path = fsm->path; const char * nsuffix = fsm->nsuffix; @@ -940,14 +956,15 @@ static int fsmCommitLinks(FSM_t fsm) fsm->path = path; return rc; } -/*@=compmempass@*/ /** * Remove (if created) directories not explicitly included in package. * @param fsm file state machine data * @return 0 on success */ -static int fsmRmdirs(FSM_t fsm) +/*@-compdef@*/ +static int fsmRmdirs(/*@special@*/ FSM_t fsm) + /*@uses fsm->path, fsm->dnlx, fsm->ldn, fsm->rdbuf, fsm->iter @*/ { const char * path = fsm->path; void * dnli = dnlInitIterator(fsm, 1); @@ -958,6 +975,7 @@ static int fsmRmdirs(FSM_t fsm) fsm->path = NULL; dn[0] = '\0'; /*@-observertrans -dependenttrans@*/ + if (fsm->ldn != NULL && fsm->dnlx != NULL) while ((fsm->path = dnlNextIterator(dnli)) != NULL) { int dnlen = strlen(fsm->path); char * te; @@ -987,13 +1005,17 @@ static int fsmRmdirs(FSM_t fsm) fsm->path = path; return rc; } +/*@=compdef@*/ /** * Create (if necessary) directories not explicitly included in package. * @param fsm file state machine data * @return 0 on success */ -static int fsmMkdirs(FSM_t fsm) +static int fsmMkdirs(/*@special@*/ FSM_t fsm) + /*@uses fsm->path, fsm->sb, fsm->osb, fsm->rdbuf, fsm->iter, + fsm->ldn, fsm->ldnlen, fsm->ldnalloc @*/ + /*@defines fsm->dnlx, fsm->ldn @*/ { struct stat * st = &fsm->sb; struct stat * ost = &fsm->osb; @@ -1010,6 +1032,7 @@ static int fsmMkdirs(FSM_t fsm) dn[0] = '\0'; fsm->dnlx = (dc ? xcalloc(dc, sizeof(*fsm->dnlx)) : NULL); /*@-observertrans -dependenttrans@*/ + if (fsm->dnlx != NULL) while ((fsm->path = dnlNextIterator(dnli)) != NULL) { int dnlen = strlen(fsm->path); char * te; @@ -1019,8 +1042,11 @@ static int fsmMkdirs(FSM_t fsm) fsm->dnlx[dc] = dnlen; if (dnlen <= 1) continue; + + /*@-compdef -nullpass@*/ /* FIX: fsm->ldn not defined ??? */ if (dnlen <= fsm->ldnlen && !strcmp(fsm->path, fsm->ldn)) continue; + /*@=compdef =nullpass@*/ /* Copy to avoid const on fsm->path. */ (void) stpcpy(dn, fsm->path); @@ -1033,6 +1059,7 @@ static int fsmMkdirs(FSM_t fsm) *te = '\0'; /* Already validated? */ + /*@-usedef -compdef -nullpass -nullderef@*/ if (i < fsm->ldnlen && (fsm->ldn[i] == '/' || fsm->ldn[i] == '\0') && !strncmp(fsm->path, fsm->ldn, i)) @@ -1042,6 +1069,7 @@ static int fsmMkdirs(FSM_t fsm) fsm->dnlx[dc] = (te - dn); continue; } + /*@=usedef =compdef =nullpass =nullderef@*/ /* Validate next component of path. */ rc = fsmStage(fsm, FSM_LSTAT); @@ -1071,7 +1099,9 @@ static int fsmMkdirs(FSM_t fsm) fsm->ldnalloc = dnlen + 100; fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc); } + /*@-nullpass@*/ /* FIX: fsm->ldn NULL. */ strcpy(fsm->ldn, fsm->path); + /*@=nullpass@*/ fsm->ldnlen = dnlen; } dnli = dnlFreeIterator(dnli); @@ -120,28 +120,28 @@ struct fsm_s { /*@dependent@*/ char * rdbuf; /*!< read: Buffer. */ /*@owned@*/ char * rdb; /*!< read: Buffer allocated. */ size_t rdsize; /*!< read: Buffer allocated size. */ - size_t rdlen; /*!< read: Number of bytes requested. */ + size_t rdlen; /*!< read: Number of bytes requested.*/ size_t rdnb; /*!< read: Number of bytes returned. */ FD_t wfd; /*!< write: File handle. */ /*@dependent@*/ char * wrbuf; /*!< write: Buffer. */ /*@owned@*/ char * wrb; /*!< write: Buffer allocated. */ size_t wrsize; /*!< write: Buffer allocated size. */ - size_t wrlen; /*!< write: Number of bytes requested. */ + size_t wrlen; /*!< write: Number of bytes requested.*/ size_t wrnb; /*!< write: Number of bytes returned. */ /*@only@*/ FSMI_t iter; /*!< File iterator. */ int ix; /*!< Current file iterator index. */ /*@only@*/ struct hardLink * links; /*!< Pending hard linked file(s). */ /*@only@*/ struct hardLink * li; /*!< Current hard linked file(s). */ -/*@kept@*/ unsigned int * archiveSize; /*!< Pointer to archive size. */ -/*@kept@*/ const char ** failedFile; /*!< First file name that failed. */ +/*@kept@*/ /*@null@*/ unsigned int * archiveSize; /*!< Pointer to archive size. */ +/*@kept@*/ /*@null@*/ const char ** failedFile; /*!< First file name that failed. */ /*@shared@*/ const char * subdir; /*!< Current file sub-directory. */ char subbuf[64]; /* XXX eliminate */ /*@observer@*/ const char * osuffix; /*!< Old, preserved, file suffix. */ /*@observer@*/ const char * nsuffix; /*!< New, created, file suffix. */ /*@shared@*/ const char * suffix; /*!< Current file suffix. */ char sufbuf[64]; /* XXX eliminate */ -/*@only@*/ short * dnlx; /*!< Last dirpath verified indexes. */ -/*@only@*/ char * ldn; /*!< Last dirpath verified. */ +/*@only@*/ /*@null@*/ short * dnlx; /*!< Last dirpath verified indexes. */ +/*@only@*/ /*@null@*/ char * ldn; /*!< Last dirpath verified. */ int ldnlen; /*!< Last dirpath current length. */ int ldnalloc; /*!< Last dirpath allocated length. */ int postpone; /*!< Skip remaining stages? */ @@ -167,6 +167,7 @@ struct fsm_s { extern "C" { #endif +/*@-exportlocal@*/ /** * Return formatted string representation of file stages. * @param a file stage @@ -180,6 +181,7 @@ extern "C" { * @return formatted string */ /*@observer@*/ const char *const fileActionString(fileAction a); +/*@=exportlocal@*/ /** * Create file state machine instance. @@ -205,12 +207,12 @@ extern "C" { * @return 0 on success */ int fsmSetup(FSM_t fsm, fileStage goal, - /*@kept@*/ const rpmTransactionSet ts, - /*@kept@*/ const TFI_t fi, - FD_t cfd, - /*@out@*/ unsigned int * archiveSize, - /*@out@*/ const char ** failedFile) - /*@modifies fsm, *archiveSize, *failedFile @*/; + /*@kept@*/ const rpmTransactionSet ts, + /*@kept@*/ const TFI_t fi, + FD_t cfd, + /*@out@*/ unsigned int * archiveSize, + /*@out@*/ const char ** failedFile) + /*@modifies fsm, *archiveSize, *failedFile @*/; /** * Clean file state machine. @@ -218,35 +220,39 @@ int fsmSetup(FSM_t fsm, fileStage goal, * @return 0 on success */ int fsmTeardown(FSM_t fsm) - /*@modifies fsm @*/; + /*@modifies fsm @*/; +/*@-exportlocal@*/ /** * Retrieve transaction set from file state machine iterator. * @param fsm file state machine data * @return transaction set */ -/*@kept@*/ rpmTransactionSet fsmGetTs(const FSM_t fsm) /*@*/; +/*@kept@*/ rpmTransactionSet fsmGetTs(const FSM_t fsm) + /*@*/; /** * Retrieve transaction element file info from file state machine iterator. * @param fsm file state machine data * @return transaction element file info */ -/*@kept@*/ TFI_t fsmGetFi(const FSM_t fsm) /*@*/; +/*@kept@*/ TFI_t fsmGetFi(/*@partial@*/const FSM_t fsm) + /*@*/; /** * Map next file path and action. * @param fsm file state machine data */ int fsmMapPath(FSM_t fsm) - /*@modifies fsm @*/; + /*@modifies fsm @*/; /** * Map file stat(2) info. * @param fsm file state machine data */ int fsmMapAttrs(FSM_t fsm) - /*@modifies fsm @*/; + /*@modifies fsm @*/; +/*@=exportlocal@*/ /** * File state machine driver. @@ -255,7 +261,7 @@ int fsmMapAttrs(FSM_t fsm) * @return 0 on success */ int fsmStage(/*@partial@*/ FSM_t fsm, fileStage stage) - /*@modifies fsm @*/; + /*@modifies fsm @*/; #ifdef __cplusplus } diff --git a/lib/header.h b/lib/header.h index d0032c0ff..db7fdea21 100644 --- a/lib/header.h +++ b/lib/header.h @@ -431,9 +431,11 @@ int headerGetEntryMinMemory(Header h, int_32 tag, /*@out@*/ int_32 *type, * @retval c address of number of values * @return 1 on success, 0 on failure */ +/*@-exportlocal@*/ int headerGetRawEntry(Header h, int_32 tag, /*@out@*/ int_32 *type, /*@out@*/ const void **p, /*@out@*/ int_32 *c) /*@modifies *type, *p, *c @*/; +/*@=exportlocal@*/ /** \ingroup header * Check if tag is in header. @@ -495,6 +497,7 @@ void headerFreeIterator( /*@only@*/ HeaderIterator iter); * Sort tags in header. * @param h header */ +/*@-exportlocal@*/ void headerSort(Header h) /*@modifies h @*/; @@ -504,6 +507,7 @@ void headerSort(Header h) */ void headerUnsort(Header h) /*@modifies h @*/; +/*@=exportlocal@*/ /** \ingroup header * Duplicate tag values from one header into another. diff --git a/lib/manifest.c b/lib/manifest.c index 7660cb449..c1480ec84 100644 --- a/lib/manifest.c +++ b/lib/manifest.c @@ -153,7 +153,7 @@ exit: /*@-unqualifiedtrans@*/av[i] = _free(av[i]); /*@=unqualifiedtrans@*/ /*@-dependenttrans@*/ av = _free(av); /*@=dependenttrans@*/ } - freeStringBuf(sb); + sb = freeStringBuf(sb); /*@-nullstate@*/ return rc; /*@=nullstate@*/ @@ -27,7 +27,9 @@ static union _mendian { int i; char b[4]; } *_endian = (union _mendian *)&_ie; #define IS_BIG_ENDIAN() (_endian->b[0] == '\x44') #define IS_LITTLE_ENDIAN() (_endian->b[0] == '\x11') +/*@-exportlocal@*/ void byteReverse(unsigned char *buf, unsigned longs); +/*@=exportlocal@*/ /* * Note: this code is harmless on little-endian machines. @@ -64,9 +64,9 @@ void rpmMD5Final(unsigned char digest[16], struct MD5Context *context); * @param buf current MD5 variables * @param in next block of data to add */ -/*@-fixedformalarray@*/ +/*@-fixedformalarray -exportlocal@*/ void rpmMD5Transform(uint32 buf[4], uint32 const in[16]); -/*@=fixedformalarray@*/ +/*@=fixedformalarray =exportlocal@*/ /** * Return MD5 sum of file as ASCII string. @@ -1427,7 +1427,9 @@ assert(psm->mi == NULL); } /* Retrieve type of payload compression. */ + /*@-nullstate@*/ /* FIX: psm->oh may be NULL */ rc = psmStage(psm, PSM_RPMIO_FLAGS); + /*@=nullstate@*/ /* Write the lead section into the package. */ { int archnum = -1; @@ -1613,8 +1615,10 @@ assert(psm->mi == NULL); int_32 installTime = time(NULL); if (fi->fc > 0 && fi->fstates) + /*@-nullpass@*/ /* LCL: fi->fstates != NULL */ (void) headerAddEntry(fi->h, RPMTAG_FILESTATES, RPM_CHAR_TYPE, fi->fstates, fi->fc); + /*@=nullpass@*/ (void) headerAddEntry(fi->h, RPMTAG_INSTALLTIME, RPM_INT32_TYPE, &installTime, 1); @@ -1712,7 +1716,8 @@ assert(psm->mi == NULL); if (psm->goal == PSM_PKGSAVE) { if (!rc) - rpmMessage(RPMMESS_VERBOSE, _("Wrote: %s\n"), psm->pkgURL); + rpmMessage(RPMMESS_VERBOSE, _("Wrote: %s\n"), + (psm->pkgURL ? psm->pkgURL : "???")); } if (fi->h && (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE)) { @@ -1857,5 +1862,7 @@ assert(psm->mi == NULL); break; } + /*@-nullstate@*/ /* FIX: psm->oh and psm->fi->h may be NULL. */ return rc; + /*@=nullstate@*/ } @@ -56,7 +56,7 @@ struct transactionFileInfo_s { /*@owned@*/ const char ** flinks; /*!< File link(s) (from header) */ /* XXX setuid/setgid bits are turned off if fuser/fgroup doesn't map. */ uint_16 * fmodes; /*!< File mode(s) (from header) */ -/*@owned@*/ char * fstates; /*!< File state(s) (from header) */ +/*@only@*/ /*@null@*/ char * fstates; /*!< File state(s) (from header) */ /*@owned@*/ const char ** fuser; /*!< File owner(s) */ /*@owned@*/ const char ** fgroup; /*!< File group(s) */ /*@owned@*/ const char ** flangs; /*!< File lang(s) */ @@ -69,7 +69,7 @@ struct transactionFileInfo_s { unsigned int archiveSize; mode_t dperms; /*!< Directory perms (0755) if not mapped. */ mode_t fperms; /*!< File perms (0644) if not mapped. */ -/*@owned@*/ const char ** apath; +/*@only@*/ /*@null@*/ const char ** apath; int mapflags; /*@owned@*/ int * fmapflags; uid_t uid; @@ -142,11 +142,11 @@ struct psm_s { FD_t cfd; /*!< Payload file handle. */ FD_t fd; /*!< Repackage file handle. */ Header oh; /*!< Repackage/multilib header. */ - rpmdbMatchIterator mi; +/*@null@*/ rpmdbMatchIterator mi; /*@observer@*/ const char * stepName; -/*@owned@*/ const char * rpmio_flags; -/*@owned@*/ const char * failedFile; -/*@owned@*/ const char * pkgURL; /*!< Repackage URL. */ +/*@only@*/ /*@null@*/ const char * rpmio_flags; +/*@only@*/ /*@null@*/ const char * failedFile; +/*@only@*/ /*@null@*/ const char * pkgURL; /*!< Repackage URL. */ /*@dependent@*/ const char * pkgfn; /*!< Repackage file name. */ int scriptTag; /*!< Scriptlet data tag. */ int progTag; /*!< Scriptlet interpreter tag. */ @@ -187,7 +187,8 @@ void freeFi(TFI_t fi) * @param a package dispostion * @return formatted string */ -/*@observer@*/ const char *const fiTypeString(/*@partial@*/TFI_t fi); +/*@observer@*/ const char *const fiTypeString(/*@partial@*/TFI_t fi) + /*@*/; /** * Package state machine driver. @@ -195,7 +196,7 @@ void freeFi(TFI_t fi) * @param stage next stage * @return 0 on success */ -int psmStage(/*@partial@*/ PSM_t psm, pkgStage stage) +int psmStage(PSM_t psm, pkgStage stage) /*@modifies psm @*/; #ifdef __cplusplus diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 5bedc7972..f8d1b97bc 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -28,7 +28,9 @@ extern int _noDirTokens; static int _rebuildinprogress = 0; static int _db_filter_dups = 0; +/*@-exportlocal@*/ int _filterDbDups = 0; /* Filter duplicate entries ? (bug in pre rpm-3.0.4) */ +/*@=exportlocal@*/ #define _DBI_FLAGS 0 #define _DBI_PERMS 0644 @@ -723,7 +725,7 @@ int rpmdbSync(rpmdb rpmdb) } static /*@only@*/ rpmdb newRpmdb(/*@kept@*/ /*@null@*/ const char * root, - /*@kept@*/ const char * home, + /*@kept@*/ /*@null@*/ const char * home, int mode, int perms, int flags) { rpmdb rpmdb = xcalloc(sizeof(*rpmdb), 1); diff --git a/lib/rpmdb.h b/lib/rpmdb.h index 5b5d5414b..a23689160 100644 --- a/lib/rpmdb.h +++ b/lib/rpmdb.h @@ -277,6 +277,7 @@ enum rpmdbFlags { extern "C" { #endif +/*@-exportlocal@*/ /** \ingroup db3 * Return new configured index database handle instance. * @param rpmdb rpm database @@ -392,6 +393,7 @@ int dbiByteSwapped(dbiIndex dbi); * @return base file name of db1 database */ char * db1basename(int rpmtag); +/*@=exportlocal@*/ /** \ingroup rpmdb */ diff --git a/lib/rpmlib.h b/lib/rpmlib.h index 750c5da73..717e98785 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -484,7 +484,7 @@ int rpmReadConfigFiles(/*@null@*/ const char * file, * @param file colon separated files to read (NULL uses default) * @return 0 on succes */ -int rpmReadRC(const char * file); +int rpmReadRC(/*@null@*/ const char * file); /** \ingroup rpmrc * Return current arch name and/or number. @@ -912,7 +912,7 @@ typedef struct rpmRelocation_s { * @retval cooke address of cookie pointer * @return rpmRC return code */ -rpmRC rpmInstallSourcePackage(const char * root, FD_t fd, +rpmRC rpmInstallSourcePackage(/*@null@*/ const char * root, FD_t fd, /*@out@*/ const char ** specFile, rpmCallbackFunction notify, rpmCallbackData notifyData, /*@out@*/ char ** cookie) diff --git a/lib/rpmrc.c b/lib/rpmrc.c index 0caf493c6..24698ba50 100644 --- a/lib/rpmrc.c +++ b/lib/rpmrc.c @@ -413,6 +413,7 @@ int rpmReadConfigFiles(const char * file, const char * target) { /* Preset target macros */ + /*@-nullstate@*/ /* FIX: target can be NULL */ rpmRebuildTargetVars(&target, NULL); /* Read the files */ @@ -420,6 +421,7 @@ int rpmReadConfigFiles(const char * file, const char * target) /* Reset target macros */ rpmRebuildTargetVars(&target, NULL); + /*@=nullstate@*/ /* Finally set target platform */ { const char *cpu = rpmExpand("%{_target_cpu}", NULL); @@ -611,6 +613,7 @@ int rpmReadRC(const char * rcfiles) return rc; } +/*@-usedef@*/ /*@ FIX: se usage inconsistent, W2DO? */ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) { const char *s; @@ -825,6 +828,7 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) return 0; } +/*@=usedef@*/ # if defined(__linux__) && defined(__i386__) #include <setjmp.h> @@ -1385,7 +1389,7 @@ void rpmGetOsInfo(const char ** name, int * num) { getMachineInfo(OS, name, num); } -void rpmRebuildTargetVars(const char **buildtarget, const char ** canontarget) +void rpmRebuildTargetVars(const char ** buildtarget, const char ** canontarget) { char *ca = NULL, *co = NULL, *ct = NULL; diff --git a/lib/signature.h b/lib/signature.h index 59d613d47..4e88d21a6 100644 --- a/lib/signature.h +++ b/lib/signature.h @@ -92,8 +92,8 @@ int rpmLookupSignatureType(int action) * Return path to pgp executable of given type, or NULL when not found. */ /*@null@*/ const char * rpmDetectPGPVersion( - /*@null@*/ /*@out@*/ pgpVersion *pgpVersion) - /*@modifies *pgpVersion, fileSystem @*/; + /*@null@*/ /*@out@*/ pgpVersion * pgpVer) + /*@modifies *pgpVer, fileSystem @*/; #ifdef __cplusplus } diff --git a/lib/stringbuf.c b/lib/stringbuf.c index 203f869c5..c4324d12b 100644 --- a/lib/stringbuf.c +++ b/lib/stringbuf.c @@ -9,6 +9,13 @@ #define BUF_CHUNK 1024 +struct StringBufRec { + /*@owned@*/ char *buf; + /*@dependent@*/ char *tail; /* Points to first "free" char */ + int allocated; + int free; +}; + /** * Locale insensitive isspace(3). */ @@ -16,12 +23,15 @@ return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v'); } -struct StringBufRec { - /*@owned@*/ char *buf; - /*@dependent@*/ char *tail; /* Points to first "free" char */ - int allocated; - int free; -}; +/** + * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. + * @param this memory to free + * @retval NULL always + */ +/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { + if (this != NULL) free((void *)this); + return NULL; +} StringBuf newStringBuf(void) { @@ -35,14 +45,13 @@ StringBuf newStringBuf(void) return sb; } -void freeStringBuf(StringBuf sb) +StringBuf freeStringBuf(StringBuf sb) { - if (! sb) { - return; + if (sb) { + sb->buf = _free(sb->buf); + sb = _free(sb); } - - free(sb->buf); - free(sb); + return sb; } void truncStringBuf(StringBuf sb) @@ -64,7 +73,7 @@ void stripTrailingBlanksStringBuf(StringBuf sb) sb->tail[0] = '\0'; } -char *getStringBuf(StringBuf sb) +char * getStringBuf(StringBuf sb) { return sb->buf; } diff --git a/lib/stringbuf.h b/lib/stringbuf.h index cc48fac95..c5a50eb7c 100644 --- a/lib/stringbuf.h +++ b/lib/stringbuf.h @@ -19,7 +19,7 @@ extern "C" { /** */ -void freeStringBuf( /*@only@*/ StringBuf sb); +/*@null@*/ StringBuf freeStringBuf( /*@only@*/ /*@null@*/ StringBuf sb); /** */ diff --git a/lib/transaction.c b/lib/transaction.c index 6e633db31..b1dd2f477 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -1142,7 +1142,7 @@ static void handleOverlappedFiles(TFI_t fi, hashTable ht, } if (XFA_SKIPPING(fi->actions[i])) break; - if (fi->fstates[i] != RPMFILE_STATE_NORMAL) + if (fi->fstates && fi->fstates[i] != RPMFILE_STATE_NORMAL) break; if (!(S_ISREG(fi->fmodes[i]) && (fi->fflags[i] & RPMFILE_CONFIG))) { fi->actions[i] = FA_ERASE; diff --git a/lib/verify.c b/lib/verify.c index f302e5bf5..c0b3bb057 100644 --- a/lib/verify.c +++ b/lib/verify.c @@ -331,7 +331,7 @@ static int verifyHeader(QVA_t qva, Header h) HGE_t hge = (HGE_t)headerGetEntryMinMemory; char buf[BUFSIZ]; char * t, * te; - + const char * prefix = (qva->qva_prefix ? qva->qva_prefix : ""); const char ** fileNames = NULL; int count; int_32 * fileFlagsList = NULL; @@ -355,7 +355,7 @@ static int verifyHeader(QVA_t qva, Header h) for (i = 0; i < count; i++) { int rc; - rc = rpmVerifyFile(qva->qva_prefix, h, i, &verifyResult, omitMask); + rc = rpmVerifyFile(prefix, h, i, &verifyResult, omitMask); if (rc) { sprintf(te, _("missing %s"), fileNames[i]); te += strlen(te); @@ -469,6 +469,7 @@ static int verifyDependencies(rpmdb rpmdb, Header h) int showVerifyPackage(QVA_t qva, rpmdb rpmdb, Header h) { + const char * prefix = (qva->qva_prefix ? qva->qva_prefix : ""); FD_t fdo; int ec = 0; int rc; @@ -481,7 +482,7 @@ int showVerifyPackage(QVA_t qva, rpmdb rpmdb, Header h) ec = rc;; fdo = fdDup(STDOUT_FILENO); if ((qva->qva_flags & VERIFY_SCRIPT) && - (rc = rpmVerifyScript(qva->qva_prefix, h, fdo)) != 0) + (rc = rpmVerifyScript(prefix, h, fdo)) != 0) ec = rc; if (fdo) rc = Fclose(fdo); diff --git a/popt/.lclintrc b/popt/.lclintrc index 81370f681..bf23f75df 100644 --- a/popt/.lclintrc +++ b/popt/.lclintrc @@ -1,4 +1,4 @@ --I. -I.. -DHAVE_CONFIG_H +-I. -I./build -I./lib -I./rpmio -I./popt -DHAVE_CONFIG_H -D_GNU_SOURCE +partial @@ -7,16 +7,17 @@ +unixlib +# XXX ignore doxygen markings +-unrecogcomments + # don't-bother-me-yet parameters -#-branchstate --mustfree +#-branchstate # painful +-mustfree # alloca is painful # not-yet normal parameters -boolops # w->n -#-null -predboolint # w->n --type - +-type # # -weak paramaters #+boolint diff --git a/popt/findme.c b/popt/findme.c index e65762dbc..f8d51bd36 100644 --- a/popt/findme.c +++ b/popt/findme.c @@ -15,14 +15,16 @@ const char * findProgramPath(const char * argv0) { char * start, * chptr; char * buf; + if (argv0 == NULL) return NULL; /* XXX can't happen */ /* If there is a / in the argv[0], it has to be an absolute path */ if (strchr(argv0, '/')) return xstrdup(argv0); - if (!path) return NULL; + if (path == NULL) return NULL; start = pathbuf = alloca(strlen(path) + 1); buf = malloc(strlen(path) + strlen(argv0) + sizeof("/")); + if (buf == NULL) return NULL; /* XXX can't happen */ strcpy(pathbuf, path); chptr = NULL; diff --git a/popt/findme.h b/popt/findme.h index 2fe346d38..1626ee5c6 100644 --- a/popt/findme.h +++ b/popt/findme.h @@ -14,6 +14,6 @@ * @param argv0 name of executable * @return (malloc'd) absolute path to executable (or NULL) */ -/*@null@*/ const char * findProgramPath(const char * argv0); +/*@null@*/ const char * findProgramPath(/*@null@*/ const char * argv0); #endif diff --git a/popt/popt.c b/popt/popt.c index 168c46ef6..169c3a4f4 100644 --- a/popt/popt.c +++ b/popt/popt.c @@ -30,21 +30,26 @@ static char * strerror(int errno) { } #endif -void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) { - if (con->execPath) free((void *)con->execPath); +void poptSetExecPath(poptContext con, const char * path, int allowAbsolute) +{ + con->execPath = _free(con->execPath); con->execPath = xstrdup(path); con->execAbsolute = allowAbsolute; } static void invokeCallbacksPRE(poptContext con, const struct poptOption * opt) { + if (opt != NULL) for (; opt->longName || opt->shortName || opt->arg; opt++) { + if (opt->arg == NULL) continue; /* XXX program error. */ if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { /* Recurse on included sub-tables. */ invokeCallbacksPRE(con, opt->arg); } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK && (opt->argInfo & POPT_CBFLAG_PRE)) - { poptCallbackType cb = (poptCallbackType)opt->arg; + { /*@-castfcnptr@*/ + poptCallbackType cb = (poptCallbackType)opt->arg; + /*@=castfcnptr@*/ /* Perform callback. */ cb(con, POPT_CALLBACK_REASON_PRE, NULL, NULL, opt->descrip); } @@ -53,13 +58,17 @@ static void invokeCallbacksPRE(poptContext con, const struct poptOption * opt) static void invokeCallbacksPOST(poptContext con, const struct poptOption * opt) { + if (opt != NULL) for (; opt->longName || opt->shortName || opt->arg; opt++) { + if (opt->arg == NULL) continue; /* XXX program error. */ if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { /* Recurse on included sub-tables. */ invokeCallbacksPOST(con, opt->arg); } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK && (opt->argInfo & POPT_CBFLAG_POST)) - { poptCallbackType cb = (poptCallbackType)opt->arg; + { /*@-castfcnptr@*/ + poptCallbackType cb = (poptCallbackType)opt->arg; + /*@=castfcnptr@*/ /* Perform callback. */ cb(con, POPT_CALLBACK_REASON_POST, NULL, NULL, opt->descrip); } @@ -69,14 +78,16 @@ static void invokeCallbacksPOST(poptContext con, const struct poptOption * opt) static void invokeCallbacksOPTION(poptContext con, const struct poptOption * opt, const struct poptOption * myOpt, - const void * myData, int shorty) + /*@null@*/ const void * myData, int shorty) { const struct poptOption * cbopt = NULL; + if (opt != NULL) for (; opt->longName || opt->shortName || opt->arg; opt++) { if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { /* Recurse on included sub-tables. */ - invokeCallbacksOPTION(con, opt->arg, myOpt, myData, shorty); + if (opt->arg != NULL) /* XXX program error */ + invokeCallbacksOPTION(con, opt->arg, myOpt, myData, shorty); } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK && !(opt->argInfo & POPT_CBFLAG_SKIPOPTION)) { /* Save callback info. */ @@ -85,12 +96,17 @@ static void invokeCallbacksOPTION(poptContext con, ((myOpt->shortName && opt->shortName && shorty && myOpt->shortName == opt->shortName) || (myOpt->longName && opt->longName && + /*@-nullpass@*/ /* LCL: opt->longName != NULL */ !strcmp(myOpt->longName, opt->longName))) + /*@=nullpass@*/ ) - { poptCallbackType cb = (poptCallbackType)cbopt->arg; + { /*@-castfcnptr@*/ + poptCallbackType cb = (poptCallbackType)cbopt->arg; + /*@=castfcnptr@*/ const void * cbData = (cbopt->descrip ? cbopt->descrip : myData); /* Perform callback. */ - cb(con, POPT_CALLBACK_REASON_OPTION, myOpt, + if (cb != NULL) /* XXX program error */ + cb(con, POPT_CALLBACK_REASON_OPTION, myOpt, con->os->nextArg, cbData); /* Terminate (unless explcitly continuing). */ if (!(cbopt->argInfo & POPT_CBFLAG_CONTINUE)) @@ -104,18 +120,23 @@ poptContext poptGetContext(const char * name, int argc, const char ** argv, { poptContext con = malloc(sizeof(*con)); + if (con == NULL) return NULL; /* XXX can't happen */ memset(con, 0, sizeof(*con)); con->os = con->optionStack; con->os->argc = argc; + /*@-dependenttrans@*/ /* FIX: W2DO? */ con->os->argv = argv; + /*@=dependenttrans@*/ con->os->argb = NULL; if (!(flags & POPT_CONTEXT_KEEP_FIRST)) con->os->next = 1; /* skip argv[0] */ con->leftovers = calloc( (argc + 1), sizeof(char *) ); + /*@-dependenttrans@*/ /* FIX: W2DO? */ con->options = options; + /*@=dependenttrans@*/ con->aliases = NULL; con->numAliases = 0; con->flags = flags; @@ -130,7 +151,9 @@ poptContext poptGetContext(const char * name, int argc, const char ** argv, con->flags |= POPT_CONTEXT_POSIXMEHARDER; if (name) + /*@-nullpass@*/ /* FIX: malloc can return NULL. */ con->appName = strcpy(malloc(strlen(name) + 1), name); + /*@=nullpass@*/ invokeCallbacksPRE(con, con->options); @@ -139,30 +162,20 @@ poptContext poptGetContext(const char * name, int argc, const char ** argv, static void cleanOSE(struct optionStackEntry *os) { - if (os->nextArg) { - free((void *)os->nextArg); - os->nextArg = NULL; - } - if (os->argv) { - free((void *)os->argv); - os->argv = NULL; - } - if (os->argb) { - PBM_FREE(os->argb); - os->argb = NULL; - } + os->nextArg = _free(os->nextArg); + os->argv = _free(os->argv); + os->argb = PBM_FREE(os->argb); } -void poptResetContext(poptContext con) { +void poptResetContext(poptContext con) +{ int i; + if (con == NULL) return; while (con->os > con->optionStack) { cleanOSE(con->os--); } - if (con->os->argb) { - PBM_FREE(con->os->argb); - con->os->argb = NULL; - } + con->os->argb = PBM_FREE(con->os->argb); con->os->currAlias = NULL; con->os->nextCharArg = NULL; con->os->nextArg = NULL; @@ -173,25 +186,27 @@ void poptResetContext(poptContext con) { con->restLeftover = 0; con->doExec = NULL; - for (i = 0; i < con->finalArgvCount; i++) { - if (con->finalArgv[i]) { - free((void *)con->finalArgv[i]); - con->finalArgv[i] = NULL; - } - } + if (con->finalArgv != NULL) + for (i = 0; i < con->finalArgvCount; i++) + /*@-unqualifiedtrans@*/ /* FIX: typedef double indirection. */ + con->finalArgv[i] = _free(con->finalArgv[i]); + /*@=unqualifiedtrans@*/ con->finalArgvCount = 0; - - if (con->arg_strip) { - PBM_FREE(con->arg_strip); - con->arg_strip = NULL; - } + con->arg_strip = PBM_FREE(con->arg_strip); + /*@-nullstate@*/ /* FIX: con->finalArgv != NULL */ + return; + /*@=nullstate@*/ } /* Only one of longName, shortName may be set at a time */ -static int handleExec(poptContext con, char * longName, char shortName) { +static int handleExec(poptContext con, /*@null@*/ const char * longName, + char shortName) +{ int i; + if (con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */ + return 0; i = con->numExecs - 1; if (longName) { while (i >= 0 && (!con->execs[i].longName || @@ -220,29 +235,42 @@ static int handleExec(poptContext con, char * longName, char shortName) { } i = con->finalArgvCount++; + if (con->finalArgv != NULL) /* XXX can't happen */ { char *s = malloc((longName ? strlen(longName) : 0) + 3); - if (longName) - sprintf(s, "--%s", longName); - else - sprintf(s, "-%c", shortName); - con->finalArgv[i] = s; + if (s != NULL) { /* XXX can't happen */ + if (longName) + sprintf(s, "--%s", longName); + else + sprintf(s, "-%c", shortName); + con->finalArgv[i] = s; + } else + con->finalArgv[i] = NULL; } + /*@-nullstate@*/ /* FIX: con->finalArgv[] == NULL */ return 1; + /*@=nullstate@*/ } /* Only one of longName, shortName may be set at a time */ -static int handleAlias(poptContext con, const char * longName, char shortName, - /*@keep@*/ const char * nextCharArg) { +static int handleAlias(poptContext con, + /*@null@*/ const char * longName, char shortName, + /*@keep@*/ /*@null@*/ const char * nextCharArg) +{ + int rc; int i; if (con->os->currAlias && con->os->currAlias->longName && longName && + /*@-nullpass@*/ /* LCL: con->os->currAlias->longName != NULL */ !strcmp(con->os->currAlias->longName, longName)) + /*@=nullpass@*/ return 0; if (con->os->currAlias && shortName && shortName == con->os->currAlias->shortName) return 0; + if (con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */ + return 0; i = con->numAliases - 1; if (longName) { while (i >= 0 && (!con->aliases[i].longName || @@ -266,27 +294,34 @@ static int handleAlias(poptContext con, const char * longName, char shortName, con->os->nextArg = NULL; con->os->nextCharArg = NULL; con->os->currAlias = con->aliases + i; - poptDupArgv(con->os->currAlias->argc, con->os->currAlias->argv, + rc = poptDupArgv(con->os->currAlias->argc, con->os->currAlias->argv, &con->os->argc, &con->os->argv); con->os->argb = NULL; - return 1; + return (rc ? rc : 1); } -static void execCommand(poptContext con) { +static int execCommand(poptContext con) + /*@modifies fileSystem @*/ +{ const char ** argv; int argc = 0; const char ** sargv; int sargc = 0; + int rc; - poptParseArgvString(con->doExec->script, &sargc, &sargv); + if (con->doExec == NULL || con->doExec->script == NULL) /*XXX can't happen*/ + return POPT_ERROR_NOARG; + rc = poptParseArgvString(con->doExec->script, &sargc, &sargv); + if (rc) return rc; if (sargv == NULL || sargc < 1 || (!con->execAbsolute && strchr(sargv[0], '/'))) - return; + return POPT_ERROR_NOARG; argv = malloc(sizeof(*argv) * (6 + sargc + con->numLeftovers + con->finalArgvCount)); + if (argv == NULL) return POPT_ERROR_MALLOC; /* XXX can't happen */ if (!strchr(sargv[0], '/') && con->execPath) { char *s = alloca(strlen(con->execPath) + strlen(sargv[0]) + sizeof("/")); @@ -295,17 +330,20 @@ static void execCommand(poptContext con) { } else { argv[argc] = findProgramPath(sargv[0]); } - if (argv[argc++] == NULL) return; + if (argv[argc++] == NULL) return POPT_ERROR_NOARG; if (sargc > 1) { memcpy(argv + argc, sargv + 1, sizeof(*argv) * (sargc - 1)); argc += (sargc - 1); } - memcpy(argv + argc, con->finalArgv, sizeof(*argv) * con->finalArgvCount); - argc += con->finalArgvCount; + if (con->finalArgv != NULL && con->finalArgvCount > 0) { + memcpy(argv + argc, con->finalArgv, + sizeof(*argv) * con->finalArgvCount); + argc += con->finalArgvCount; + } - if (con->numLeftovers) { + if (con->leftovers != NULL && con->numLeftovers > 0) { argv[argc++] = "--"; memcpy(argv + argc, con->leftovers, sizeof(*argv) * con->numLeftovers); argc += con->numLeftovers; @@ -314,7 +352,7 @@ static void execCommand(poptContext con) { argv[argc++] = NULL; #ifdef __hpux - setresuid(getuid(), getuid(),-1); + (void) setresuid(getuid(), getuid(),-1); #else /* * XXX " ... on BSD systems setuid() should be preferred over setreuid()" @@ -322,16 +360,16 @@ static void execCommand(poptContext con) { * XXX from Norbert Warmuth <nwarmuth@privat.circular.de> */ #if defined(HAVE_SETUID) - setuid(getuid()); + (void) setuid(getuid()); #elif defined (HAVE_SETREUID) - setreuid(getuid(), getuid()); /*hlauer: not portable to hpux9.01 */ + (void) setreuid(getuid(), getuid()); /*hlauer: not portable to hpux9.01 */ #else ; /* Can't drop privileges */ #endif #endif if (argv[0] == NULL) - return; + return POPT_ERROR_NOARG; #ifdef MYDEBUG { const char ** arg; fprintf(stderr, "==> execvp(%s):", argv[0]); @@ -341,19 +379,22 @@ static void execCommand(poptContext con) { } #endif - execvp(argv[0], (char *const *)argv); + (void) execvp(argv[0], (char *const *)argv); + return POPT_ERROR_ERRNO; } -/*@observer@*/ static const struct poptOption * -findOption(const struct poptOption * opt, const char * longName, - char shortName, - /*@out@*/ poptCallbackType * callback, /*@out@*/ const void ** callbackData, - int singleDash) +/*@observer@*/ /*@null@*/ static const struct poptOption * +findOption(const struct poptOption * opt, /*@null@*/ const char * longName, + char shortName, + /*@null@*/ /*@out@*/ poptCallbackType * callback, + /*@null@*/ /*@out@*/ const void ** callbackData, + int singleDash) + /*@modifies *callback, *callbackData */ { const struct poptOption * cb = NULL; /* This happens when a single - is given */ - if (singleDash && !shortName && !*longName) + if (singleDash && !shortName && (longName && *longName == '\0')) shortName = '-'; for (; opt->longName || opt->shortName || opt->arg; opt++) { @@ -361,19 +402,28 @@ findOption(const struct poptOption * opt, const char * longName, if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { const struct poptOption * opt2; /* Recurse on included sub-tables. */ + if (opt->arg == NULL) continue; /* XXX program error */ opt2 = findOption(opt->arg, longName, shortName, callback, callbackData, singleDash); if (opt2) { /* Sub-table data will be inheirited if no data yet. */ - if (*callback && *callbackData == NULL) + /*@-nullderef@*/ /* LCL: *callback != NULL */ + if (callback && *callback && + callbackData && *callbackData == NULL) + /*@-observertrans -dependenttrans @*/ *callbackData = opt->descrip; + /*@=observertrans =dependenttrans @*/ + /*@=nullderef@*/ return opt2; } } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) { cb = opt; } else if (longName && opt->longName && (!singleDash || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) && - !strcmp(longName, opt->longName)) { + /*@-nullpass@*/ /* LCL: opt->longName != NULL */ + !strcmp(longName, opt->longName)) + /*@=nullpass@*/ + { break; } else if (shortName && shortName == opt->shortName) { break; @@ -382,18 +432,28 @@ findOption(const struct poptOption * opt, const char * longName, if (!opt->longName && !opt->shortName) return NULL; - *callbackData = NULL; - *callback = NULL; + /*@-modobserver -mods @*/ + if (callback) *callback = NULL; + if (callbackData) *callbackData = NULL; if (cb) { - *callback = (poptCallbackType)cb->arg; - if (!(cb->argInfo & POPT_CBFLAG_INC_DATA)) - *callbackData = cb->descrip; + if (callback) + /*@-castfcnptr@*/ + *callback = (poptCallbackType)cb->arg; + /*@=castfcnptr@*/ + if (!(cb->argInfo & POPT_CBFLAG_INC_DATA)) { + if (callbackData) + /*@-observertrans@*/ /* FIX: typedef double indirection. */ + *callbackData = cb->descrip; + /*@=observertrans@*/ + } } + /*@=modobserver =mods @*/ return opt; } -static const char *findNextArg(poptContext con, unsigned argx, int delete) +static const char * findNextArg(poptContext con, unsigned argx, int delete) + /*@modifies con @*/ { struct optionStackEntry * os = con->os; const char * arg; @@ -403,6 +463,7 @@ static const char *findNextArg(poptContext con, unsigned argx, int delete) arg = NULL; while (os->next == os->argc && os > con->optionStack) os--; if (os->next == os->argc && os == con->optionStack) break; + if (os->argv != NULL) for (i = os->next; i < os->argc; i++) { if (os->argb && PBM_ISSET(i, os->argb)) continue; if (*os->argv[i] == '-') continue; @@ -410,16 +471,21 @@ static const char *findNextArg(poptContext con, unsigned argx, int delete) arg = os->argv[i]; if (delete) { if (os->argb == NULL) os->argb = PBM_ALLOC(os->argc); + if (os->argb != NULL) /* XXX can't happen */ PBM_SET(i, os->argb); } break; } if (os > con->optionStack) os--; } while (arg == NULL); + /*@-compdef@*/ /* FIX: con->os->argv undefined */ return arg; + /*@=compdef@*/ } -static /*@only@*/ const char * expandNextArg(poptContext con, const char * s) +static /*@only@*/ /*@null@*/ const char * +expandNextArg(poptContext con, const char * s) + /*@modifies con @*/ { const char *a; size_t alen; @@ -428,6 +494,7 @@ static /*@only@*/ const char * expandNextArg(poptContext con, const char * s) char c; te = t = malloc(tn);; + if (t == NULL) return NULL; /* XXX can't happen */ while ((c = *s++) != '\0') { switch (c) { #if 0 /* XXX can't do this */ @@ -456,7 +523,7 @@ static /*@only@*/ const char * expandNextArg(poptContext con, const char * s) *te++ = c; } *te = '\0'; - t = realloc(t, strlen(t)+1); /* XXX memory leak, hard to plug */ + t = realloc(t, strlen(t) + 1); /* XXX memory leak, hard to plug */ return t; } @@ -464,10 +531,15 @@ static void poptStripArg(poptContext con, int which) { if (con->arg_strip == NULL) con->arg_strip = PBM_ALLOC(con->optionStack[0].argc); + if (con->arg_strip != NULL) /* XXX can't happen */ PBM_SET(which, con->arg_strip); } -static int poptSaveLong(const struct poptOption * opt, long aLong) { +static int poptSaveLong(const struct poptOption * opt, long aLong) +{ + if (opt->arg == NULL) + return POPT_ERROR_NULLARG; + if (opt->argInfo & POPT_ARGFLAG_NOT) aLong = ~aLong; switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) { @@ -485,12 +557,16 @@ static int poptSaveLong(const struct poptOption * opt, long aLong) { break; default: return POPT_ERROR_BADOPERATION; - break; + /*@notreached@*/ break; } return 0; } -static int poptSaveInt(const struct poptOption * opt, long aLong) { +static int poptSaveInt(const struct poptOption * opt, long aLong) +{ + if (opt->arg == NULL) + return POPT_ERROR_NULLARG; + if (opt->argInfo & POPT_ARGFLAG_NOT) aLong = ~aLong; switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) { @@ -508,7 +584,7 @@ static int poptSaveInt(const struct poptOption * opt, long aLong) { break; default: return POPT_ERROR_BADOPERATION; - break; + /*@notreached@*/ break; } return 0; } @@ -533,6 +609,8 @@ int poptGetNextOpt(poptContext con) const struct poptOption * opt = NULL; int done = 0; + if (con == NULL) + return -1; while (!done) { const char * origOptString = NULL; poptCallbackType cb = NULL; @@ -547,7 +625,7 @@ int poptGetNextOpt(poptContext con) } if (!con->os->nextCharArg && con->os->next == con->os->argc) { invokeCallbacksPOST(con, con->options); - if (con->doExec) execCommand(con); + if (con->doExec) return execCommand(con); return -1; } @@ -561,9 +639,14 @@ int poptGetNextOpt(poptContext con) continue; } thisopt = con->os->next; + if (con->os->argv != NULL) /* XXX can't happen */ origOptString = con->os->argv[con->os->next++]; + if (origOptString == NULL) /* XXX can't happen */ + return POPT_ERROR_BADOPT; + if (con->restLeftover || *origOptString != '-') { + if (con->leftovers != NULL) /* XXX can't happen */ con->leftovers[con->numLeftovers++] = origOptString; if (con->flags & POPT_CONTEXT_POSIXMEHARDER) con->restLeftover = 1; @@ -572,10 +655,9 @@ int poptGetNextOpt(poptContext con) /* Make a copy we can hack at */ localOptString = optString = - strcpy(alloca(strlen(origOptString) + 1), - origOptString); + strcpy(alloca(strlen(origOptString) + 1), origOptString); - if (!optString[0]) + if (optString[0] == '\0') return POPT_ERROR_BADOPT; if (optString[1] == '-' && !optString[2]) { @@ -626,6 +708,7 @@ int poptGetNextOpt(poptContext con) /* Process next short option */ if (con->os->nextCharArg) { + /*@-branchstate@*/ /* FIX: W2DO? */ origOptString = con->os->nextCharArg; con->os->nextCharArg = NULL; @@ -637,7 +720,8 @@ int poptGetNextOpt(poptContext con) if (handleExec(con, NULL, *origOptString)) { /* Restore rest of short options for further processing */ origOptString++; - if (*origOptString) con->os->nextCharArg = origOptString; + if (*origOptString != '\0') + con->os->nextCharArg = origOptString; continue; } @@ -648,9 +732,12 @@ int poptGetNextOpt(poptContext con) shorty = 1; origOptString++; - if (*origOptString) con->os->nextCharArg = origOptString; + if (*origOptString != '\0') + con->os->nextCharArg = origOptString; + /*@=branchstate@*/ } + if (opt == NULL) return POPT_ERROR_BADOPT; /* XXX can't happen */ if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) { if (poptSaveInt(opt, 1L)) return POPT_ERROR_BADOPERATION; @@ -660,14 +747,17 @@ int poptGetNextOpt(poptContext con) return POPT_ERROR_BADOPERATION; } } else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) { - if (con->os->nextArg) { - free((void *)con->os->nextArg); - con->os->nextArg = NULL; - } + con->os->nextArg = _free(con->os->nextArg); + /*@-usedef@*/ /* FIX: W2DO? */ if (longArg) { + /*@=usedef@*/ + /*@-evalorder@*/ /* FIX: W2DO? */ con->os->nextArg = expandNextArg(con, longArg); + /*@=evalorder@*/ } else if (con->os->nextCharArg) { + /*@-evalorder@*/ /* FIX: W2DO? */ con->os->nextArg = expandNextArg(con, con->os->nextCharArg); + /*@=evalorder@*/ con->os->nextCharArg = NULL; } else { while (con->os->next == con->os->argc && @@ -689,7 +779,11 @@ int poptGetNextOpt(poptContext con) poptStripArg(con, con->os->next); } - con->os->nextArg = expandNextArg(con, con->os->argv[con->os->next++]); + if (con->os->argv != NULL) /* XXX can't happen */ + /*@-evalorder@*/ /* FIX: W2DO? */ + con->os->nextArg = + expandNextArg(con, con->os->argv[con->os->next++]); + /*@=evalorder@*/ } } @@ -732,24 +826,21 @@ int poptGetNextOpt(poptContext con) if (con->os->nextArg) { aDouble = strtod(con->os->nextArg, &end); - if (*end) + if (*end != '\0') return POPT_ERROR_BADNUMBER; } - if (aDouble == +HUGE_VAL || aDouble == -HUGE_VAL) + if ((aDouble - HUGE_VAL) < DBL_EPSILON || + (aDouble + HUGE_VAL) < DBL_EPSILON) return POPT_ERROR_OVERFLOW; - if (aDouble == 0.0 && errno == ERANGE) + if ((aDouble - 0.0) < DBL_EPSILON && errno == ERANGE) return POPT_ERROR_OVERFLOW; if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_DOUBLE) { *((double *) opt->arg) = aDouble; } else { -#ifdef ABS -#undef ABS -#endif -#define ABS(a) (((a) < 0) ? -(a) : (a)) - if (ABS(aDouble) > FLT_MAX) + if ((aDouble - FLT_MAX) > DBL_EPSILON) return POPT_ERROR_OVERFLOW; - if (ABS(aDouble) < FLT_MIN) + if ((aDouble + FLT_MIN) > DBL_EPSILON) return POPT_ERROR_OVERFLOW; *((float *) opt->arg) = aDouble; } @@ -773,83 +864,107 @@ int poptGetNextOpt(poptContext con) sizeof(*con->finalArgv) * con->finalArgvAlloced); } + if (con->finalArgv != NULL) { char *s = malloc((opt->longName ? strlen(opt->longName) : 0) + 3); - if (opt->longName) - sprintf(s, "%s%s", - ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"), - opt->longName); - else - sprintf(s, "-%c", opt->shortName); - con->finalArgv[con->finalArgvCount++] = s; + if (s != NULL) { /* XXX can't happen */ + if (opt->longName) + sprintf(s, "%s%s", + ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"), + opt->longName); + else + sprintf(s, "-%c", opt->shortName); + con->finalArgv[con->finalArgvCount++] = s; + } else + con->finalArgv[con->finalArgvCount++] = NULL; } if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) - /*@-ifempty@*/ ; + /*@-ifempty@*/ ; /*@=ifempty@*/ else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) - /*@-ifempty@*/ ; + /*@-ifempty@*/ ; /*@=ifempty@*/ else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) { - if (con->os->nextArg) + if (con->finalArgv != NULL && con->os->nextArg) con->finalArgv[con->finalArgvCount++] = + /*@-nullpass@*/ /* LCL: con->os->nextArg != NULL */ xstrdup(con->os->nextArg); + /*@=nullpass@*/ } } - return opt->val; + return (opt ? opt->val : -1); /* XXX can't happen */ } -const char * poptGetOptArg(poptContext con) { - const char * ret = con->os->nextArg; - con->os->nextArg = NULL; +const char * poptGetOptArg(poptContext con) +{ + const char * ret = NULL; + if (con) { + ret = con->os->nextArg; + con->os->nextArg = NULL; + } return ret; } -const char * poptGetArg(poptContext con) { - const char * ret = (con->nextLeftover < con->numLeftovers) - ? con->leftovers[con->nextLeftover++] : NULL; +const char * poptGetArg(poptContext con) +{ + const char * ret = NULL; + if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers) + ret = con->leftovers[con->nextLeftover++]; return ret; } -const char * poptPeekArg(poptContext con) { - const char * ret = (con->nextLeftover < con->numLeftovers) - ? con->leftovers[con->nextLeftover] : NULL; +const char * poptPeekArg(poptContext con) +{ + const char * ret = NULL; + if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers) + ret = con->leftovers[con->nextLeftover]; return ret; } -const char ** poptGetArgs(poptContext con) { - if (con->numLeftovers == con->nextLeftover) return NULL; +const char ** poptGetArgs(poptContext con) +{ + if (con == NULL || + con->leftovers == NULL || con->numLeftovers == con->nextLeftover) + return NULL; /* some apps like [like RPM ;-) ] need this NULL terminated */ con->leftovers[con->numLeftovers] = NULL; + /*@-nullret -nullstate @*/ /* FIX: typedef double indirection. */ return (con->leftovers + con->nextLeftover); + /*@=nullret =nullstate @*/ } -void poptFreeContext(poptContext con) { +poptContext poptFreeContext(poptContext con) +{ int i; + if (con == NULL) return con; poptResetContext(con); - if (con->os->argb) free(con->os->argb); + con->os->argb = _free(con->os->argb); + if (con->aliases != NULL) for (i = 0; i < con->numAliases; i++) { - if (con->aliases[i].longName) free((void *)con->aliases[i].longName); - free(con->aliases[i].argv); + con->aliases[i].longName = _free(con->aliases[i].longName); + con->aliases[i].argv = _free(con->aliases[i].argv); } + if (con->execs != NULL) for (i = 0; i < con->numExecs; i++) { - if (con->execs[i].longName) free((void *)con->execs[i].longName); - free((void *)con->execs[i].script); + con->execs[i].longName = _free(con->execs[i].longName); + con->execs[i].script = _free(con->execs[i].script); } - if (con->execs) free((void *)con->execs); - - free(con->leftovers); - free(con->finalArgv); - if (con->appName) free((void *)con->appName); - if (con->aliases) free(con->aliases); - if (con->otherHelp) free((void *)con->otherHelp); - if (con->execPath) free((void *)con->execPath); - if (con->arg_strip) PBM_FREE(con->arg_strip); + con->execs = _free(con->execs); + + con->leftovers = _free(con->leftovers); + con->finalArgv = _free(con->finalArgv); + con->appName = _free(con->appName); + con->aliases = _free(con->aliases); + con->otherHelp = _free(con->otherHelp); + con->execPath = _free(con->execPath); + con->arg_strip = PBM_FREE(con->arg_strip); - free(con); + con = _free(con); + return con; } int poptAddAlias(poptContext con, struct poptAlias newAlias, @@ -867,7 +982,9 @@ int poptAddAlias(poptContext con, struct poptAlias newAlias, alias = con->aliases + aliasNum; alias->longName = (newAlias.longName) + /*@-nullpass@*/ /* FIX: malloc can return NULL. */ ? strcpy(malloc(strlen(newAlias.longName) + 1), newAlias.longName) + /*@=nullpass@*/ : NULL; alias->shortName = newAlias.shortName; alias->argc = newAlias.argc; @@ -876,18 +993,20 @@ int poptAddAlias(poptContext con, struct poptAlias newAlias, return 0; } -const char * poptBadOption(poptContext con, int flags) { - struct optionStackEntry * os; +const char * poptBadOption(poptContext con, int flags) +{ + struct optionStackEntry * os = NULL; - if (flags & POPT_BADOPTION_NOALIAS) - os = con->optionStack; - else - os = con->os; + if (con != NULL) + os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os; - return os->argv[os->next - 1]; + /*@-nullderef@*/ /* LCL: os->argv != NULL */ + return (os && os->argv ? os->argv[os->next - 1] : NULL); + /*@=nullderef@*/ } -const char *const poptStrerror(const int error) { +const char *const poptStrerror(const int error) +{ switch (error) { case POPT_ERROR_NOARG: return POPT_("missing argument"); @@ -895,6 +1014,8 @@ const char *const poptStrerror(const int error) { return POPT_("unknown option"); case POPT_ERROR_BADOPERATION: return POPT_("mutually exclusive logical operations requested"); + case POPT_ERROR_NULLARG: + return POPT_("opt->arg should not be NULL"); case POPT_ERROR_OPTSTOODEEP: return POPT_("aliases nested too deeply"); case POPT_ERROR_BADQUOTE: @@ -903,6 +1024,8 @@ const char *const poptStrerror(const int error) { return POPT_("invalid numeric value"); case POPT_ERROR_OVERFLOW: return POPT_("number too large or too small"); + case POPT_ERROR_MALLOC: + return POPT_("memory allocation failed"); case POPT_ERROR_ERRNO: return strerror(errno); default: @@ -910,8 +1033,10 @@ const char *const poptStrerror(const int error) { } } -int poptStuffArgs(poptContext con, const char ** argv) { +int poptStuffArgs(poptContext con, const char ** argv) +{ int argc; + int rc; if ((con->os - con->optionStack) == POPT_OPTION_DEPTH) return POPT_ERROR_OPTSTOODEEP; @@ -924,30 +1049,34 @@ int poptStuffArgs(poptContext con, const char ** argv) { con->os->nextArg = NULL; con->os->nextCharArg = NULL; con->os->currAlias = NULL; - poptDupArgv(argc, argv, &con->os->argc, &con->os->argv); + rc = poptDupArgv(argc, argv, &con->os->argc, &con->os->argv); con->os->argb = NULL; con->os->stuffed = 1; - return 0; + return rc; } -const char * poptGetInvocationName(poptContext con) { - return con->os->argv[0]; +const char * poptGetInvocationName(poptContext con) +{ + return (con->os->argv ? con->os->argv[0] : ""); } -int poptStrippedArgv(poptContext con, int argc, char **argv) +int poptStrippedArgv(poptContext con, int argc, char ** argv) { - int i,j=1, numargs=argc; + int numargs = argc; + int j = 1; + int i; + if (con->arg_strip) for (i = 1; i < argc; i++) { if (PBM_ISSET(i, con->arg_strip)) numargs--; } for (i = 1; i < argc; i++) { - if (PBM_ISSET(i, con->arg_strip)) + if (con->arg_strip && PBM_ISSET(i, con->arg_strip)) continue; - argv[j] = (j < numargs) ? argv[i] : '\0'; + argv[j] = (j < numargs) ? argv[i] : NULL; j++; } diff --git a/popt/popt.h b/popt/popt.h index 70bb40869..b74f7d8c0 100644 --- a/popt/popt.h +++ b/popt/popt.h @@ -84,6 +84,8 @@ extern "C" { #define POPT_ERROR_BADNUMBER -17 /*!< invalid numeric value */ #define POPT_ERROR_OVERFLOW -18 /*!< number too large or too small */ #define POPT_ERROR_BADOPERATION -19 /*!< mutually exclusive logical operations requested */ +#define POPT_ERROR_NULLARG -20 /*!< opt->arg should not be NULL */ +#define POPT_ERROR_MALLOC -21 /*!< memory allocation failed */ /*@}*/ /** \ingroup popt @@ -110,8 +112,8 @@ struct poptOption { int argInfo; /*@shared@*/ /*@null@*/ void * arg; /*!< depends on argInfo */ int val; /*!< 0 means don't return, just update flag */ -/*@shared@*/ /*@null@*/ const char * descrip; /*!< description for autohelp -- may be NULL */ -/*@shared@*/ /*@null@*/ const char * argDescrip; /*!< argument description for autohelp */ +/*@observer@*/ /*@null@*/ const char * descrip; /*!< description for autohelp -- may be NULL */ +/*@observer@*/ /*@null@*/ const char * argDescrip; /*!< argument description for autohelp */ }; /** \ingroup popt @@ -135,7 +137,7 @@ extern struct poptOption poptHelpOptions[]; /** \ingroup popt */ -typedef struct poptContext_s * poptContext; +typedef /*@abstract@*/ struct poptContext_s * poptContext; /** \ingroup popt */ @@ -156,9 +158,10 @@ enum poptCallbackReason { POPT_CALLBACK_REASON_PRE, * @param data @todo Document. */ typedef void (*poptCallbackType) (poptContext con, - enum poptCallbackReason reason, - const struct poptOption * opt, - const char * arg, const void * data); + enum poptCallbackReason reason, + /*@null@*/ const struct poptOption * opt, + /*@null@*/ const char * arg, + /*@null@*/ const void * data); /** \ingroup popt * Initialize popt context. @@ -169,7 +172,7 @@ typedef void (*poptCallbackType) (poptContext con, * @param flags or'd POPT_CONTEXT_* bits * @return initialized popt context */ -/*@only@*/ poptContext poptGetContext( +/*@only@*/ /*@null@*/ poptContext poptGetContext( /*@dependent@*/ /*@keep@*/ const char * name, int argc, /*@dependent@*/ /*@keep@*/ const char ** argv, /*@dependent@*/ /*@keep@*/ const struct poptOption * options, @@ -179,54 +182,55 @@ typedef void (*poptCallbackType) (poptContext con, * Reinitialize popt context. * @param con context */ -void poptResetContext(poptContext con); +void poptResetContext(/*@null@*/poptContext con); /** \ingroup popt * Return value of next option found. * @param con context * @return next option val, -1 on last item, POPT_ERROR_* on error */ -int poptGetNextOpt(poptContext con); +int poptGetNextOpt(/*@null@*/poptContext con); /* returns NULL if no argument is available */ /** \ingroup popt * @param con context */ -/*@observer@*/ /*@null@*/ const char * poptGetOptArg(poptContext con); +/*@observer@*/ /*@null@*/ const char * poptGetOptArg(/*@null@*/poptContext con); /** \ingroup popt * Return current option's argument. * @param con context * @return option argument, NULL if no more options are available */ -/*@observer@*/ /*@null@*/ const char * poptGetArg(poptContext con); +/*@observer@*/ /*@null@*/ const char * poptGetArg(/*@null@*/poptContext con); /** \ingroup popt * Peek at current option's argument. * @param con context * @return option argument */ -/*@observer@*/ /*@null@*/ const char * poptPeekArg(poptContext con); +/*@observer@*/ /*@null@*/ const char * poptPeekArg(/*@null@*/poptContext con); /** \ingroup popt * Return remaining arguments. * @param con context * @return argument array, terminated with NULL */ -/*@observer@*/ /*@null@*/ const char ** poptGetArgs(poptContext con); +/*@observer@*/ /*@null@*/ const char ** poptGetArgs(/*@null@*/poptContext con); /** \ingroup popt * Return the option which caused the most recent error. * @param con context * @return offending option */ -/*@observer@*/ const char * poptBadOption(poptContext con, int flags); +/*@observer@*/ const char * poptBadOption(/*@null@*/poptContext con, int flags); /** \ingroup popt * Destroy context. * @param con context + * @return NULL */ -void poptFreeContext( /*@only@*/ poptContext con); +/*@null@*/ poptContext poptFreeContext( /*@only@*/ /*@null@*/ poptContext con); /** \ingroup popt * Add arguments to context. @@ -252,7 +256,9 @@ int poptAddAlias(poptContext con, struct poptAlias alias, int flags); * @param fn file name to read * @return 0 on success, POPT_ERROR_ERRNO on failure */ -int poptReadConfigFile(poptContext con, const char * fn); +int poptReadConfigFile(poptContext con, const char * fn) + /*@modifies fileSystem, + con->execs, con->numExecs @*/; /** \ingroup popt * Read default configuration from /etc/popt and $HOME/.popt. @@ -260,7 +266,9 @@ int poptReadConfigFile(poptContext con, const char * fn); * @param useEnv (unused) * @return 0 on success, POPT_ERROR_ERRNO on failure */ -int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv); +int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv) + /*@modifies fileSystem, + con->execs, con->numExecs @*/; /** \ingroup popt * Duplicate an argument array. @@ -273,8 +281,10 @@ int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv); * @retval argvPtr address of returned argument array * @return 0 on success, POPT_ERROR_NOARG on failure */ -int poptDupArgv(int argc, const char **argv, - /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr); +int poptDupArgv(int argc, /*@null@*/ const char **argv, + /*@null@*/ /*@out@*/ int * argcPtr, + /*@null@*/ /*@out@*/ const char *** argvPtr) + /*@modifies *argcPtr, *argvPtr @*/; /** \ingroup popt * Parse a string into an argument array. @@ -288,14 +298,16 @@ int poptDupArgv(int argc, const char **argv, * @retval argvPtr address of returned argument array */ int poptParseArgvString(const char * s, - /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr); + /*@out@*/ int * argcPtr, /*@out@*/ const char *** argvPtr) + /*@modifies *argcPtr, *argvPtr @*/; /** \ingroup popt * Return formatted error string for popt failure. * @param error popt error * @return error string */ -/*@observer@*/ const char *const poptStrerror(const int error); +/*@observer@*/ const char *const poptStrerror(const int error) + /*@*/; /** \ingroup popt * Limit search for executables. @@ -339,7 +351,7 @@ void poptSetOtherOptionHelp(poptContext con, const char * text); * @param con context * @return new argc */ -int poptStrippedArgv(poptContext con, int argc, char **argv); +int poptStrippedArgv(poptContext con, int argc, char ** argv); #ifdef __cplusplus } diff --git a/popt/poptconfig.c b/popt/poptconfig.c index 0cfd1a1db..d5186468b 100644 --- a/popt/poptconfig.c +++ b/popt/poptconfig.c @@ -9,30 +9,33 @@ #include "system.h" #include "poptint.h" -static void configLine(poptContext con, char * line) { +static void configLine(poptContext con, char * line) + /*@modifies *line, + con->execs, con->numExecs @*/ +{ int nameLength = strlen(con->appName); - char * opt; + const char * opt; struct poptAlias alias; - char * entryType; - char * longName = NULL; + const char * entryType; + const char * longName = NULL; char shortName = '\0'; if (strncmp(line, con->appName, nameLength)) return; line += nameLength; - if (!*line || !isspace(*line)) return; - while (*line && isspace(*line)) line++; + if (*line == '\0' || !isspace(*line)) return; + while (*line != '\0' && isspace(*line)) line++; entryType = line; - while (!*line || !isspace(*line)) line++; + while (*line == '\0' || !isspace(*line)) line++; *line++ = '\0'; - while (*line && isspace(*line)) line++; - if (!*line) return; + while (*line != '\0' && isspace(*line)) line++; + if (*line == '\0') return; opt = line; - while (!*line || !isspace(*line)) line++; + while (*line == '\0' || !isspace(*line)) line++; *line++ = '\0'; - while (*line && isspace(*line)) line++; - if (!*line) return; + while (*line != '\0' && isspace(*line)) line++; + if (*line == '\0') return; if (opt[0] == '-' && opt[1] == '-') longName = opt + 2; @@ -42,10 +45,11 @@ static void configLine(poptContext con, char * line) { if (!strcmp(entryType, "alias")) { if (poptParseArgvString(line, &alias.argc, &alias.argv)) return; alias.longName = longName, alias.shortName = shortName; - poptAddAlias(con, alias, 0); + (void) poptAddAlias(con, alias, 0); } else if (!strcmp(entryType, "exec")) { con->execs = realloc(con->execs, sizeof(*con->execs) * (con->numExecs + 1)); + if (con->execs == NULL) return; /* XXX can't happen */ if (longName) con->execs[con->numExecs].longName = xstrdup(longName); else @@ -54,13 +58,17 @@ static void configLine(poptContext con, char * line) { con->execs[con->numExecs].shortName = shortName; con->execs[con->numExecs].script = xstrdup(line); + /*@-noeffect@*/ /* LCL: broken? */ con->numExecs++; + /*@=noeffect@*/ } } -int poptReadConfigFile(poptContext con, const char * fn) { - char * file, * chptr, * end; - char * buf, * dst; +int poptReadConfigFile(poptContext con, const char * fn) +{ + const char * file, * chptr, * end; + char * buf; +/*@dependent@*/ char * dst; int fd, rc; int fileLength; @@ -76,27 +84,27 @@ int poptReadConfigFile(poptContext con, const char * fn) { (void) lseek(fd, 0, 0); file = alloca(fileLength + 1); - if (read(fd, file, fileLength) != fileLength) { + if (read(fd, (char *)file, fileLength) != fileLength) { rc = errno; - close(fd); + (void) close(fd); errno = rc; return POPT_ERROR_ERRNO; } - close(fd); + (void) close(fd); dst = buf = alloca(fileLength + 1); chptr = file; end = (file + fileLength); + /*@-infloops@*/ /* LCL: can't detect chptr++ */ while (chptr < end) { switch (*chptr) { case '\n': *dst = '\0'; dst = buf; while (*dst && isspace(*dst)) dst++; - if (*dst && *dst != '#') { + if (*dst && *dst != '#') configLine(con, dst); - } chptr++; break; case '\\': @@ -114,6 +122,7 @@ int poptReadConfigFile(poptContext con, const char * fn) { break; } } + /*@=infloops@*/ return 0; } @@ -138,4 +147,3 @@ int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv) { return 0; } - diff --git a/popt/popthelp.c b/popt/popthelp.c index a76b03cdf..086cd4300 100644 --- a/popt/popthelp.c +++ b/popt/popthelp.c @@ -23,31 +23,33 @@ static void displayArgs(poptContext con, exit(0); } +/*@-castfcnptr@*/ struct poptOption poptHelpOptions[] = { { NULL, '\0', POPT_ARG_CALLBACK, (void *)&displayArgs, '\0', NULL, NULL }, { "help", '?', 0, NULL, '?', N_("Show this help message"), NULL }, { "usage", '\0', 0, NULL, 'u', N_("Display brief usage message"), NULL }, POPT_TABLEEND } ; - +/*@=castfcnptr@*/ /*@observer@*/ /*@null@*/ static const char *const -getTableTranslationDomain(const struct poptOption *table) +getTableTranslationDomain(/*@null@*/ const struct poptOption *table) { - const struct poptOption *opt; - - for(opt = table; - opt->longName || opt->shortName || opt->arg; - opt++) { - if(opt->argInfo == POPT_ARG_INTL_DOMAIN) - return opt->arg; - } + const struct poptOption *opt; - return NULL; + if (table != NULL) + for (opt = table; opt->longName || opt->shortName || opt->arg; opt++) { + if (opt->argInfo == POPT_ARG_INTL_DOMAIN) + return opt->arg; + } + return NULL; } /*@observer@*/ /*@null@*/ static const char *const -getArgDescrip(const struct poptOption * opt, const char *translation_domain) +getArgDescrip(const struct poptOption * opt, + /*@-paramuse@*/ /* FIX: wazzup? */ + /*@null@*/ const char * translation_domain) + /*@=paramuse@*/ { if (!(opt->argInfo & POPT_ARG_MASK)) return NULL; @@ -69,8 +71,8 @@ getArgDescrip(const struct poptOption * opt, const char *translation_domain) } static void singleOptionHelp(FILE * f, int maxLeftCol, - const struct poptOption * opt, - const char *translation_domain) + const struct poptOption * opt, + /*@null@*/ const char *translation_domain) { int indentLength = maxLeftCol + 5; int lineLength = 79 - indentLength; @@ -85,13 +87,15 @@ static void singleOptionHelp(FILE * f, int maxLeftCol, if (argDescrip) nb += strlen(argDescrip); left = malloc(nb); - left[0] = left[maxLeftCol] = '\0'; + if (left == NULL) return; /* XXX can't happen */ + left[0] = '\0'; + left[maxLeftCol] = '\0'; if (opt->longName && opt->shortName) sprintf(left, "-%c, %s%s", opt->shortName, ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"), opt->longName); - else if (opt->shortName) + else if (opt->shortName != '\0') sprintf(left, "-%c", opt->shortName); else if (opt->longName) sprintf(left, "%s%s", @@ -113,11 +117,11 @@ static void singleOptionHelp(FILE * f, int maxLeftCol, if (opt->argInfo & POPT_ARGFLAG_NOT) aLong = ~aLong; switch (opt->argInfo & POPT_ARGFLAG_LOGICALOPS) { case POPT_ARGFLAG_OR: - sprintf(le, "[|=0x%lx]", aLong); break; + sprintf(le, "[|=0x%lx]", (unsigned long)aLong); break; case POPT_ARGFLAG_AND: - sprintf(le, "[&=0x%lx]", aLong); break; + sprintf(le, "[&=0x%lx]", (unsigned long)aLong); break; case POPT_ARGFLAG_XOR: - sprintf(le, "[^=0x%lx]", aLong); break; + sprintf(le, "[^=0x%lx]", (unsigned long)aLong); break; default: if (!(aLong == 0L || aLong == 1L || aLong == -1L)) sprintf(le, "[=%ld]", aLong); @@ -173,20 +177,22 @@ out: } static int maxArgWidth(const struct poptOption * opt, - const char * translation_domain) + /*@null@*/ const char * translation_domain) { int max = 0; - int this; + int this = 0; const char * s; + if (opt != NULL) while (opt->longName || opt->shortName || opt->arg) { if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { + if (opt->arg) /* XXX program error */ this = maxArgWidth(opt->arg, translation_domain); if (this > max) max = this; } else if (!(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) { this = sizeof(" ")-1; - if (opt->shortName) this += sizeof("-X")-1; - if (opt->shortName && opt->longName) this += sizeof(", ")-1; + if (opt->shortName != '\0') this += sizeof("-X")-1; + if (opt->shortName != '\0' && opt->longName) this += sizeof(", ")-1; if (opt->longName) { this += ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? sizeof("-")-1 : sizeof("--")-1); @@ -206,23 +212,25 @@ static int maxArgWidth(const struct poptOption * opt, return max; } -static void singleTableHelp(FILE * f, const struct poptOption * table, - int left, - const char *translation_domain) +static void singleTableHelp(FILE * f, + /*@null@*/ const struct poptOption * table, int left, + /*@null@*/ const char * translation_domain) { const struct poptOption * opt; const char *sub_transdom; + if (table != NULL) for (opt = table; (opt->longName || opt->shortName || opt->arg); opt++) { if ((opt->longName || opt->shortName) && !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) singleOptionHelp(f, left, opt, translation_domain); } + if (table != NULL) for (opt = table; (opt->longName || opt->shortName || opt->arg); opt++) { if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { sub_transdom = getTableTranslationDomain(opt->arg); - if(!sub_transdom) + if (sub_transdom == NULL) sub_transdom = translation_domain; if (opt->descrip) @@ -240,7 +248,10 @@ static int showHelpIntro(poptContext con, FILE * f) fprintf(f, POPT_("Usage:")); if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) { + /*@-nullderef@*/ /* LCL: wazzup? */ fn = con->optionStack->argv[0]; + /*@=nullderef@*/ + if (fn == NULL) return len; if (strchr(fn, '/')) fn = strrchr(fn, '/') + 1; fprintf(f, " %s", fn); len += strlen(fn) + 1; @@ -253,7 +264,7 @@ void poptPrintHelp(poptContext con, FILE * f, /*@unused@*/ int flags) { int leftColWidth; - showHelpIntro(con, f); + (void) showHelpIntro(con, f); if (con->otherHelp) fprintf(f, " %s\n", con->otherHelp); else @@ -264,15 +275,15 @@ void poptPrintHelp(poptContext con, FILE * f, /*@unused@*/ int flags) } static int singleOptionUsage(FILE * f, int cursor, - const struct poptOption * opt, - const char *translation_domain) + const struct poptOption * opt, + /*@null@*/ const char *translation_domain) { int len = 3; char shortStr[2] = { '\0', '\0' }; const char * item = shortStr; const char * argDescrip = getArgDescrip(opt, translation_domain); - if (opt->shortName) { + if (opt->shortName!= '\0' ) { if (!(opt->argInfo & POPT_ARG_MASK)) return cursor; /* we did these already */ len++; @@ -296,47 +307,57 @@ static int singleOptionUsage(FILE * f, int cursor, fprintf(f, " [-%s%s%s%s]", ((opt->shortName || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) ? "" : "-"), item, - (argDescrip ? (opt->shortName ? " " : "=") : ""), + (argDescrip ? (opt->shortName != '\0' ? " " : "=") : ""), (argDescrip ? argDescrip : "")); return cursor + len + 1; } -static int singleTableUsage(FILE * f, int cursor, - const struct poptOption * opt, const char * translation_domain) +static int singleTableUsage(FILE * f, + int cursor, const struct poptOption * opt, + /*@null@*/ const char * translation_domain) { + /*@-branchstate@*/ /* FIX: W2DO? */ + if (opt != NULL) for (; (opt->longName || opt->shortName || opt->arg) ; opt++) { - if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) + if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) { translation_domain = (const char *)opt->arg; - else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) + } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { + if (opt->arg) /* XXX program error */ cursor = singleTableUsage(f, cursor, opt->arg, translation_domain); - else if ((opt->longName || opt->shortName) && - !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) + } else if ((opt->longName || opt->shortName) && + !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) { cursor = singleOptionUsage(f, cursor, opt, translation_domain); + } } + /*@=branchstate@*/ return cursor; } -static int showShortOptions(const struct poptOption * opt, FILE * f, char * str) +static int showShortOptions(const struct poptOption * opt, FILE * f, + /*@null@*/ char * str) { - char s[300]; /* this is larger then the ascii set, so - it should do just fine */ + char * s = alloca(300); /* larger then the ascii set */ s[0] = '\0'; + /*@-branchstate@*/ /* FIX: W2DO? */ if (str == NULL) { memset(s, 0, sizeof(s)); str = s; } + /*@=branchstate@*/ + if (opt != NULL) for (; (opt->longName || opt->shortName || opt->arg); opt++) { if (opt->shortName && !(opt->argInfo & POPT_ARG_MASK)) str[strlen(str)] = opt->shortName; else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) - showShortOptions(opt->arg, f, str); + if (opt->arg) /* XXX program error */ + (void) showShortOptions(opt->arg, f, str); } - if (s != str || !*s) + if (s != str || *s != '\0') return 0; fprintf(f, " [-%s]", s); @@ -349,7 +370,7 @@ void poptPrintUsage(poptContext con, FILE * f, /*@unused@*/ int flags) cursor = showHelpIntro(con, f); cursor += showShortOptions(con->options, f, NULL); - singleTableUsage(f, cursor, con->options, NULL); + (void) singleTableUsage(f, cursor, con->options, NULL); if (con->otherHelp) { cursor += strlen(con->otherHelp) + 1; diff --git a/popt/poptint.h b/popt/poptint.h index 066e14312..3a3ee9be5 100644 --- a/popt/poptint.h +++ b/popt/poptint.h @@ -9,6 +9,16 @@ #ifndef H_POPTINT #define H_POPTINT +/** + * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. + * @param this memory to free + * @retval NULL always + */ +/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { + if (this != NULL) free((void *)this); + return NULL; +} + /* Bit mask macros. */ typedef unsigned int __pbm_bits; #define __PBM_NBITS (8 * sizeof (__pbm_bits)) @@ -20,50 +30,50 @@ typedef struct { #define __PBM_BITS(set) ((set)->bits) #define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits)) -#define PBM_FREE(s) free(s); +#define PBM_FREE(s) _free(s); #define PBM_SET(d, s) (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d)) #define PBM_CLR(d, s) (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d)) #define PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0) struct optionStackEntry { int argc; -/*@only@*/ const char ** argv; -/*@only@*/ pbm_set * argb; +/*@only@*/ /*@null@*/ const char ** argv; +/*@only@*/ /*@null@*/ pbm_set * argb; int next; -/*@only@*/ const char * nextArg; -/*@keep@*/ const char * nextCharArg; -/*@dependent@*/ struct poptAlias * currAlias; +/*@only@*/ /*@null@*/ const char * nextArg; +/*@keep@*/ /*@null@*/ const char * nextCharArg; +/*@dependent@*/ /*@null@*/ struct poptAlias * currAlias; int stuffed; }; struct execEntry { - const char * longName; +/*@owned@*/ /*@null@*/ const char * longName; char shortName; - const char * script; +/*@only@*/ /*@null@*/ const char * script; }; struct poptContext_s { struct optionStackEntry optionStack[POPT_OPTION_DEPTH]; /*@dependent@*/ struct optionStackEntry * os; -/*@owned@*/ const char ** leftovers; +/*@owned@*/ /*@null@*/ const char ** leftovers; int numLeftovers; int nextLeftover; /*@keep@*/ const struct poptOption * options; int restLeftover; -/*@only@*/ const char * appName; -/*@only@*/ struct poptAlias * aliases; +/*@only@*/ /*@null@*/ const char * appName; +/*@only@*/ /*@null@*/ struct poptAlias * aliases; int numAliases; int flags; - struct execEntry * execs; +/*@owned@*/ /*@null@*/ struct execEntry * execs; int numExecs; -/*@only@*/ const char ** finalArgv; +/*@only@*/ /*@null@*/ const char ** finalArgv; int finalArgvCount; int finalArgvAlloced; -/*@dependent@*/ struct execEntry * doExec; +/*@dependent@*/ /*@null@*/ struct execEntry * doExec; /*@only@*/ const char * execPath; int execAbsolute; /*@only@*/ const char * otherHelp; - pbm_set * arg_strip; +/*@null@*/ pbm_set * arg_strip; }; #ifdef HAVE_LIBINTL_H diff --git a/popt/poptparse.c b/popt/poptparse.c index 9133c365b..fdce57286 100644 --- a/popt/poptparse.c +++ b/popt/poptparse.c @@ -18,6 +18,8 @@ int poptDupArgv(int argc, const char **argv, char * dst; int i; + if (argc <= 0 || argv == NULL) /* XXX can't happen */ + return POPT_ERROR_NOARG; for (i = 0; i < argc; i++) { if (argv[i] == NULL) return POPT_ERROR_NOARG; @@ -25,6 +27,8 @@ int poptDupArgv(int argc, const char **argv, } dst = malloc(nb); + if (dst == NULL) /* XXX can't happen */ + return POPT_ERROR_MALLOC; argv2 = (void *) dst; dst += (argc + 1) * sizeof(*argv); @@ -34,8 +38,14 @@ int poptDupArgv(int argc, const char **argv, } argv2[argc] = NULL; - *argvPtr = argv2; - *argcPtr = argc; + if (argvPtr) { + *argvPtr = argv2; + } else { + free(argv2); + argv2 = NULL; + } + if (argcPtr) + *argcPtr = argc; return 0; } @@ -48,28 +58,31 @@ int poptParseArgvString(const char * s, int * argcPtr, const char *** argvPtr) int argc = 0; int buflen = strlen(s) + 1; char * buf = memset(alloca(buflen), 0, buflen); + int rc = POPT_ERROR_MALLOC; + if (argv == NULL) return rc; argv[argc] = buf; - for (src = s; *src; src++) { + for (src = s; *src != '\0'; src++) { if (quote == *src) { quote = '\0'; - } else if (quote) { + } else if (quote != '\0') { if (*src == '\\') { src++; if (!*src) { - free(argv); - return POPT_ERROR_BADQUOTE; + rc = POPT_ERROR_BADQUOTE; + goto exit; } if (*src != quote) *buf++ = '\\'; } *buf++ = *src; } else if (isspace(*src)) { - if (*argv[argc]) { + if (*argv[argc] != '\0') { buf++, argc++; if (argc == argvAlloced) { argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA; argv = realloc(argv, sizeof(*argv) * argvAlloced); + if (argv == NULL) goto exit; } argv[argc] = buf; } @@ -81,8 +94,8 @@ int poptParseArgvString(const char * s, int * argcPtr, const char *** argvPtr) case '\\': src++; if (!*src) { - free(argv); - return POPT_ERROR_BADQUOTE; + rc = POPT_ERROR_BADQUOTE; + goto exit; } /*@fallthrough@*/ default: @@ -95,9 +108,9 @@ int poptParseArgvString(const char * s, int * argcPtr, const char *** argvPtr) argc++, buf++; } - (void) poptDupArgv(argc, argv, argcPtr, argvPtr); - - free(argv); + rc = poptDupArgv(argc, argv, argcPtr, argvPtr); - return 0; +exit: + if (argv) free(argv); + return rc; } diff --git a/popt/system.h b/popt/system.h index 43ad70f9a..8015c6445 100644 --- a/popt/system.h +++ b/popt/system.h @@ -44,12 +44,14 @@ char *alloca (); /*@only@*/ char * xstrdup (const char *str); +#if !defined(__LCLINT__) #if HAVE_MCHECK_H && defined(__GNUC__) #define vmefail() (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL) #define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str))) #else #define xstrdup(_str) strdup(_str) #endif /* HAVE_MCHECK_H && defined(__GNUC__) */ +#endif /* !__LCLINT__ */ #include "popt.h" diff --git a/popt/test1.c b/popt/test1.c index 7b7f55fe0..919ea7cdd 100644 --- a/popt/test1.c +++ b/popt/test1.c @@ -149,7 +149,7 @@ int main(int argc, const char ** argv) { fprintf(stdout, "\n"); exit: - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); #if HAVE_MCHECK_H && HAVE_MTRACE muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */ #endif diff --git a/popt/test2.c b/popt/test2.c index 3181c0fda..afac1c61e 100644 --- a/popt/test2.c +++ b/popt/test2.c @@ -133,7 +133,7 @@ main(int argc, const char ** argv) { /* although there are no options to be parsed, check for --help */ poptGetNextOpt(optCon); - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); printf( "dbusername %s\tdbpassword %s\n" "txhost %s\ttxsslport %d\ttxstoreid %d\tpathofkeyfile %s\n" @@ -1281,7 +1281,7 @@ int main(int argc, const char ** argv) break; } - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); rpmFreeMacros(NULL); rpmFreeMacros(&rpmCLIMacroContext); rpmFreeRpmrc(); diff --git a/rpmio/digest.c b/rpmio/digest.c index 461aebd47..c2e9628eb 100644 --- a/rpmio/digest.c +++ b/rpmio/digest.c @@ -6,8 +6,10 @@ #include "rpmio_internal.h" #include "debug.h" +/*@-redef@*/ typedef unsigned int uint32; typedef unsigned char byte; +/*@=redef@*/ /*@access DIGEST_CTX@*/ @@ -358,7 +360,9 @@ MD5Transform(DIGEST_CTX ctx) } static int _ie = 0x44332211; +/*@-redef@*/ static union _mendian { int i; char b[4]; } *_endian = (union _mendian *)&_ie; +/*@=redef@*/ #define IS_BIG_ENDIAN() (_endian->b[0] == '\x44') #define IS_LITTLE_ENDIAN() (_endian->b[0] == '\x11') @@ -367,6 +371,7 @@ static union _mendian { int i; char b[4]; } *_endian = (union _mendian *)&_ie; * @param buf data buffer (uint32 aligned address) * @param nbytes no. bytes of data (multiple of sizeof(uint32)) */ +/*@-shadow@*/ static void byteReverse(byte *buf, unsigned nbytes) { @@ -379,6 +384,7 @@ byteReverse(byte *buf, unsigned nbytes) buf += 4; } while (--nlongs); } +/*@=shadow@*/ DIGEST_CTX rpmDigestInit(rpmDigestFlags flags) diff --git a/rpmio/macro.c b/rpmio/macro.c index e815daed2..60eab1444 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -62,13 +62,13 @@ struct MacroContext_s rpmCLIMacroContext; * Macro expansion state. */ typedef struct MacroBuf { -/*@shared@*/ const char *s; /*!< Text to expand. */ -/*@shared@*/ char *t; /*!< Expansion buffer. */ +/*@shared@*/ const char * s; /*!< Text to expand. */ +/*@shared@*/ char * t; /*!< Expansion buffer. */ size_t nb; /*!< No. bytes remaining in expansion buffer. */ - int depth; /*!< Current expansion depth. */ - int macro_trace; /*!< Pre-print macro to expand? */ - int expand_trace; /*!< Post-print macro expansion? */ -/*@shared@*/ void *spec; /*!< (future) %file expansion info. */ + int depth; /*!< Current expansion depth. */ + int macro_trace; /*!< Pre-print macro to expand? */ + int expand_trace; /*!< Post-print macro expansion? */ +/*@shared@*/ /*@null@*/ void * spec; /*!< (future) %file expansion info?. */ /*@dependent@*/ MacroContext mc; } MacroBuf; @@ -76,6 +76,7 @@ typedef struct MacroBuf { static int expandMacro(MacroBuf *mb); +/*@-exportlocal@*/ #define MAX_MACRO_DEPTH 16 int max_macro_depth = MAX_MACRO_DEPTH; @@ -86,6 +87,7 @@ int print_expand_trace = 0; int print_macro_trace = 0; int print_expand_trace = 0; #endif +/*@=exportlocal@*/ #define MACRO_CHUNK_SIZE 16 diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index a5f097134..9ddc7709b 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -401,7 +401,9 @@ static struct FDIO_s fdio_s = { }; FDIO_t fdio = /*@-compmempass@*/ &fdio_s /*@=compmempass@*/ ; +/*@-redef@*/ /* see lib/falloc.c */ FDIO_t fadio; /* XXX usually NULL, filled in when linked with rpm */ +/*@=redef@*/ int fdWritable(FD_t fd, int secs) { @@ -1473,6 +1475,7 @@ static ssize_t ufdRead(void * cookie, /*@out@*/ char * buf, size_t count) { int bytesRead; int total; + *buf = '\0'; /* LCL: insistent bugger. */ /* XXX preserve timedRead() behavior */ if (fdGetIo(fd) == fdio) { struct stat sb; @@ -1608,6 +1611,7 @@ static inline int ufdSeek(void * cookie, _libio_pos_t pos, int whence) { return fdSeek(cookie, pos, whence); } +/*@-usereleased@*/ /* LCL: fd handling is tricky here. */ int ufdClose( /*@only@*/ void * cookie) { FD_t fd = c2f(cookie); @@ -1720,7 +1724,9 @@ fprintf(stderr, "-> \r\n"); } return fdClose(fd); } +/*@=usereleased@*/ +/*@-nullstate@*/ /* FIX: u->{ctrl,data}->url undef after XurlLink. */ /*@null@*/ FD_t ftpOpen(const char *url, /*@unused@*/ int flags, /*@unused@*/ mode_t mode, /*@out@*/ urlinfo *uret) { @@ -1755,7 +1761,9 @@ exit: *uret = u; return fd; } +/*@=nullstate@*/ +/*@-nullstate@*/ /* FIX: u->{ctrl,data}->url undef after XurlLink. */ static /*@null@*/ FD_t httpOpen(const char * url, /*@unused@*/ int flags, /*@unused@*/ mode_t mode, /*@out@*/ urlinfo * uret) { @@ -1795,6 +1803,7 @@ exit: *uret = u; return fd; } +/*@=nullstate@*/ static /*@null@*/ FD_t ufdOpen(const char *url, int flags, mode_t mode) { diff --git a/rpmio/rpmio.h b/rpmio/rpmio.h index 13bf75df7..0533dbeb8 100644 --- a/rpmio/rpmio.h +++ b/rpmio/rpmio.h @@ -331,6 +331,7 @@ int fdFileno(void * cookie); /*@=shadow@*/ +/*@-exportlocal@*/ /** \ingroup rpmio */ /*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode); @@ -360,6 +361,7 @@ int fdWritable(FD_t fd, int secs); /** \ingroup rpmio */ int fdReadable(FD_t fd, int secs); +/*@=exportlocal@*/ /** \ingroup rpmio * FTP and HTTP error codes. @@ -393,7 +395,9 @@ typedef enum ftperrCode_e { /** \ingroup rpmio */ +/*@-exportlocal@*/ int ufdCopy(FD_t sfd, FD_t tfd); +/*@=exportlocal@*/ /** \ingroup rpmio */ @@ -405,6 +409,7 @@ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length); #define timedRead ufdio->read +/*@-exportlocal@*/ /** \ingroup rpmio */ /*@observer@*/ extern FDIO_t fdio; @@ -428,6 +433,7 @@ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length); /** \ingroup rpmio */ /*@observer@*/ extern FDIO_t fadio; +/*@=exportlocal@*/ /*@}*/ /*@unused@*/ static inline int xislower(int c) {return (c >= 'a' && c <= 'z');} diff --git a/rpmio/rpmlog.h b/rpmio/rpmlog.h index 30607a2aa..12877f3b9 100644 --- a/rpmio/rpmlog.h +++ b/rpmio/rpmlog.h @@ -168,21 +168,6 @@ extern "C" { int rpmlogGetNrecs(void); /** - * Return text of last rpmError() message. - * @return text of last message - */ -/*@observer@*/ /*@null@*/ const char * rpmlogMessage(void); - -/** - * Return error code from last rpmError() message. - * @deprecated Perl-RPM needs, what's really needed is predictable, non-i18n - * encumbered, error text that can be retrieved through rpmlogMessage() - * and parsed IMHO. - * @return code from last message - */ -int rpmlogCode(void); - -/** * Print all rpmError() messages. * @param f file handle (NULL uses stderr) */ @@ -210,10 +195,27 @@ int rpmlogSetMask (int mask); */ /*@mayexit@*/ /*@printflike@*/ void rpmlog (int pri, const char *fmt, ...); +/*@-exportlocal@*/ +/** + * Return text of last rpmError() message. + * @return text of last message + */ +/*@observer@*/ /*@null@*/ const char * rpmlogMessage(void); + +/** + * Return error code from last rpmError() message. + * @deprecated Perl-RPM needs, what's really needed is predictable, non-i18n + * encumbered, error text that can be retrieved through rpmlogMessage() + * and parsed IMHO. + * @return code from last message + */ +int rpmlogCode(void); + /** * Set rpmlog callback function. */ rpmlogCallback rpmlogSetCallback(rpmlogCallback cb); +/*@=exportlocal@*/ /** * Set rpmlog callback function. diff --git a/rpmio/rpmmalloc.c b/rpmio/rpmmalloc.c index 7923f87ff..d5e467ab5 100644 --- a/rpmio/rpmmalloc.c +++ b/rpmio/rpmmalloc.c @@ -17,7 +17,7 @@ return NULL; } -#if !(HAVE_MCHECK_H && defined(__GNUC__)) +#if !(HAVE_MCHECK_H && defined(__GNUC__)) && !defined(__LCLINT__) /*@only@*/ void * xmalloc (size_t size) { @@ -49,7 +49,9 @@ static int noPgp = 0; #define GETOPT_SHOWRC 1018 #define GETOPT_DEFINEMACRO 1020 #define GETOPT_EVALMACRO 1021 +#ifdef NOTYET #define GETOPT_RCFILE 1022 +#endif enum modes { @@ -146,7 +148,7 @@ static struct poptOption rpmAllPoptTable[] = { { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0, N_("read <file:...> instead of default macro file(s)"), N_("<file:...>") }, -#ifndef DYING +#if !defined(GETOPT_RCFILE) { "rcfile", '\0', POPT_ARG_STRING, &rcfile, 0, N_("read <file:...> instead of default rpmrc file(s)"), N_("<file:...>") }, @@ -897,28 +899,36 @@ int main(int argc, const char ** argv) #endif case GETOPT_EXCLUDEPATH: - if (*optArg != '/') + /*@-nullderef@*/ /* LCL: optarg != NULL */ + if (optarg == NULL || *optArg != '/') argerror(_("exclude paths must begin with a /")); + /*@=nullderef@*/ relocations = xrealloc(relocations, sizeof(*relocations) * (numRelocations + 1)); + /*@-observertrans -dependenttrans@*/ /* FIX: W2DO? */ relocations[numRelocations].oldPath = optArg; relocations[numRelocations++].newPath = NULL; + /*@=observertrans =dependenttrans@*/ break; case GETOPT_RELOCATE: - { char * errString = NULL; - if (*optArg != '/') + { char * newPath = NULL; + /*@-nullderef -nullpass@*/ /* LCL: optarg != NULL */ + if (optarg == NULL || *optArg != '/') argerror(_("relocations must begin with a /")); - if (!(errString = strchr(optArg, '='))) + if (!(newPath = strchr(optArg, '='))) argerror(_("relocations must contain a =")); - *errString++ = '\0'; - if (*errString != '/') + /*@=nullderef =nullpass@*/ + *newPath++ = '\0'; + if (*newPath != '/') argerror(_("relocations must have a / following the =")); relocations = xrealloc(relocations, sizeof(*relocations) * (numRelocations + 1)); + /*@-observertrans -kepttrans@*/ /* FIX: W2DO? */ relocations[numRelocations].oldPath = optArg; - relocations[numRelocations++].newPath = errString; + relocations[numRelocations++].newPath = newPath; + /*@=observertrans =kepttrans@*/ } break; #endif /* IAM_RPMEIU */ @@ -955,23 +965,29 @@ int main(int argc, const char ** argv) #endif /* IAM_RPMK */ case GETOPT_DEFINEMACRO: + /*@-nullderef -nullpass@*/ /* LCL: optarg != NULL */ + if (optarg == NULL) break; /* XXX can't happen. */ (void) rpmDefineMacro(NULL, optArg, RMIL_CMDLINE); (void) rpmDefineMacro(&rpmCLIMacroContext, optArg, RMIL_CMDLINE); + /*@=nullderef =nullpass@*/ noUsageMsg = 1; break; case GETOPT_EVALMACRO: + if (optarg == NULL) break; /* XXX can't happen. */ { const char *val = rpmExpand(optArg, NULL); fprintf(stdout, "%s\n", val); free((void *)val); noUsageMsg = 1; } break; +#if defined(GETOPT_RCFILE) case GETOPT_RCFILE: fprintf(stderr, _("The --rcfile option has been eliminated.\n")); fprintf(stderr, _("Use \"--macros <file:...>\" instead.\n")); exit(EXIT_FAILURE); /*@notreached@*/ break; +#endif default: fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg); @@ -1568,7 +1584,7 @@ int main(int argc, const char ** argv) #if defined(IAM_RPMBT) || defined(IAM_RPMK) exit: #endif /* IAM_RPMBT || IAM_RPMK */ - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); rpmFreeMacros(NULL); rpmFreeMacros(&rpmCLIMacroContext); rpmFreeRpmrc(); diff --git a/scripts/trpm b/scripts/trpm index 2219eaebc..f3e1ccb82 100755 --- a/scripts/trpm +++ b/scripts/trpm @@ -19,7 +19,7 @@ rpmdb=/usr/bin/rpmdb dist=7.0 type=min -arch=`$rpmq --eval '%{_arch}'` +arch=`$rpm --eval '%{_arch}'` top=`pwd` root=$top/$dist @@ -90,7 +90,9 @@ extern int errno; #endif #ifdef STDC_HEADERS +/*@-macrounrecog -incondefs -globuse@*/ /* FIX: shrug */ #define getopt system_getopt +/*@=macrounrecog =incondefs =globuse@*/ /*@-skipansiheaders@*/ #include <stdlib.h> /*@=skipansiheaders@*/ diff --git a/tools/rpminject.c b/tools/rpminject.c index 04f7c3959..b43b37797 100644 --- a/tools/rpminject.c +++ b/tools/rpminject.c @@ -610,6 +610,6 @@ main(int argc, char *argv[]) ec = do_inject(cmds, ncmds, poptGetArgs(optCon)); - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); return ec; } diff --git a/tools/rpmsort.c b/tools/rpmsort.c index d392fc605..83f507f4e 100644 --- a/tools/rpmsort.c +++ b/tools/rpmsort.c @@ -322,7 +322,7 @@ main(int argc, const char *argv[]) ec = do_tsort(poptGetArgs(optCon)); - poptFreeContext(optCon); + optCon = poptFreeContext(optCon); return ec; } |