diff options
64 files changed, 960 insertions, 1031 deletions
@@ -13,7 +13,7 @@ # don't-bother-me-yet parameters #-branchstate #-immediatetrans --mustfree +-mustfree # alloca is painful #-observertrans #-statictrans @@ -27,7 +27,7 @@ -type -# -weak paramaters +# not-yet -weak paramaters #+boolint #-boolops #+ignorequals diff --git a/build/build.c b/build/build.c index 403e0c8e7..ecda494ae 100644 --- a/build/build.c +++ b/build/build.c @@ -23,14 +23,14 @@ static void doRmSource(Spec spec) Package pkg; #if 0 - unlink(spec->specFile); + Unlink(spec->specFile); #endif for (p = spec->sources; p != NULL; p = p->next) { if (! (p->flags & RPMBUILD_ISNO)) { const char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL); - unlink(fn); - free((void *)fn); + Unlink(fn); + fn = _free(fn); } } @@ -38,8 +38,8 @@ static void doRmSource(Spec spec) for (p = pkg->icon; p != NULL; p = p->next) { if (! (p->flags & RPMBUILD_ISNO)) { const char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL); - unlink(fn); - free((void *)fn); + Unlink(fn); + fn = _free(fn); } } } @@ -218,7 +218,7 @@ exit: if (scriptName) { if (!rc) Unlink(scriptName); - free((void *)scriptName); + scriptName = _free(scriptName); } if (u) { switch (u->urltype) { @@ -235,11 +235,11 @@ fprintf(stderr, "*** delMacros\n"); break; } } - FREE(argv); - FREE(buildCmd); - FREE(buildTemplate); - FREE(buildPost); - FREE(buildDirURL); + argv = _free(argv); + buildCmd = _free(buildCmd); + buildTemplate = _free(buildTemplate); + buildPost = _free(buildPost); + buildDirURL = _free(buildDirURL); return rc; } @@ -303,7 +303,7 @@ int buildSpec(Spec spec, int what, int test) doRmSource(spec); if (what & RPMBUILD_RMSPEC) - unlink(spec->specFile); + Unlink(spec->specFile); exit: if (rc && rpmlogGetNrecs() > 0) { diff --git a/build/expression.c b/build/expression.c index b8e34072f..abdfb3e2c 100644 --- a/build/expression.c +++ b/build/expression.c @@ -67,8 +67,9 @@ static Value valueMakeString(/*@only@*/ const char *s) static void valueFree( /*@only@*/ Value v) { if (v) { - if (v->type == VALUE_TYPE_STRING) free((void *)v->data.s); - free(v); + if (v->type == VALUE_TYPE_STRING) + v->data.s = _free(v->data.s); + v = _free(v); } } @@ -182,7 +183,7 @@ static int rdToken(ParseState state) char *p = state->p; /* Skip whitespace before the next token. */ - while (*p && isspace(*p)) p++; + while (*p && xisspace(*p)) p++; switch (*p) { case '\0': @@ -257,10 +258,10 @@ static int rdToken(ParseState state) break; default: - if (isdigit(*p)) { + if (xisdigit(*p)) { char temp[EXPRBUFSIZ], *t = temp; - while (*p && isdigit(*p)) + while (*p && xisdigit(*p)) *t++ = *p++; *t++ = '\0'; p--; @@ -268,10 +269,10 @@ static int rdToken(ParseState state) token = TOK_INTEGER; v = valueMakeInteger(atoi(temp)); - } else if (isalpha(*p)) { + } else if (xisalpha(*p)) { char temp[EXPRBUFSIZ], *t = temp; - while (*p && (isalnum(*p) || *p == '_')) + while (*p && (xisalnum(*p) || *p == '_')) *t++ = *p++; *t++ = '\0'; p--; @@ -649,14 +650,14 @@ int parseExpressionBoolean(Spec spec, const char *expr) /* Parse the expression. */ v = doLogical(&state); if (!v) { - free(state.str); + state.str = _free(state.str); return -1; } /* If the next token is not TOK_EOF, we have a syntax error. */ if (state.nextToken != TOK_EOF) { rpmError(RPMERR_BADSPEC, _("syntax error in expression\n")); - free(state.str); + state.str = _free(state.str); return -1; } @@ -673,7 +674,7 @@ int parseExpressionBoolean(Spec spec, const char *expr) break; } - free(state.str); + state.str = _free(state.str); valueFree(v); return result; } @@ -696,14 +697,14 @@ char * parseExpressionString(Spec spec, const char *expr) /* Parse the expression. */ v = doLogical(&state); if (!v) { - free(state.str); + state.str = _free(state.str); return NULL; } /* If the next token is not TOK_EOF, we have a syntax error. */ if (state.nextToken != TOK_EOF) { rpmError(RPMERR_BADSPEC, _("syntax error in expression\n")); - free(state.str); + state.str = _free(state.str); return NULL; } @@ -722,7 +723,7 @@ char * parseExpressionString(Spec spec, const char *expr) break; } - free(state.str); + state.str = _free(state.str); valueFree(v); return result; } diff --git a/build/files.c b/build/files.c index d6084babc..1b8fa9a3d 100644 --- a/build/files.c +++ b/build/files.c @@ -26,28 +26,32 @@ /*@access TFI_t @*/ /*@access FD_t @*/ -#define SKIPWHITE(_x) {while(*(_x) && (isspace(*_x) || *(_x) == ',')) (_x)++;} -#define SKIPNONWHITE(_x){while(*(_x) &&!(isspace(*_x) || *(_x) == ',')) (_x)++;} +#define SKIPWHITE(_x) {while(*(_x) && (xisspace(*_x) || *(_x) == ',')) (_x)++;} +#define SKIPNONWHITE(_x){while(*(_x) &&!(xisspace(*_x) || *(_x) == ',')) (_x)++;} #define MAXDOCDIR 1024 extern int _noDirTokens; -#define SPECD_DEFFILEMODE (1<<0) -#define SPECD_DEFDIRMODE (1<<1) -#define SPECD_DEFUID (1<<2) -#define SPECD_DEFGID (1<<3) -#define SPECD_DEFVERIFY (1<<4) - -#define SPECD_FILEMODE (1<<8) -#define SPECD_DIRMODE (1<<9) -#define SPECD_UID (1<<10) -#define SPECD_GID (1<<11) -#define SPECD_VERIFY (1<<12) +/** + */ +typedef enum specdFlags_e { + SPECD_DEFFILEMODE = (1 << 0), + SPECD_DEFDIRMODE = (1 << 1), + SPECD_DEFUID = (1 << 2), + SPECD_DEFGID = (1 << 3), + SPECD_DEFVERIFY = (1 << 4), + + SPECD_FILEMODE = (1 << 8), + SPECD_DIRMODE = (1 << 9), + SPECD_UID = (1 << 10), + SPECD_GID = (1 << 11), + SPECD_VERIFY = (1 << 12) +} specdFlags; /** */ -typedef struct { +typedef struct FileListRec_s { struct stat fl_st; #define fl_dev fl_st.st_dev #define fl_ino fl_st.st_ino @@ -59,26 +63,26 @@ typedef struct { #define fl_size fl_st.st_size #define fl_mtime fl_st.st_mtime - const char *diskURL; /* get file from here */ - const char *fileURL; /* filename in cpio archive */ - /*@observer@*/ const char *uname; - /*@observer@*/ const char *gname; +/*@only@*/ const char * diskURL; /* get file from here */ +/*@only@*/ const char * fileURL; /* filename in cpio archive */ +/*@observer@*/ const char * uname; +/*@observer@*/ const char * gname; int flags; - int specdFlags; /* which attributes have been explicitly specified. */ + specdFlags specdFlags; /* which attributes have been explicitly specified. */ int verifyFlags; - const char *langs; /* XXX locales separated with | */ -} FileListRec; +/*@only@*/ const char *langs; /* XXX locales separated with | */ +} * FileListRec; /** */ -typedef struct { - const char *ar_fmodestr; - const char *ar_dmodestr; - const char *ar_user; - const char *ar_group; +typedef struct AttrRec_s { + const char * ar_fmodestr; + const char * ar_dmodestr; + const char * ar_user; + const char * ar_group; mode_t ar_fmode; mode_t ar_dmode; -} AttrRec; +} * AttrRec; /** */ @@ -87,9 +91,9 @@ static int multiLib = 0; /* MULTILIB */ /** * Package file tree walk data. */ -struct FileList { - const char *buildRootURL; - const char *prefix; +typedef struct FileList_s { +/*@only@*/ const char * buildRootURL; +/*@only@*/ const char * prefix; int fileCount; int totalFileSize; @@ -101,28 +105,28 @@ struct FileList { int isDir; int inFtw; int currentFlags; - int currentSpecdFlags; + specdFlags currentSpecdFlags; int currentVerifyFlags; - AttrRec cur_ar; - AttrRec def_ar; - int defSpecdFlags; + struct AttrRec_s cur_ar; + struct AttrRec_s def_ar; + specdFlags defSpecdFlags; int defVerifyFlags; int nLangs; - /*@only@*/ const char **currentLangs; +/*@only@*/ const char ** currentLangs; /* Hard coded limit of MAXDOCDIR docdirs. */ /* If you break it you are doing something wrong. */ - const char *docDirs[MAXDOCDIR]; + const char * docDirs[MAXDOCDIR]; int docDirCount; - FileListRec *fileList; +/*@only@*/ FileListRec fileList; int fileListRecsAlloced; int fileListRecsUsed; -}; +} * FileList; /** */ -static void nullAttrRec(/*@out@*/AttrRec *ar) +static void nullAttrRec(/*@out@*/ AttrRec ar) { ar->ar_fmodestr = NULL; ar->ar_dmodestr = NULL; @@ -134,20 +138,20 @@ static void nullAttrRec(/*@out@*/AttrRec *ar) /** */ -static void freeAttrRec(AttrRec *ar) +static void freeAttrRec(AttrRec ar) { - FREE(ar->ar_fmodestr); - FREE(ar->ar_dmodestr); - FREE(ar->ar_user); - FREE(ar->ar_group); + ar->ar_fmodestr = _free(ar->ar_fmodestr); + ar->ar_dmodestr = _free(ar->ar_dmodestr); + ar->ar_user = _free(ar->ar_user); + ar->ar_group = _free(ar->ar_group); /* XXX doesn't free ar (yet) */ } /** */ -static void dupAttrRec(AttrRec *oar, /*@out@*/ AttrRec *nar) +static void dupAttrRec(const AttrRec oar, /*@in@*/ /*@out@*/ AttrRec nar) { - if (oar == nar) /* XXX pathological paranoia */ + if (oar == nar) return; freeAttrRec(nar); nar->ar_fmodestr = (oar->ar_fmodestr ? xstrdup(oar->ar_fmodestr) : NULL); @@ -161,7 +165,7 @@ static void dupAttrRec(AttrRec *oar, /*@out@*/ AttrRec *nar) #if 0 /** */ -static void dumpAttrRec(const char *msg, AttrRec *ar) { +static void dumpAttrRec(const char *msg, AttrRec ar) { if (msg) fprintf(stderr, "%s:\t", msg); fprintf(stderr, "(%s, %s, %s, %s)\n", @@ -235,21 +239,22 @@ static char *strtokWithQuotes(char *s, char *delim) */ static void timeCheck(int tc, Header h) { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; int *mtime; - char **files; - int count, x, currentTime; - - headerGetEntry(h, RPMTAG_OLDFILENAMES, NULL, (void **) &files, &count); - headerGetEntry(h, RPMTAG_FILEMTIMES, NULL, (void **) &mtime, NULL); + const char ** files; + int fnt; + int count, x; + time_t currentTime = time(NULL); - currentTime = time(NULL); + hge(h, RPMTAG_OLDFILENAMES, &fnt, (void **) &files, &count); + hge(h, RPMTAG_FILEMTIMES, NULL, (void **) &mtime, NULL); for (x = 0; x < count; x++) { - if (currentTime - mtime[x] > tc) { + if ((currentTime - mtime[x]) > tc) rpmMessage(RPMMESS_WARNING, _("TIMECHECK failure: %s\n"), files[x]); - } } - FREE(files); + files = hfd(files, fnt); } /** @@ -276,14 +281,14 @@ VFA_t verifyAttrs[] = { /** * @param fl package file tree walk data */ -static int parseForVerify(char *buf, struct FileList *fl) +static int parseForVerify(char *buf, FileList fl) { char *p, *pe, *q; const char *name; int *resultVerify; int not; int verifyFlags; - int *specdFlags; + specdFlags * specdFlags; if ((p = strstr(buf, (name = "%verify"))) != NULL) { resultVerify = &(fl->currentVerifyFlags); @@ -366,13 +371,14 @@ static int parseForVerify(char *buf, struct FileList *fl) /** * @param fl package file tree walk data */ -static int parseForAttr(char *buf, struct FileList *fl) +static int parseForAttr(char *buf, FileList fl) { char *p, *pe, *q; const char *name; int x; - AttrRec arbuf, *ar = &arbuf, *ret_ar; - int *specdFlags = NULL; + struct AttrRec_s arbuf; + AttrRec ar = &arbuf, ret_ar; + specdFlags * specdFlags; if ((p = strstr(buf, (name = "%attr"))) != NULL) { ret_ar = &(fl->cur_ar); @@ -490,7 +496,7 @@ static int parseForAttr(char *buf, struct FileList *fl) /** * @param fl package file tree walk data */ -static int parseForConfig(char *buf, struct FileList *fl) +static int parseForConfig(char *buf, FileList fl) { char *p, *pe, *q; const char *name; @@ -555,7 +561,7 @@ static int langCmp(const void * ap, const void *bp) { /** * @param fl package file tree walk data */ -static int parseForLang(char *buf, struct FileList *fl) +static int parseForLang(char *buf, FileList fl) { char *p, *pe, *q; const char *name; @@ -642,7 +648,7 @@ static int parseForLang(char *buf, struct FileList *fl) /** */ -static int parseForRegexLang(const char *fileName, /*@out@*/char **lang) +static int parseForRegexLang(const char * fileName, /*@out@*/ char ** lang) { static int initialized = 0; static int hasRegex = 0; @@ -659,13 +665,14 @@ static int parseForRegexLang(const char *fileName, /*@out@*/char **lang) rc = 1; else if (regcomp(&compiledPatt, patt, REG_EXTENDED)) rc = -1; - free((void *)patt); + patt = _free(patt); if (rc) return rc; hasRegex = 1; initialized = 1; } + memset(matches, 0, sizeof(matches)); if (! hasRegex || regexec(&compiledPatt, fileName, 2, matches, REG_NOTEOL)) return 1; @@ -699,7 +706,7 @@ static int parseForRegexMultiLib(const char *fileName) rc = 1; else if (regcomp(&compiledPatt, patt, REG_EXTENDED | REG_NOSUB)) rc = -1; - free((void *)patt); + patt = _free(patt); if (rc) return rc; hasRegex = 1; @@ -737,7 +744,7 @@ VFA_t virtualFileAttributes[] = { * @param fl package file tree walk data */ static int parseForSimple(/*@unused@*/Spec spec, Package pkg, char *buf, - struct FileList *fl, const char **fileName) + FileList fl, const char ** fileName) { char *s, *t; int res, specialDoc = 0; @@ -825,7 +832,7 @@ static int parseForSimple(/*@unused@*/Spec spec, Package pkg, char *buf, ddir = rpmGetPath("%{_docdir}/", n, "-", v, NULL); strcpy(buf, ddir); - free((void *)ddir); + ddir = _free(ddir); } /* XXX FIXME: this is easy to do as macro expansion */ @@ -856,15 +863,15 @@ static int parseForSimple(/*@unused@*/Spec spec, Package pkg, char *buf, */ static int compareFileListRecs(const void *ap, const void *bp) { - const char *a = ((FileListRec *)ap)->fileURL; - const char *b = ((FileListRec *)bp)->fileURL; + const char *a = ((FileListRec)ap)->fileURL; + const char *b = ((FileListRec)bp)->fileURL; return strcmp(a, b); } /** * @param fl package file tree walk data */ -static int isDoc(struct FileList *fl, const char *fileName) +static int isDoc(FileList fl, const char * fileName) { int x = fl->docDirCount; @@ -880,10 +887,10 @@ static int isDoc(struct FileList *fl, const char *fileName) * @todo only %lang for now, finish other attributes later. * @param fl package file tree walk data */ -static void checkHardLinks(struct FileList *fl) +static void checkHardLinks(FileList fl) { char nlangs[BUFSIZ]; - FileListRec *ilp, *jlp; + FileListRec ilp, jlp; int i, j; for (i = 0; i < fl->fileListRecsUsed; i++) { @@ -921,7 +928,7 @@ static void checkHardLinks(struct FileList *fl) if (te == nlangs) continue; - free((void *)ilp->langs); + ilp->langs = _free(ilp->langs); ilp->langs = xstrdup(nlangs); for (j = i + 1; j < fl->fileListRecsUsed; j++) { jlp = fl->fileList + j; @@ -934,7 +941,7 @@ static void checkHardLinks(struct FileList *fl) if (ilp->fl_dev != jlp->fl_dev) continue; jlp->flags |= RPMFILE_SPECFILE; - free((void *)jlp->langs); + jlp->langs = _free(jlp->langs); jlp->langs = xstrdup(nlangs); } } @@ -950,15 +957,15 @@ static void checkHardLinks(struct FileList *fl) * @todo Remove RPMTAG_OLDFILENAMES, add dirname/basename instead. * @param fl package file tree walk data */ -static void genCpioListAndHeader(struct FileList *fl, TFI_t *cpioList, - Header h, int isSrc) +static void genCpioListAndHeader(/*@partial@*/ FileList fl, + TFI_t *cpioList, Header h, int isSrc) { int _addDotSlash = !(isSrc || rpmExpandNumeric("%{_noPayloadPrefix}")); uint_32 multiLibMask = 0; int apathlen = 0; int dpathlen = 0; int skipLen = 0; - FileListRec *flp; + FileListRec flp; char buf[BUFSIZ]; int i; @@ -1043,7 +1050,7 @@ static void genCpioListAndHeader(struct FileList *fl, TFI_t *cpioList, if (flp->flags & RPMFILE_MULTILIB_MASK) multiLibMask |= - (1 << ((flp->flags & RPMFILE_MULTILIB_MASK)) + (1u << ((flp->flags & RPMFILE_MULTILIB_MASK)) >> RPMFILE_MULTILIB_SHIFT); /* @@ -1177,12 +1184,8 @@ static void genCpioListAndHeader(struct FileList *fl, TFI_t *cpioList, fi->type = TR_ADDED; loadFi(h, fi); - if (fi->dnl) { - free((void *)fi->dnl); fi->dnl = NULL; - } - if (fi->bnl) { - free((void *)fi->bnl); fi->bnl = NULL; - } + fi->dnl = _free(fi->dnl); + fi->bnl = _free(fi->bnl); fi->dnl = xmalloc(fi->fc * sizeof(*fi->dnl) + dpathlen); d = (char *)(fi->dnl + fi->fc); @@ -1247,26 +1250,27 @@ static void genCpioListAndHeader(struct FileList *fl, TFI_t *cpioList, if (cpioList) *cpioList = fi; else - free(fi); + fi = _free(fi); } } /** */ -static void freeFileList(FileListRec *fileList, int count) +static /*@null@*/ FileListRec freeFileList(/*@only@*/ FileListRec fileList, int count) { while (count--) { - FREE(fileList[count].diskURL); - FREE(fileList[count].fileURL); - FREE(fileList[count].langs); + fileList[count].diskURL = _free(fileList[count].diskURL); + fileList[count].fileURL = _free(fileList[count].fileURL); + fileList[count].langs = _free(fileList[count].langs); } - FREE(fileList); + fileList = _free(fileList); + return NULL; } /** * @param fl package file tree walk data */ -static int addFile(struct FileList *fl, const char * diskURL, struct stat *statp) +static int addFile(FileList fl, const char * diskURL, struct stat *statp) { const char *fileURL = diskURL; struct stat statbuf; @@ -1384,7 +1388,7 @@ static int addFile(struct FileList *fl, const char * diskURL, struct stat *statp fl->fileListRecsAlloced * sizeof(*(fl->fileList))); } - { FileListRec * flp = &fl->fileList[fl->fileListRecsUsed]; + { FileListRec flp = &fl->fileList[fl->fileListRecsUsed]; flp->fl_st = *statp; /* structure assignment */ flp->fl_mode = fileMode; @@ -1439,7 +1443,7 @@ static int addFile(struct FileList *fl, const char * diskURL, struct stat *statp /** * @param fl package file tree walk data */ -static int processBinaryFile(/*@unused@*/Package pkg, struct FileList *fl, +static int processBinaryFile(/*@unused@*/Package pkg, FileList fl, const char *fileURL) { int doGlob; @@ -1478,9 +1482,9 @@ static int processBinaryFile(/*@unused@*/Package pkg, struct FileList *fl, if (rc == 0 && argc >= 1 && !myGlobPatternP(argv[0])) { for (i = 0; i < argc; i++) { rc = addFile(fl, argv[i], NULL); - free((void *)argv[i]); + argv[i] = _free(argv[i]); } - free((void *)argv); + argv = _free(argv); } else { rpmError(RPMERR_BADSPEC, _("File not found by glob: %s\n"), diskURL); @@ -1491,8 +1495,7 @@ static int processBinaryFile(/*@unused@*/Package pkg, struct FileList *fl, } exit: - if (diskURL) - free((void *)diskURL); + diskURL = _free(diskURL); if (rc) fl->processingFailed = 1; return rc; @@ -1503,11 +1506,13 @@ exit: static int processPackageFiles(Spec spec, Package pkg, int installSpecialDoc, int test) { - struct FileList fl; + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + struct FileList_s fl; char *s, **files, **fp; const char *fileName; char buf[BUFSIZ]; - AttrRec specialDocAttrRec; + struct AttrRec_s arbuf; + AttrRec specialDocAttrRec = &arbuf; char *specialDoc = NULL; #ifdef MULTILIB @@ -1516,11 +1521,12 @@ static int processPackageFiles(Spec spec, Package pkg, multiLib = RPMFILE_MULTILIB(multiLib); #endif /* MULTILIB */ - nullAttrRec(&specialDocAttrRec); + nullAttrRec(specialDocAttrRec); pkg->cpioList = NULL; if (pkg->fileFile) { const char *ffn; + FILE * f; FD_t fd; /* XXX W2DO? urlPath might be useful here. */ @@ -1540,9 +1546,10 @@ static int processPackageFiles(Spec spec, Package pkg, ffn, Fstrerror(fd)); return RPMERR_BADFILENAME; } - free((void *)ffn); + ffn = _free(ffn); - while (fgets(buf, sizeof(buf), (FILE *)fdGetFp(fd))) { + /*@+voidabstract@*/ f = fdGetFp(fd); /*@=voidabstract@*/ + while (fgets(buf, sizeof(buf), f)) { handleComments(buf); if (expandMacros(spec, spec->macros, buf, sizeof(buf))) { rpmError(RPMERR_BADSPEC, _("line: %s\n"), buf); @@ -1558,12 +1565,10 @@ static int processPackageFiles(Spec spec, Package pkg, /* XXX spec->buildRootURL == NULL, then xstrdup("") is returned */ fl.buildRootURL = rpmGenPath(spec->rootURL, spec->buildRootURL, NULL); - if (headerGetEntry(pkg->header, RPMTAG_DEFAULTPREFIX, - NULL, (void **)&fl.prefix, NULL)) { + if (hge(pkg->header, RPMTAG_DEFAULTPREFIX, NULL, (void **)&fl.prefix, NULL)) fl.prefix = xstrdup(fl.prefix); - } else { + else fl.prefix = NULL; - } fl.fileCount = 0; fl.totalFileSize = 0; @@ -1619,7 +1624,7 @@ static int processPackageFiles(Spec spec, Package pkg, fl.inFtw = 0; fl.currentFlags = 0; /* turn explicit flags into %def'd ones (gosh this is hacky...) */ - fl.currentSpecdFlags = fl.defSpecdFlags>>8; + fl.currentSpecdFlags = ((unsigned)fl.defSpecdFlags) >> 8; fl.currentVerifyFlags = fl.defVerifyFlags; fl.isSpecialDoc = 0; @@ -1627,8 +1632,8 @@ static int processPackageFiles(Spec spec, Package pkg, if (fl.currentLangs) { int i; for (i = 0; i < fl.nLangs; i++) - free((void *)fl.currentLangs[i]); - FREE(fl.currentLangs); + fl.currentLangs[i] = _free(fl.currentLangs[i]); + fl.currentLangs = _free(fl.currentLangs); } fl.nLangs = 0; @@ -1649,9 +1654,9 @@ static int processPackageFiles(Spec spec, Package pkg, if (fl.isSpecialDoc) { /* Save this stuff for last */ - FREE(specialDoc); + specialDoc = _free(specialDoc); specialDoc = xstrdup(fileName); - dupAttrRec(&fl.cur_ar, &specialDocAttrRec); + dupAttrRec(&fl.cur_ar, specialDocAttrRec); } else { processBinaryFile(pkg, &fl, fileName); } @@ -1673,17 +1678,17 @@ static int processPackageFiles(Spec spec, Package pkg, if (fl.currentLangs) { int i; for (i = 0; i < fl.nLangs; i++) - free((void *)fl.currentLangs[i]); - FREE(fl.currentLangs); + fl.currentLangs[i] = _free(fl.currentLangs[i]); + fl.currentLangs = _free(fl.currentLangs); } fl.nLangs = 0; - dupAttrRec(&specialDocAttrRec, &fl.cur_ar); - freeAttrRec(&specialDocAttrRec); + dupAttrRec(specialDocAttrRec, &fl.cur_ar); + freeAttrRec(specialDocAttrRec); processBinaryFile(pkg, &fl, specialDoc); - FREE(specialDoc); + specialDoc = _free(specialDoc); } freeSplitString(files); @@ -1700,8 +1705,8 @@ static int processPackageFiles(Spec spec, Package pkg, timeCheck(spec->timeCheck, pkg->header); exit: - FREE(fl.buildRootURL); - FREE(fl.prefix); + fl.buildRootURL = _free(fl.buildRootURL); + fl.prefix = _free(fl.prefix); freeAttrRec(&fl.cur_ar); freeAttrRec(&fl.def_ar); @@ -1709,14 +1714,13 @@ exit: if (fl.currentLangs) { int i; for (i = 0; i < fl.nLangs; i++) - free((void *)fl.currentLangs[i]); - FREE(fl.currentLangs); + fl.currentLangs[i] = _free(fl.currentLangs[i]); + fl.currentLangs = _free(fl.currentLangs); } - freeFileList(fl.fileList, fl.fileListRecsUsed); - while (fl.docDirCount--) { - FREE(fl.docDirs[fl.docDirCount]); - } + fl.fileList = freeFileList(fl.fileList, fl.fileListRecsUsed); + while (fl.docDirCount--) + fl.docDirs[fl.docDirCount] = _free(fl.docDirs[fl.docDirCount]); return fl.processingFailed; } @@ -1782,7 +1786,7 @@ int processSourceFiles(Spec spec) struct Source *srcPtr; StringBuf sourceFiles; int x, isSpec = 1; - struct FileList fl; + struct FileList_s fl; char *s, **files, **fp; Package pkg; @@ -1815,27 +1819,27 @@ int processSourceFiles(Spec spec) } } - { const char *s; - s = rpmGetPath( ((srcPtr->flags & RPMBUILD_ISNO) ? "!" : ""), + { const char * sfn; + sfn = rpmGetPath( ((srcPtr->flags & RPMBUILD_ISNO) ? "!" : ""), "%{_sourcedir}/", srcPtr->source, NULL); - appendLineStringBuf(sourceFiles, s); - free((void *)s); + appendLineStringBuf(sourceFiles, sfn); + sfn = _free(sfn); } } for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) { for (srcPtr = pkg->icon; srcPtr != NULL; srcPtr = srcPtr->next) { - const char *s; - s = rpmGetPath( ((srcPtr->flags & RPMBUILD_ISNO) ? "!" : ""), + const char * sfn; + sfn = rpmGetPath( ((srcPtr->flags & RPMBUILD_ISNO) ? "!" : ""), "%{_sourcedir}/", srcPtr->source, NULL); - appendLineStringBuf(sourceFiles, s); - free((void *)s); + appendLineStringBuf(sourceFiles, sfn); + sfn = _free(sfn); } } spec->sourceCpioList = NULL; - fl.fileList = xmalloc((spec->numSources + 1) * sizeof(FileListRec)); + fl.fileList = xmalloc((spec->numSources + 1) * sizeof(*fl.fileList)); fl.processingFailed = 0; fl.fileListRecsUsed = 0; fl.totalFileSize = 0; @@ -1848,7 +1852,7 @@ int processSourceFiles(Spec spec) x = 0; for (fp = files; *fp != NULL; fp++) { const char * diskURL, *diskPath; - FileListRec *flp; + FileListRec flp; diskURL = *fp; SKIPSPACE(diskURL); @@ -1864,7 +1868,7 @@ int processSourceFiles(Spec spec) diskURL++; } - urlPath(diskURL, &diskPath); + (void) urlPath(diskURL, &diskPath); flp->diskURL = xstrdup(diskURL); diskPath = strrchr(diskPath, '/'); @@ -1904,7 +1908,7 @@ int processSourceFiles(Spec spec) } freeStringBuf(sourceFiles); - freeFileList(fl.fileList, fl.fileListRecsUsed); + fl.fileList = freeFileList(fl.fileList, fl.fileListRecsUsed); return fl.processingFailed; } @@ -2159,7 +2163,7 @@ static int generateDepends(Spec spec, Package pkg, TFI_t cpioList, int multiLib) myargv[0] = (dm->argv[0] ? rpmExpand(dm->argv[0], NULL) : NULL); if (!(myargv[0] && *myargv[0] != '%')) { - free(myargv[0]); + myargv[0] = _free(myargv[0]); continue; } @@ -2168,8 +2172,7 @@ static int generateDepends(Spec spec, Package pkg, TFI_t cpioList, int multiLib) #if 0 if (*myargv[0] != '/') { /* XXX FIXME: stat script here */ - free(myargv[0]); - myargv[0] = NULL; + myargv[0] = _free(myargv[0]); continue; } #endif @@ -2183,11 +2186,8 @@ static int generateDepends(Spec spec, Package pkg, TFI_t cpioList, int multiLib) getStringBuf(writeBuf), writeBytes, failnonzero); /* Free expanded args */ - for (i = 0; i < 4; i++) { - if (myargv[i] == NULL) continue; - free(myargv[i]); - myargv[i] = NULL; - } + for (i = 0; i < 4; i++) + myargv[i] = _free(myargv[i]); if (readBuf == NULL) { rc = RPMERR_EXEC; @@ -2259,34 +2259,38 @@ static void printDepMsg(DepMsg_t *dm, int count, const char **names, */ static void printDeps(Header h) { - const char **names = NULL; - const char **versions = NULL; - int *flags = NULL; - DepMsg_t *dm; - int type, count; + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; + const char ** names = NULL; + int dnt = -1; + const char ** versions = NULL; + int dvt = -1; + int * flags = NULL; + DepMsg_t * dm; + int count; for (dm = depMsgs; dm->msg != NULL; dm++) { switch (dm->ntag) { case 0: - FREE(names); + names = hfd(names, dnt); break; case -1: break; default: - FREE(names); - if (!headerGetEntry(h, dm->ntag, &type, (void **) &names, &count)) + names = hfd(names, dnt); + if (!hge(h, dm->ntag, &dnt, (void **) &names, &count)) continue; break; } switch (dm->vtag) { case 0: - FREE(versions); + versions = hfd(versions, dvt); break; case -1: break; default: - FREE(versions); - headerGetEntry(h, dm->vtag, NULL, (void **) &versions, NULL); + versions = hfd(versions, dvt); + hge(h, dm->vtag, &dvt, (void **) &versions, NULL); break; } switch (dm->ftag) { @@ -2296,13 +2300,13 @@ static void printDeps(Header h) case -1: break; default: - headerGetEntry(h, dm->ftag, NULL, (void **) &flags, NULL); + hge(h, dm->ftag, NULL, (void **) &flags, NULL); break; } printDepMsg(dm, count, names, versions, flags); } - FREE(names); - FREE(versions); + names = hfd(names, dnt); + versions = hfd(versions, dvt); } int processBinaryFiles(Spec spec, int installSpecialDoc, int test) @@ -2327,13 +2331,12 @@ int processBinaryFiles(Spec spec, int installSpecialDoc, int test) * XXX However, there is logic in files.c/depends.c that checks for * XXX existence (rather than value) that will need to change as well. */ - if (headerGetEntry(pkg->header, RPMTAG_MULTILIBS, NULL, NULL, NULL)) { + if (headerIsEntry(pkg->header, RPMTAG_MULTILIBS)) { generateDepends(spec, pkg, pkg->cpioList, 1); generateDepends(spec, pkg, pkg->cpioList, 2); } else generateDepends(spec, pkg, pkg->cpioList, 0); printDeps(pkg->header); - } return res; diff --git a/build/names.c b/build/names.c index 6cdbee988..da2787ac5 100644 --- a/build/names.c +++ b/build/names.c @@ -21,9 +21,9 @@ void freeNames(void) { int x; for (x = 0; x < uid_used; x++) - free((void *)unames[x]); + unames[x] = _free(unames[x]); for (x = 0; x < gid_used; x++) - free((void *)gnames[x]); + gnames[x] = _free(gnames[x]); } const char *getUname(uid_t uid) @@ -32,23 +32,18 @@ const char *getUname(uid_t uid) int x; for (x = 0; x < uid_used; x++) { - if (uids[x] == uid) { + if (uids[x] == uid) return unames[x]; - } } /* XXX - This is the other hard coded limit */ if (x == 1024) rpmlog(RPMLOG_CRIT, _("getUname: too many uid's\n")); + uid_used++; pw = getpwuid(uid); uids[x] = uid; - uid_used++; - if (pw) { - unames[x] = xstrdup(pw->pw_name); - } else { - unames[x] = NULL; - } + unames[x] = (pw ? xstrdup(pw->pw_name) : NULL); return unames[x]; } @@ -58,24 +53,18 @@ const char *getUnameS(const char *uname) int x; for (x = 0; x < uid_used; x++) { - if (!strcmp(unames[x],uname)) { + if (!strcmp(unames[x],uname)) return unames[x]; - } } /* XXX - This is the other hard coded limit */ if (x == 1024) rpmlog(RPMLOG_CRIT, _("getUnameS: too many uid's\n")); + uid_used++; pw = getpwnam(uname); - uid_used++; - if (pw) { - uids[x] = pw->pw_uid; - unames[x] = xstrdup(pw->pw_name); - } else { - uids[x] = -1; - unames[x] = xstrdup(uname); - } + uids[x] = (pw ? pw->pw_uid : -1); + unames[x] = (pw ? xstrdup(pw->pw_name) : xstrdup(uname)); return unames[x]; } @@ -85,23 +74,18 @@ const char *getGname(gid_t gid) int x; for (x = 0; x < gid_used; x++) { - if (gids[x] == gid) { + if (gids[x] == gid) return gnames[x]; - } } /* XXX - This is the other hard coded limit */ if (x == 1024) rpmlog(RPMLOG_CRIT, _("getGname: too many gid's\n")); + gid_used++; gr = getgrgid(gid); gids[x] = gid; - gid_used++; - if (gr) { - gnames[x] = xstrdup(gr->gr_name); - } else { - gnames[x] = NULL; - } + gnames[x] = (gr ? xstrdup(gr->gr_name) : NULL); return gnames[x]; } @@ -111,34 +95,28 @@ const char *getGnameS(const char *gname) int x; for (x = 0; x < gid_used; x++) { - if (!strcmp(gnames[x], gname)) { + if (!strcmp(gnames[x], gname)) return gnames[x]; - } } /* XXX - This is the other hard coded limit */ if (x == 1024) rpmlog(RPMLOG_CRIT, _("getGnameS: too many gid's\n")); + gid_used++; gr = getgrnam(gname); - gid_used++; - if (gr) { - gids[x] = gr->gr_gid; - gnames[x] = xstrdup(gr->gr_name); - } else { - gids[x] = -1; - gnames[x] = xstrdup(gname); - } + gids[x] = (gr ? gr->gr_gid : -1); + gnames[x] = (gr ? xstrdup(gr->gr_name) : xstrdup(gname)); return gnames[x]; } time_t *const getBuildTime(void) { - static time_t buildTime = 0; + static time_t buildTime[1]; - if (! buildTime) - buildTime = time(NULL); - return &buildTime; + if (buildTime[0] == 0) + buildTime[0] = time(NULL); + return buildTime; } const char *const buildHost(void) @@ -149,12 +127,11 @@ const char *const buildHost(void) if (! gotit) { gethostname(hostname, sizeof(hostname)); - if ((hbn = /*@-unrecog@*/ gethostbyname(hostname) /*@=unrecog@*/ )) { + if ((hbn = /*@-unrecog@*/ gethostbyname(hostname) /*@=unrecog@*/ )) strcpy(hostname, hbn->h_name); - } else { - rpmMessage(RPMMESS_WARNING, _("Could not canonicalize hostname: %s\n"), - hostname); - } + else + rpmMessage(RPMMESS_WARNING, + _("Could not canonicalize hostname: %s\n"), hostname); gotit = 1; } return(hostname); diff --git a/build/pack.c b/build/pack.c index f6dd4aa72..43fc29a23 100644 --- a/build/pack.c +++ b/build/pack.c @@ -41,7 +41,8 @@ static inline int genSourceRpmName(Spec spec) /** * @todo Create transaction set *much* earlier. */ -static int cpio_doio(FD_t fdo, Header h, CSA_t * csa, const char * fmodeMacro) +static int cpio_doio(FD_t fdo, /*@unused@*/ Header h, CSA_t * csa, + const char * fmodeMacro) { const char * rootDir = "/"; rpmdb rpmdb = NULL; @@ -68,9 +69,8 @@ static int cpio_doio(FD_t fdo, Header h, CSA_t * csa, const char * fmodeMacro) rc = 1; } - if (failedFile) - free((void *)failedFile); - free((void *)fmode); + failedFile = _free(failedFile); + fmode = _free(fmode); rpmtransFree(ts); return rc; @@ -111,7 +111,7 @@ static StringBuf addFileToTagAux(Spec spec, const char *file, StringBuf sb) fn = rpmGetPath("%{_builddir}/", spec->buildSubdir, "/", file, NULL); fd = Fopen(fn, "r.ufdio"); - if (fn != buf) free((void *)fn); + if (fn != buf) fn = _free(fn); if (fd == NULL || Ferror(fd)) { freeStringBuf(sb); return NULL; @@ -131,12 +131,13 @@ static StringBuf addFileToTagAux(Spec spec, const char *file, StringBuf sb) /** */ -static int addFileToTag(Spec spec, const char *file, Header h, int tag) +static int addFileToTag(Spec spec, const char * file, Header h, int tag) { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; StringBuf sb = newStringBuf(); char *s; - if (headerGetEntry(h, tag, NULL, (void **)&s, NULL)) { + if (hge(h, tag, NULL, (void **)&s, NULL)) { appendLineStringBuf(sb, s); headerRemoveEntry(h, tag); } @@ -152,7 +153,7 @@ static int addFileToTag(Spec spec, const char *file, Header h, int tag) /** */ -static int addFileToArrayTag(Spec spec, char *file, Header h, int tag) +static int addFileToArrayTag(Spec spec, const char *file, Header h, int tag) { StringBuf sb = newStringBuf(); char *s; @@ -351,7 +352,7 @@ int writeRPM(Header *hdrp, const char *fileName, int type, break; } if (!(rpmio_flags && *rpmio_flags)) { - if (rpmio_flags) free((void *)rpmio_flags); + rpmio_flags = _free(rpmio_flags); rpmio_flags = xstrdup("w9.gzdio"); } s = strchr(rpmio_flags, '.'); @@ -402,7 +403,7 @@ int writeRPM(Header *hdrp, const char *fileName, int type, rc = RPMERR_BADARG; } } - if (rpmio_flags) free((void *)rpmio_flags); + rpmio_flags = _free(rpmio_flags); if (rc) goto exit; @@ -416,8 +417,9 @@ int writeRPM(Header *hdrp, const char *fileName, int type, * to memory not in the region. <shrug> */ if (Fileno(csa->cpioFdIn) < 0) { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; int_32 * archiveSize; - if (headerGetEntry(h, RPMTAG_ARCHIVESIZE, NULL, (void *)&archiveSize, NULL)) + if (hge(h, RPMTAG_ARCHIVESIZE, NULL, (void *)&archiveSize, NULL)) *archiveSize = csa->cpioArchiveSize; } @@ -564,7 +566,7 @@ exit: } if (sigtarget) { Unlink(sigtarget); - free((void *)sigtarget); + sigtarget = _free(sigtarget); } if (rc == 0) @@ -618,7 +620,7 @@ int packageBinaries(Spec spec) { const char * optflags = rpmExpand("%{optflags}", NULL); headerAddEntry(pkg->header, RPMTAG_OPTFLAGS, RPM_STRING_TYPE, optflags, 1); - free((void *)optflags); + optflags = _free(optflags); } genSourceRpmName(spec); @@ -629,7 +631,7 @@ int packageBinaries(Spec spec) char *binRpm, *binDir; binRpm = headerSprintf(pkg->header, binFormat, rpmTagTable, rpmHeaderFormats, &errorString); - free((void *)binFormat); + binFormat = _free(binFormat); if (binRpm == NULL) { const char *name; headerNVR(pkg->header, &name, NULL, NULL); @@ -655,9 +657,9 @@ int packageBinaries(Spec spec) break; } } - free((void *)dn); + dn = _free(dn); } - free((void *)binRpm); + binRpm = _free(binRpm); } memset(csa, 0, sizeof(*csa)); @@ -668,7 +670,7 @@ int packageBinaries(Spec spec) rc = writeRPM(&pkg->header, fn, RPMLEAD_BINARY, csa, spec->passPhrase, NULL); csa->cpioFdIn = fdFree(csa->cpioFdIn, "init (packageBinaries)"); - free((void *)fn); + fn = _free(fn); if (rc) return rc; } @@ -691,7 +693,7 @@ int packageSources(Spec spec) genSourceRpmName(spec); - FREE(spec->cookie); + spec->cookie = _free(spec->cookie); /* XXX this should be %_srpmdir */ { const char *fn = rpmGetPath("%{_srcrpmdir}/", spec->sourceRpmName,NULL); @@ -704,7 +706,7 @@ int packageSources(Spec spec) rc = writeRPM(&spec->sourceHeader, fn, RPMLEAD_SOURCE, csa, spec->passPhrase, &(spec->cookie)); csa->cpioFdIn = fdFree(csa->cpioFdIn, "init (packageSources)"); - free((void *)fn); + fn = _free(fn); } return rc; } diff --git a/build/parseChangelog.c b/build/parseChangelog.c index 0c81fcd49..19cb19e2c 100644 --- a/build/parseChangelog.c +++ b/build/parseChangelog.c @@ -161,7 +161,7 @@ static int addChangelog(Header h, StringBuf sb) /* name */ name = s; while (*s) s++; - while (s > name && isspace(*s)) { + while (s > name && xisspace(*s)) { *s-- = '\0'; } if (s == name) { @@ -185,7 +185,7 @@ static int addChangelog(Header h, StringBuf sb) s--; /* backup to end of description */ - while ((s > text) && isspace(*s)) { + while ((s > text) && xisspace(*s)) { *s-- = '\0'; } diff --git a/build/parseDescription.c b/build/parseDescription.c index 8cf5ae537..f7052e2df 100644 --- a/build/parseDescription.c +++ b/build/parseDescription.c @@ -53,7 +53,7 @@ int parseDescription(Spec spec) spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), spec->line); - FREE(argv); + argv = _free(argv); poptFreeContext(optCon); return RPMERR_BADSPEC; } @@ -65,7 +65,7 @@ int parseDescription(Spec spec) rpmError(RPMERR_BADSPEC, _("line %d: Too many names: %s\n"), spec->lineNum, spec->line); - FREE(argv); + argv = _free(argv); poptFreeContext(optCon); return RPMERR_BADSPEC; } @@ -74,7 +74,7 @@ int parseDescription(Spec spec) if (lookupPackage(spec, name, flag, &pkg)) { rpmError(RPMERR_BADSPEC, _("line %d: Package does not exist: %s\n"), spec->lineNum, spec->line); - FREE(argv); + argv = _free(argv); poptFreeContext(optCon); return RPMERR_BADSPEC; } @@ -86,7 +86,7 @@ int parseDescription(Spec spec) if (headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) { rpmError(RPMERR_BADSPEC, _("line %d: Second description\n"), spec->lineNum); - FREE(argv); + argv = _free(argv); poptFreeContext(optCon); return RPMERR_BADSPEC; } @@ -124,7 +124,7 @@ int parseDescription(Spec spec) freeStringBuf(sb); - FREE(argv); + argv = _free(argv); poptFreeContext(optCon); return nextPart; diff --git a/build/parseFiles.c b/build/parseFiles.c index b948ba205..df3e8d9ec 100644 --- a/build/parseFiles.c +++ b/build/parseFiles.c @@ -105,8 +105,7 @@ int parseFiles(Spec spec) rc = nextPart; exit: - if (argv) - FREE(argv); + argv = _free(argv); if (optCon) poptFreeContext(optCon); diff --git a/build/parsePreamble.c b/build/parsePreamble.c index 19d272f5c..73b5de67a 100644 --- a/build/parsePreamble.c +++ b/build/parsePreamble.c @@ -53,7 +53,7 @@ static void addOrAppendListEntry(Header h, int_32 tag, char *line) poptParseArgvString(line, &argc, &argv); if (argc) headerAddOrAppendEntry(h, tag, RPM_STRING_ARRAY_TYPE, argv, argc); - FREE(argv); + argv = _free(argv); } /* Parse a simple part line that only take -n <pkg> or <pkg> */ @@ -99,14 +99,14 @@ static inline int parseYesNo(const char *s) ? 0 : 1); } -struct tokenBits { +typedef struct tokenBits_s { const char * name; - int bits; -}; + rpmsenseFlags bits; +} * tokenBits; /** */ -static struct tokenBits installScriptBits[] = { +static struct tokenBits_s installScriptBits[] = { { "interp", RPMSENSE_INTERP }, { "prereq", RPMSENSE_PREREQ }, { "preun", RPMSENSE_SCRIPT_PREUN }, @@ -120,7 +120,7 @@ static struct tokenBits installScriptBits[] = { /** */ -static struct tokenBits buildScriptBits[] = { +static struct tokenBits_s buildScriptBits[] = { { "prep", RPMSENSE_SCRIPT_PREP }, { "build", RPMSENSE_SCRIPT_BUILD }, { "install", RPMSENSE_SCRIPT_INSTALL }, @@ -130,18 +130,19 @@ static struct tokenBits buildScriptBits[] = { /** */ -static int parseBits(const char * s, struct tokenBits * tokbits, int * bp) +static int parseBits(const char * s, const tokenBits tokbits, + /*@out@*/ rpmsenseFlags * bp) { - struct tokenBits *tb; - const char *se; - int bits = 0; + tokenBits tb; + const char * se; + rpmsenseFlags bits = RPMSENSE_ANY; int c = 0; if (s) { while (*s) { - while ((c = *s) && isspace(c)) s++; + while ((c = *s) && xisspace(c)) s++; se = s; - while ((c = *se) && isalpha(c)) se++; + while ((c = *se) && xisalpha(c)) se++; if (s == se) break; for (tb = tokbits; tb->name; tb++) { @@ -151,7 +152,7 @@ static int parseBits(const char * s, struct tokenBits * tokbits, int * bp) if (tb->name == NULL) break; bits |= tb->bits; - while ((c = *se) && isspace(c)) se++; + while ((c = *se) && xisspace(c)) se++; if (c != ',') break; s = ++se; @@ -168,7 +169,7 @@ static inline char * findLastChar(char * s) char *res = s; while (*s) { - if (! isspace(*s)) + if (! xisspace(*s)) res = s; s++; } @@ -180,16 +181,18 @@ static inline char * findLastChar(char * s) */ static int isMemberInEntry(Header header, const char *name, int tag) { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; const char ** names; - int count; + int type, count; - if (!headerGetEntry(header, tag, NULL, (void **)&names, &count)) + if (!hge(header, tag, &type, (void **)&names, &count)) return -1; while (count--) { if (!xstrcasecmp(names[count], name)) break; } - FREE(names); + names = hfd(names, type); return (count >= 0 ? 1 : 0); } @@ -302,7 +305,7 @@ static void fillOutMainPackage(Header h) const char *val = rpmExpand(ot->ot_mac, NULL); if (val && *val != '%') headerAddEntry(h, ot->ot_tag, RPM_STRING_TYPE, (void *)val, 1); - free((void *)val); + val = _free(val); } } } @@ -358,16 +361,17 @@ static int readIcon(Header h, const char *file) rc = RPMERR_BADSPEC; goto exit; } - free((void *)icon); + icon = _free(icon); exit: - FREE(fn); + fn = _free(fn); return rc; } struct spectag * stashSt(Spec spec, Header h, int tag, const char *lang) { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; struct spectag *t = NULL; if (spec->st) { @@ -384,7 +388,7 @@ stashSt(Spec spec, Header h, int tag, const char *lang) t->t_msgid = NULL; if (!(t->t_lang && strcmp(t->t_lang, RPMBUILD_DEFAULT_LANG))) { char *n; - if (headerGetEntry(h, RPMTAG_NAME, NULL, (void **) &n, NULL)) { + if (hge(h, RPMTAG_NAME, NULL, (void **) &n, NULL)) { char buf[1024]; sprintf(buf, "%s(%s)", n, tagName(tag)); t->t_msgid = xstrdup(buf); @@ -408,11 +412,14 @@ extern int noLang; /* XXX FIXME: pass as arg */ static int handlePreambleTag(Spec spec, Package pkg, int tag, const char *macro, const char *lang) { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; char *field = spec->line; char *end; char **array; int multiToken = 0; - int tagflags; + rpmsenseFlags tagflags; + int type; int len; int num; int rc; @@ -499,7 +506,7 @@ static int handlePreambleTag(Spec spec, Package pkg, int tag, const char *macro, } else { const char * specURL = field; - free((void *)buildRootURL); + buildRootURL = _free(buildRootURL); (void) urlPath(specURL, (const char **)&field); if (*field == '\0') field = "/"; buildRootURL = rpmGenPath(spec->rootURL, field, NULL); @@ -516,25 +523,25 @@ static int handlePreambleTag(Spec spec, Package pkg, int tag, const char *macro, if (!strcmp(buildRoot, "/")) { rpmError(RPMERR_BADSPEC, _("BuildRoot can not be \"/\": %s\n"), spec->buildRootURL); - free((void *)buildRootURL); + buildRootURL = _free(buildRootURL); return RPMERR_BADSPEC; } - free((void *)buildRootURL); + buildRootURL = _free(buildRootURL); } break; case RPMTAG_PREFIXES: addOrAppendListEntry(pkg->header, tag, field); - headerGetEntry(pkg->header, tag, NULL, (void **)&array, &num); + hge(pkg->header, tag, &type, (void **)&array, &num); while (num--) { len = strlen(array[num]); if (array[num][len - 1] == '/' && len > 1) { rpmError(RPMERR_BADSPEC, _("line %d: Prefixes must not end with \"/\": %s\n"), spec->lineNum, spec->line); - FREE(array); + array = hfd(array, type); return RPMERR_BADSPEC; } } - FREE(array); + array = hfd(array, type); break; case RPMTAG_DOCDIR: SINGLE_TOKEN_ONLY; @@ -614,7 +621,7 @@ static int handlePreambleTag(Spec spec, Package pkg, int tag, const char *macro, case RPMTAG_CONFLICTFLAGS: case RPMTAG_OBSOLETEFLAGS: case RPMTAG_PROVIDEFLAGS: - tagflags = 0; + tagflags = RPMSENSE_ANY; if ((rc = parseRCPOT(spec, pkg, field, tag, 0, tagflags))) return rc; break; @@ -634,7 +641,7 @@ static int handlePreambleTag(Spec spec, Package pkg, int tag, const char *macro, return RPMERR_BADSPEC; } if (!spec->buildArchitectureCount) - FREE(spec->buildArchitectures); + spec->buildArchitectures = _free(spec->buildArchitectures); break; default: @@ -748,7 +755,7 @@ static int findPreambleTag(Spec spec, /*@out@*/int *tag, /*@out@*/char **macro, if (*s != '(') return 1; s++; SKIPSPACE(s); - while (!isspace(*s) && *s != ')') + while (!xisspace(*s) && *s != ')') *lang++ = *s++; *lang = '\0'; SKIPSPACE(s); diff --git a/build/parsePrep.c b/build/parsePrep.c index 63b113667..cd61a2f0c 100644 --- a/build/parsePrep.c +++ b/build/parsePrep.c @@ -14,8 +14,8 @@ /* These have to be global to make up for stupid compilers */ static int leaveDirs, skipDefaultAction; static int createDir, quietly; - /*@observer@*/ /*@null@*/ static const char * dirName = NULL; - static struct poptOption optionsTable[] = { +/*@observer@*/ /*@null@*/ static const char * dirName = NULL; +/*@observer@*/ static struct poptOption optionsTable[] = { { NULL, 'a', POPT_ARG_STRING, NULL, 'a', NULL, NULL}, { NULL, 'b', POPT_ARG_STRING, NULL, 'b', NULL, NULL}, { NULL, 'c', 0, &createDir, 0, NULL, NULL}, @@ -78,7 +78,7 @@ static int checkOwners(const char *urlfn) return NULL; } - fn = urlfn = rpmGetPath("%{_sourcedir}/", sp->source, NULL); + urlfn = rpmGetPath("%{_sourcedir}/", sp->source, NULL); args[0] = '\0'; if (db) { @@ -97,10 +97,11 @@ static int checkOwners(const char *urlfn) /* XXX On non-build parse's, file cannot be stat'd or read */ if (!spec->force && (isCompressed(urlfn, &compressed) || checkOwners(urlfn))) { - free((void *)urlfn); + urlfn = _free(urlfn); return NULL; } + fn = NULL; urltype = urlPath(urlfn, &fn); switch (urltype) { case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */ @@ -109,7 +110,7 @@ static int checkOwners(const char *urlfn) case URL_IS_UNKNOWN: break; case URL_IS_DASH: - free((void *)urlfn); + urlfn = _free(urlfn); return NULL; /*@notreached@*/ break; } @@ -126,10 +127,10 @@ static int checkOwners(const char *urlfn) "if [ $STATUS -ne 0 ]; then\n" " exit $STATUS\n" "fi", - c, (const char *) basename(fn), + c, /*@-unrecog@*/ (const char *) basename(fn), /*@=unrecog@*/ zipper, fn, strip, args); - free((void *)zipper); + zipper = _free(zipper); } else { sprintf(buf, "echo \"Patch #%d (%s):\"\n" @@ -137,7 +138,7 @@ static int checkOwners(const char *urlfn) strip, args, fn); } - free((void *)urlfn); + urlfn = _free(urlfn); return buf; } @@ -168,7 +169,7 @@ static int checkOwners(const char *urlfn) return NULL; } - fn = urlfn = rpmGetPath("%{_sourcedir}/", sp->source, NULL); + urlfn = rpmGetPath("%{_sourcedir}/", sp->source, NULL); taropts = ((rpmIsVerbose() && !quietly) ? "-xvvf" : "-xf"); @@ -194,10 +195,11 @@ static int checkOwners(const char *urlfn) /* XXX On non-build parse's, file cannot be stat'd or read */ if (!spec->force && (isCompressed(urlfn, &compressed) || checkOwners(urlfn))) { - free((void *)urlfn); + urlfn = _free(urlfn); return NULL; } + fn = NULL; urltype = urlPath(urlfn, &fn); switch (urltype) { case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */ @@ -206,7 +208,7 @@ static int checkOwners(const char *urlfn) case URL_IS_UNKNOWN: break; case URL_IS_DASH: - free((void *)urlfn); + urlfn = _free(urlfn); return NULL; /*@notreached@*/ break; } @@ -231,7 +233,7 @@ static int checkOwners(const char *urlfn) zipper = rpmGetPath(t, NULL); buf[0] = '\0'; t = stpcpy(buf, zipper); - free((void *)zipper); + zipper = _free(zipper); *t++ = ' '; t = stpcpy(t, fn); if (needtar) @@ -249,7 +251,7 @@ static int checkOwners(const char *urlfn) t = stpcpy(t, fn); } - free((void *)urlfn); + urlfn = _free(urlfn); return buf; } @@ -295,10 +297,10 @@ static int doSetupMacro(Spec spec, char *line) if (parseNum(optArg, &num)) { rpmError(RPMERR_BADSPEC, _("line %d: Bad arg to %%setup %c: %s\n"), spec->lineNum, num, optArg); - free(argv); freeStringBuf(before); freeStringBuf(after); poptFreeContext(optCon); + argv = _free(argv); return RPMERR_BADSPEC; } @@ -315,10 +317,10 @@ static int doSetupMacro(Spec spec, char *line) spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(arg)); - free(argv); freeStringBuf(before); freeStringBuf(after); poptFreeContext(optCon); + argv = _free(argv); return RPMERR_BADSPEC; } @@ -332,8 +334,8 @@ static int doSetupMacro(Spec spec, char *line) } addMacro(spec->macros, "buildsubdir", NULL, spec->buildSubdir, RMIL_SPEC); - free(argv); poptFreeContext(optCon); + argv = _free(argv); /* cd to the build dir */ { const char * buildDirURL = rpmGenPath(spec->rootURL, "%{_builddir}", ""); @@ -342,7 +344,7 @@ static int doSetupMacro(Spec spec, char *line) (void) urlPath(buildDirURL, &buildDir); sprintf(buf, "cd %s", buildDir); appendLineStringBuf(spec->prep, buf); - free((void *)buildDirURL); + buildDirURL = _free(buildDirURL); } /* delete any old sources */ @@ -395,7 +397,7 @@ static int doSetupMacro(Spec spec, char *line) const char *fix = rpmExpand(*fm, " .", NULL); if (fix && *fix != '%') appendLineStringBuf(spec->prep, fix); - free((void *)fix); + fix = _free(fix); } } @@ -431,8 +433,8 @@ static int doPatchMacro(Spec spec, char *line) for (bp = buf; (s = strtok(bp, " \t\n")) != NULL;) { if (bp) { /* remove 1st token (%patch) */ - bp = NULL; - continue; + bp = NULL; + continue; } if (!strcmp(s, "-P")) { opt_P = 1; @@ -496,17 +498,15 @@ static int doPatchMacro(Spec spec, char *line) if (! opt_P) { s = doPatch(spec, 0, opt_p, opt_b, opt_R, opt_E); - if (s == NULL) { + if (s == NULL) return RPMERR_BADSPEC; - } appendLineStringBuf(spec->prep, s); } for (x = 0; x < patch_index; x++) { s = doPatch(spec, patch_nums[x], opt_p, opt_b, opt_R, opt_E); - if (s == NULL) { + if (s == NULL) return RPMERR_BADSPEC; - } appendLineStringBuf(spec->prep, s); } @@ -530,9 +530,8 @@ int parsePrep(Spec spec) if ((rc = readLine(spec, STRIP_NOTHING)) > 0) { return PART_NONE; } - if (rc) { + if (rc) return rc; - } buf = newStringBuf(); @@ -544,9 +543,8 @@ int parsePrep(Spec spec) nextPart = PART_NONE; break; } - if (rc) { + if (rc) return rc; - } } saveLines = splitString(getStringBuf(buf), strlen(getStringBuf(buf)), '\n'); diff --git a/build/parseReqs.c b/build/parseReqs.c index 042f570b5..5e2f1ab1c 100644 --- a/build/parseReqs.c +++ b/build/parseReqs.c @@ -11,8 +11,8 @@ /** */ static struct ReqComp { - char *token; - int sense; + const char * token; + rpmsenseFlags sense; } ReqComparisons[] = { { "<=", RPMSENSE_LESS | RPMSENSE_EQUAL}, { "=<", RPMSENSE_LESS | RPMSENSE_EQUAL}, @@ -28,16 +28,16 @@ static struct ReqComp { { NULL, 0 }, }; -#define SKIPWHITE(_x) {while(*(_x) && (isspace(*_x) || *(_x) == ',')) (_x)++;} -#define SKIPNONWHITE(_x){while(*(_x) &&!(isspace(*_x) || *(_x) == ',')) (_x)++;} +#define SKIPWHITE(_x) {while(*(_x) && (xisspace(*_x) || *(_x) == ',')) (_x)++;} +#define SKIPNONWHITE(_x){while(*(_x) &&!(xisspace(*_x) || *(_x) == ',')) (_x)++;} int parseRCPOT(Spec spec, Package pkg, const char *field, int tag, - int index, int tagflags) + int index, rpmsenseFlags tagflags) { const char *r, *re, *v, *ve; - char *req, *version; + char * req, * version; Header h; - int flags; + rpmsenseFlags flags; switch (tag) { case RPMTAG_PROVIDEFLAGS: @@ -95,7 +95,7 @@ int parseRCPOT(Spec spec, Package pkg, const char *field, int tag, flags = (tagflags & ~RPMSENSE_SENSEMASK); /* Tokens must begin with alphanumeric, _, or / */ - if (!(isalnum(r[0]) || r[0] == '_' || r[0] == '/')) { + if (!(xisalnum(r[0]) || r[0] == '_' || r[0] == '/')) { rpmError(RPMERR_BADSPEC, _("line %d: Dependency tokens must begin with alpha-numeric, '_' or '/': %s\n"), spec->lineNum, spec->line); @@ -183,8 +183,8 @@ int parseRCPOT(Spec spec, Package pkg, const char *field, int tag, addReqProv(spec, h, flags, req, version, index); - if (req) free(req); - if (version) free(version); + req = _free(req); + version = _free(version); } diff --git a/build/parseScript.c b/build/parseScript.c index 9abd7fb0e..6476f997c 100644 --- a/build/parseScript.c +++ b/build/parseScript.c @@ -293,12 +293,8 @@ int parseScript(Spec spec, int parsePart) exit: if (sb) freeStringBuf(sb); - if (progArgv) { - FREE(progArgv); - } - if (argv) { - FREE(argv); - } + progArgv = _free(progArgv); + argv = _free(argv); if (optCon) poptFreeContext(optCon); diff --git a/build/parseSpec.c b/build/parseSpec.c index 37428b9c5..d81d23222 100644 --- a/build/parseSpec.c +++ b/build/parseSpec.c @@ -60,7 +60,7 @@ rpmParseState isPart(const char *line) if (xstrncasecmp(line, p->token, p->len)) continue; c = *(line + p->len); - if (c == '\0' || isspace(c)) + if (c == '\0' || xisspace(c)) break; } @@ -147,7 +147,7 @@ static int copyNextLine(Spec spec, OFI_t *ofi, int strip) ch = ' '; while (*spec->nextline && ch != '\n') { ch = *spec->nextline++; - if (!isspace(ch)) + if (!xisspace(ch)) last = spec->nextline; } @@ -203,8 +203,8 @@ retry: /* remove this file from the stack */ spec->fileStack = ofi->next; Fclose(ofi->fd); - FREE(ofi->fileName); - free(ofi); + ofi->fileName = _free(ofi->fileName); + ofi = _free(ofi); /* only on last file do we signal EOF to caller */ ofi = spec->fileStack; @@ -247,22 +247,22 @@ retry: const char *arch = rpmExpand("%{_target_cpu}", NULL); s += 7; match = matchTok(arch, s); - free((void *)arch); + arch = _free(arch); } else if (! strncmp("%ifnarch", s, sizeof("%ifnarch")-1)) { const char *arch = rpmExpand("%{_target_cpu}", NULL); s += 8; match = !matchTok(arch, s); - free((void *)arch); + arch = _free(arch); } else if (! strncmp("%ifos", s, sizeof("%ifos")-1)) { const char *os = rpmExpand("%{_target_os}", NULL); s += 5; match = matchTok(os, s); - free((void *)os); + os = _free(os); } else if (! strncmp("%ifnos", s, sizeof("%ifnos")-1)) { const char *os = rpmExpand("%{_target_os}", NULL); s += 6; match = !matchTok(os, s); - free((void *)os); + os = _free(os); } else if (! strncmp("%if", s, sizeof("%if")-1)) { s += 3; match = parseExpressionBoolean(spec, s); @@ -302,7 +302,7 @@ retry: s += 8; fileName = s; - if (! isspace(*fileName)) { + if (! xisspace(*fileName)) { rpmError(RPMERR_BADSPEC, _("malformed %%include statement\n")); return RPMERR_BADSPEC; } @@ -346,8 +346,8 @@ void closeSpec(Spec spec) ofi = spec->fileStack; spec->fileStack = spec->fileStack->next; if (ofi->fd) Fclose(ofi->fd); - FREE(ofi->fileName); - free(ofi); + ofi->fileName = _free(ofi->fileName); + ofi = _free(ofi); } } @@ -482,7 +482,7 @@ fprintf(stderr, "*** PS buildRootURL(%s) %p macro set to %s\n", spec->buildRootU } #ifdef DYING rpmSetMachine(saveArch, NULL); - free((void *)saveArch); + saveArch = _free(saveArch); #else delMacro(NULL, "_target_cpu"); #endif @@ -557,10 +557,10 @@ fprintf(stderr, "*** PS buildRootURL(%s) %p macro set to %s\n", spec->buildRootU headerAddEntry(pkg->header, RPMTAG_ARCH, RPM_STRING_TYPE, arch, 1); } #ifdef DYING - FREE(myos); + myos = _free(myos); #else - free((void *)arch); - free((void *)os); + arch = _free(arch); + os = _free(os); #endif } diff --git a/build/reqprov.c b/build/reqprov.c index 5ee4b96a9..6eeb80ec7 100644 --- a/build/reqprov.c +++ b/build/reqprov.c @@ -9,15 +9,19 @@ #include "debug.h" int addReqProv(/*@unused@*/ Spec spec, Header h, - int depFlags, const char *depName, const char *depEVR, int index) + rpmsenseFlags depFlags, const char *depName, const char *depEVR, + int index) { - const char **names; + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; + const char ** names; + int dnt; int nametag = 0; int versiontag = 0; int flagtag = 0; int indextag = 0; int len; - int extra = 0; + rpmsenseFlags extra = RPMSENSE_ANY; if (depFlags & RPMSENSE_PROVIDES) { nametag = RPMTAG_PROVIDENAME; @@ -56,18 +60,19 @@ int addReqProv(/*@unused@*/ Spec spec, Header h, depEVR = ""; /* Check for duplicate dependencies. */ - if (headerGetEntry(h, nametag, NULL, (void **) &names, &len)) { - const char **versions = NULL; + if (hge(h, nametag, &dnt, (void **) &names, &len)) { + const char ** versions = NULL; + int dvt; int *flags = NULL; int *indexes = NULL; int duplicate = 0; if (flagtag) { - headerGetEntry(h, versiontag, NULL, (void **) &versions, NULL); - headerGetEntry(h, flagtag, NULL, (void **) &flags, NULL); + hge(h, versiontag, &dvt, (void **) &versions, NULL); + hge(h, flagtag, NULL, (void **) &flags, NULL); } if (indextag) - headerGetEntry(h, indextag, NULL, (void **) &indexes, NULL); + hge(h, indextag, NULL, (void **) &indexes, NULL); while (len > 0) { len--; @@ -89,8 +94,8 @@ int addReqProv(/*@unused@*/ Spec spec, Header h, break; } - FREE(names); - FREE(versions); + names = hfd(names, dnt); + versions = hfd(versions, dvt); if (duplicate) return 0; } diff --git a/build/rpmbuild.h b/build/rpmbuild.h index 724a420e1..34ce244e5 100644 --- a/build/rpmbuild.h +++ b/build/rpmbuild.h @@ -19,6 +19,7 @@ * Bit(s) to control buildSpec() operation. */ typedef enum rpmBuildFlags_e { + RPMBUILD_NONE = 0, RPMBUILD_PREP = (1 << 0), /*!< Execute %%prep. */ RPMBUILD_BUILD = (1 << 1), /*!< Execute %%build. */ RPMBUILD_INSTALL = (1 << 2), /*!< Execute %%install. */ @@ -34,9 +35,8 @@ typedef enum rpmBuildFlags_e { #include <ctype.h> -#define FREE(x) { if (x) free((void *)x); x = NULL; } -#define SKIPSPACE(s) { while (*(s) && isspace(*(s))) (s)++; } -#define SKIPNONSPACE(s) { while (*(s) && !isspace(*(s))) (s)++; } +#define SKIPSPACE(s) { while (*(s) && xisspace(*(s))) (s)++; } +#define SKIPNONSPACE(s) { while (*(s) && !xisspace(*(s))) (s)++; } #define PART_SUBNAME 0 #define PART_NAME 1 @@ -222,7 +222,7 @@ int parsePrep(Spec spec); * @return 0 on success, RPMERR_BADSPEC on failure */ int parseRCPOT(Spec spec, Package pkg, const char *field, int tag, int index, - int flags); + rpmsenseFlags flags); /** \ingroup rpmbuild * Parse %%pre et al scriptlets from a spec file. @@ -310,7 +310,8 @@ void freePackage(/*@only@*/ Package pkg); * @return 0 always */ int addReqProv(/*@unused@*/Spec spec, Header h, - int flag, const char *depName, const char *depEVR, int index); + rpmsenseFlags flag, const char *depName, const char *depEVR, + int index); /** \ingroup rpmbuild * Add rpmlib feature dependency. diff --git a/build/spec.c b/build/spec.c index 037f85f04..153ad2e15 100644 --- a/build/spec.c +++ b/build/spec.c @@ -12,8 +12,8 @@ extern int specedit; extern MacroContext rpmGlobalMacroContext; -#define SKIPWHITE(_x) {while(*(_x) && (isspace(*_x) || *(_x) == ',')) (_x)++;} -#define SKIPNONWHITE(_x){while(*(_x) &&!(isspace(*_x) || *(_x) == ',')) (_x)++;} +#define SKIPWHITE(_x) {while(*(_x) && (xisspace(*_x) || *(_x) == ',')) (_x)++;} +#define SKIPNONWHITE(_x){while(*(_x) &&!(xisspace(*_x) || *(_x) == ',')) (_x)++;} /*@access Header @*/ /* compared with NULL */ @@ -26,10 +26,10 @@ static inline void freeTriggerFiles(/*@only@*/ struct TriggerFileEntry *p) while (q != NULL) { o = q; q = q->next; - FREE(o->fileName); - FREE(o->script); - FREE(o->prog); - free(o); + o->fileName = _free(o->fileName); + o->script = _free(o->script); + o->prog = _free(o->prog); + o = _free(o); } } @@ -42,8 +42,8 @@ static inline void freeSources(/*@only@*/ struct Source *s) while (t != NULL) { r = t; t = t->next; - FREE(r->fullSource); - free(r); + r->fullSource = _free(r->fullSource); + r = _free(r); } } @@ -138,21 +138,21 @@ void freePackage(/*@only@*/ Package p) if (p == NULL) return; - FREE(p->preInFile); - FREE(p->postInFile); - FREE(p->preUnFile); - FREE(p->postUnFile); - FREE(p->verifyFile); + p->preInFile = _free(p->preInFile); + p->postInFile = _free(p->postInFile); + p->preUnFile = _free(p->preUnFile); + p->postUnFile = _free(p->postUnFile); + p->verifyFile = _free(p->verifyFile); headerFree(p->header); freeStringBuf(p->fileList); - FREE(p->fileFile); + p->fileFile = _free(p->fileFile); if (p->cpioList) { TFI_t fi = p->cpioList; + p->cpioList = NULL; freeFi(fi); - free((void *)fi); + fi = _free(fi); } - p->cpioList = NULL; freeStringBuf(p->specialDoc); @@ -160,7 +160,7 @@ void freePackage(/*@only@*/ Package p) freeTriggerFiles(p->triggerFiles); - free(p); + p = _free(p); } void freePackages(Spec spec) @@ -317,7 +317,7 @@ int addSource(Spec spec, Package pkg, const char *field, int tag) sprintf(buf, "%sURL%d", (flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num); addMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC); - free((void *)body); + body = _free(body); } return 0; @@ -345,9 +345,9 @@ static inline void freeSl(/*@only@*/struct speclines *sl) if (sl == NULL) return; for (i = 0; i < sl->sl_nlines; i++) - FREE(sl->sl_lines[i]); - FREE(sl->sl_lines); - free(sl); + sl->sl_lines[i] = _free(sl->sl_lines[i]); + sl->sl_lines = _free(sl->sl_lines); + sl = _free(sl); } /** @@ -373,18 +373,16 @@ static inline void freeSt(/*@only@*/struct spectags *st) return; for (i = 0; i < st->st_ntags; i++) { struct spectag *t = st->st_t + i; - FREE(t->t_lang); - FREE(t->t_msgid); + t->t_lang = _free(t->t_lang); + t->t_msgid = _free(t->t_msgid); } - FREE(st->st_t); - free(st); + st->st_t = _free(st->st_t); + st = _free(st); } Spec newSpec(void) { - Spec spec; - - spec = (Spec)xmalloc(sizeof *spec); + Spec spec = xcalloc(1, sizeof(*spec)); spec->specFile = NULL; spec->sourceRpmName = NULL; @@ -398,7 +396,7 @@ Spec newSpec(void) spec->nextline = NULL; spec->nextpeekc = '\0'; spec->lineNum = 0; - spec->readStack = xmalloc(sizeof(struct ReadLevelEntry)); + spec->readStack = xcalloc(1, sizeof(*spec->readStack)); spec->readStack->next = NULL; spec->readStack->reading = 1; @@ -452,25 +450,25 @@ void freeSpec(/*@only@*/ Spec spec) freeStringBuf(spec->install); spec->install = NULL; freeStringBuf(spec->clean); spec->clean = NULL; - FREE(spec->buildRootURL); - FREE(spec->buildSubdir); - FREE(spec->rootURL); - FREE(spec->specFile); - FREE(spec->sourceRpmName); + spec->buildRootURL = _free(spec->buildRootURL); + spec->buildSubdir = _free(spec->buildSubdir); + spec->rootURL = _free(spec->rootURL); + spec->specFile = _free(spec->specFile); + spec->sourceRpmName = _free(spec->sourceRpmName); while (spec->fileStack) { ofi = spec->fileStack; - spec->fileStack = spec->fileStack->next; + spec->fileStack = ofi->next; ofi->next = NULL; - FREE(ofi->fileName); - free(ofi); + ofi->fileName = _free(ofi->fileName); + ofi = _free(ofi); } while (spec->readStack) { rl = spec->readStack; - spec->readStack = spec->readStack->next; + spec->readStack = rl->next; rl->next = NULL; - free(rl); + rl = _free(rl); } if (spec->sourceHeader != NULL) { @@ -480,10 +478,10 @@ void freeSpec(/*@only@*/ Spec spec) if (spec->sourceCpioList) { TFI_t fi = spec->sourceCpioList; + spec->sourceCpioList = NULL; freeFi(fi); - free((void *)fi); + fi = _free(fi); } - spec->sourceCpioList = NULL; headerFree(spec->buildRestrictions); spec->buildRestrictions = NULL; @@ -493,18 +491,18 @@ void freeSpec(/*@only@*/ Spec spec) freeSpec( spec->buildArchitectureSpecs[spec->buildArchitectureCount]); } - FREE(spec->buildArchitectureSpecs); + spec->buildArchitectureSpecs = _free(spec->buildArchitectureSpecs); } - FREE(spec->buildArchitectures); + spec->buildArchitectures = _free(spec->buildArchitectures); - FREE(spec->passPhrase); - FREE(spec->cookie); + spec->passPhrase = _free(spec->passPhrase); + spec->cookie = _free(spec->cookie); freeSources(spec->sources); spec->sources = NULL; freePackages(spec); closeSpec(spec); - free(spec); + spec = _free(spec); } /*@only@*/ struct OpenFileInfo * newOpenFileInfo(void) diff --git a/lib/.lclintrc b/lib/.lclintrc index fe5f5bfe3..98a171fe1 100644 --- a/lib/.lclintrc +++ b/lib/.lclintrc @@ -11,18 +11,18 @@ -unrecogcomments # don't-bother-me-yet parameters --branchstate # ~100 occurences, painful +-branchstate # ~142 occurences, painful #-immediatetrans --mustfree # alloca is painful +-mustfree # ~529 alloca is painful #-observertrans #-statictrans # not-yet normal parameters -boolops # w->n --fixedformalarray +#-fixedformalarray # md5 whines -null -predboolint # w->n --predboolothers # w->n +#-predboolothers # w->n -retvalint # w->n -type diff --git a/lib/cpio.c b/lib/cpio.c index fa5c8b100..edae3cd64 100644 --- a/lib/cpio.c +++ b/lib/cpio.c @@ -19,16 +19,6 @@ extern int _fsm_debug; /** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free - * @retval NULL always - */ -static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this) free((void *)this); - return NULL; -} - -/** * Convert string to unsigned integer (with buffer size check). * @param input string * @retval address of 1st character not processed @@ -47,7 +37,7 @@ static int strntoul(const char *str, /*@out@*/char **endptr, int base, int num) buf[num] = '\0'; ret = strtoul(buf, &end, base); - if (*end) + if (*end != '\0') *endptr = ((char *)str) + (end - buf); /* XXX discards const */ else *endptr = ((char *)str) + strlen(buf); @@ -35,6 +35,7 @@ static int _debug = 1; /* XXX if < 0 debugging, > 0 unusual error returns */ #include "debug.h" +/*@access Header@*/ /* XXX compared with NULL */ /*@access rpmdb@*/ /*@access dbiIndex@*/ /*@access dbiIndexSet@*/ @@ -52,7 +53,7 @@ static inline DBTYPE db3_to_dbtype(int dbitype) /*@notreached@*/ return DB_HASH; } -static /*@observer@*/ const char * db_strerror(int error) +static /*@observer@*/ char * db_strerror(int error) { if (error == 0) return ("Successful return: 0"); @@ -69,8 +70,11 @@ static /*@observer@*/ const char * db_strerror(int error) * Note, however, we're no longer thread-safe if it does. */ static char ebuf[40]; + char * t = ebuf; - (void)snprintf(ebuf, sizeof(ebuf), "Unknown error: %d", error); + *t = '\0'; + t = stpcpy(t, "Unknown error: "); + sprintf(t, "%d", error); return(ebuf); } } @@ -190,7 +194,7 @@ static void * doGetRecord(FD_t pkgs, unsigned int offset) compressFilelist(h); exit: - if (h) { + if (h != NULL) { uh = headerUnload(h); headerFree(h); } @@ -392,10 +396,8 @@ static int db1close(/*@only@*/ dbiIndex dbi, /*@unused@*/ unsigned int flags) } db3Free(dbi); - if (base) - free((void *)base); - if (urlfn) - free((void *)urlfn); + base = _free(base); + urlfn = _free(urlfn); return rc; } @@ -472,14 +474,8 @@ exit: } else db1close(dbi, 0); - if (base) { - free((void *)base); - base = NULL; - } - if (urlfn) { - free((void *)urlfn); - urlfn = NULL; - } + base = _free(base); + urlfn = _free(urlfn); return rc; } @@ -605,8 +605,7 @@ static int db2close(/*@only@*/ dbiIndex dbi, unsigned int flags) #endif /* __USE_DB2 || __USE_DB3 */ dbi->dbi_db = NULL; - if (urlfn) - free((void *)urlfn); + urlfn = _free(urlfn); db3Free(dbi); @@ -864,8 +863,7 @@ static int db2open(rpmdb rpmdb, int rpmtag, dbiIndex * dbip) } else db2close(dbi, 0); - if (urlfn) - free((void *)urlfn); + urlfn = _free(urlfn); return rc; } @@ -586,8 +586,7 @@ static int db3close(/*@only@*/ dbiIndex dbi, /*@unused@*/ unsigned int flags) #endif /* __USE_DB2 || __USE_DB3 */ dbi->dbi_db = NULL; - if (urlfn) - free((void *)urlfn); + urlfn = _free(urlfn); db3Free(dbi); @@ -829,8 +828,7 @@ static int db3open(/*@keep@*/ rpmdb rpmdb, int rpmtag, dbiIndex * dbip) } else db3close(dbi, 0); - if (urlfn) - free((void *)urlfn); + urlfn = _free(urlfn); return rc; } diff --git a/lib/dbconfig.c b/lib/dbconfig.c index 7fd71b6c7..ffcaa7ba4 100644 --- a/lib/dbconfig.c +++ b/lib/dbconfig.c @@ -192,15 +192,15 @@ static int dbSaveInt(const struct dbOption * opt, long aLong) { void db3Free(dbiIndex dbi) { if (dbi) { - if (dbi->dbi_root) free((void *)dbi->dbi_root); - if (dbi->dbi_home) free((void *)dbi->dbi_home); - if (dbi->dbi_file) free((void *)dbi->dbi_file); - if (dbi->dbi_subfile) free((void *)dbi->dbi_subfile); - if (dbi->dbi_errpfx) free((void *)dbi->dbi_errpfx); - if (dbi->dbi_re_source) free((void *)dbi->dbi_re_source); - if (dbi->dbi_dbenv) free(dbi->dbi_dbenv); - if (dbi->dbi_dbinfo) free(dbi->dbi_dbinfo); - free((void *)dbi); + dbi->dbi_root = _free(dbi->dbi_root); + dbi->dbi_home = _free(dbi->dbi_home); + dbi->dbi_file = _free(dbi->dbi_file); + dbi->dbi_subfile = _free(dbi->dbi_subfile); + dbi->dbi_errpfx = _free(dbi->dbi_errpfx); + dbi->dbi_re_source = _free(dbi->dbi_re_source); + dbi->dbi_dbenv = _free(dbi->dbi_dbenv); + dbi->dbi_dbinfo = _free(dbi->dbi_dbinfo); + dbi = _free(dbi); } } @@ -232,10 +232,10 @@ dbiIndex db3New(rpmdb rpmdb, int rpmtag) for (o = dbOpts; o && *o; o = oe) { struct dbOption *opt; - while (*o && isspace(*o)) + while (*o && xisspace(*o)) o++; for (oe = o; oe && *oe; oe++) { - if (isspace(*oe)) + if (xisspace(*oe)) break; if (oe[0] == ':' && !(oe[1] == '/' && oe[2] == '/')) break; @@ -270,7 +270,7 @@ dbiIndex db3New(rpmdb rpmdb, int rpmtag) break; case POPT_ARG_STRING: { const char ** t = opt->arg; - if (*t) free((void *)*t); + *t = _free(*t); *t = xstrdup( (p ? p : "") ); } break; diff --git a/lib/depends.c b/lib/depends.c index 5975ee763..f2168de34 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -16,19 +16,11 @@ int _depends_debug = 0; /*@access dbiIndex@*/ /* XXX compared with NULL */ /*@access dbiIndexSet@*/ /* XXX compared with NULL */ /*@access Header@*/ /* XXX compared with NULL */ +/*@access FD_t@*/ /* XXX compared with NULL */ /*@access rpmdb@*/ /* XXX compared with NULL */ +/*@access rpmdbMatchIterator@*/ /* XXX compared with NULL */ /*@access rpmTransactionSet@*/ -/** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free - * @retval NULL always - */ -static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this) free((void *)this); - return NULL; -} - int headerNVR(Header h, const char **np, const char **vp, const char **rp) { int type, count; @@ -80,11 +72,11 @@ static /*@only@*/ char *printDepend(const char * depend, const char * key, t = tbuf = xmalloc(nb + 1); if (depend) { - while(*depend) *t++ = *depend++; + while(*depend != '\0') *t++ = *depend++; *t++ = ' '; } if (key) - while(*key) *t++ = *key++; + while(*key != '\0') *t++ = *key++; if (keyFlags & RPMSENSE_SENSEMASK) { if (t != tbuf) *t++ = ' '; if (keyFlags & RPMSENSE_LESS) *t++ = '<'; @@ -93,7 +85,7 @@ static /*@only@*/ char *printDepend(const char * depend, const char * key, } if (keyEVR && *keyEVR) { if (t != tbuf) *t++ = ' '; - while(*keyEVR) *t++ = *keyEVR++; + while(*keyEVR != '\0') *t++ = *keyEVR++; } *t = '\0'; return tbuf; @@ -188,7 +180,7 @@ static void alFree(struct availableList * al) } p->relocs = _free(p->relocs); } - if (p->fd) + if (p->fd != NULL) p->fd = fdFree(p->fd, "alAddPackage (alFree)"); } @@ -212,8 +204,8 @@ static void alFree(struct availableList * al) */ static int dirInfoCompare(const void * one, const void * two) /*@*/ { - const struct dirInfo * a = one; - const struct dirInfo * b = two; + const dirInfo a = (const dirInfo) one; + const dirInfo b = (const dirInfo) two; int lenchk = a->dirNameLen - b->dirNameLen; if (lenchk) @@ -246,8 +238,8 @@ static /*@exposed@*/ struct availablePackage * alAddPackage(struct availableList const char ** dirNames; int numDirs, dirNum; int * dirMapping; - struct dirInfo dirNeedle; - struct dirInfo * dirMatch; + struct dirInfo_s dirNeedle; + dirInfo dirMatch; int first, last, fileNum; int origNumDirs; int pkgNum; @@ -388,7 +380,7 @@ static /*@exposed@*/ struct availablePackage * alAddPackage(struct availableList } p->key = key; - p->fd = (fd ? fdLink(fd, "alAddPackage") : NULL); + p->fd = (fd != NULL ? fdLink(fd, "alAddPackage") : NULL); if (relocs) { for (i = 0, r = relocs; r->oldPath || r->newPath; i++, r++); @@ -500,7 +492,7 @@ static void parseEVR(char *evr, char *s, *se; s = evr; - while (*s && isdigit(*s)) s++; /* s points to epoch terminator */ + while (*s && xisdigit(*s)) s++; /* s points to epoch terminator */ se = strrchr(s, '-'); /* se points to version terminator */ if (*s == ':') { @@ -680,7 +672,7 @@ int headerMatchesDepFlags(Header h, *p = '\0'; if (hge(h, RPMTAG_EPOCH, NULL, (void **) &epoch, NULL)) { sprintf(p, "%d:", *epoch); - while (*p) + while (*p != '\0') p++; } (void) stpcpy( stpcpy( stpcpy(p, version) , "-") , release); @@ -885,7 +877,7 @@ void rpmtransFree(rpmTransactionSet ts) ts->di = _free(ts->di); ts->removedPackages = _free(ts->removedPackages); ts->order = _free(ts->order); - if (ts->scriptFd) + if (ts->scriptFd != NULL) ts->scriptFd = fdFree(ts->scriptFd, "rpmtransSetScriptFd (rpmtransFree"); ts->rootDir = _free(ts->rootDir); ts->currDir = _free(ts->currDir); @@ -924,8 +916,8 @@ alFileSatisfiesDepend(struct availableList * al, int i; const char * dirName; const char * baseName; - struct dirInfo dirNeedle; - struct dirInfo * dirMatch; + struct dirInfo_s dirNeedle; + dirInfo dirMatch; if (al->numDirs == 0) /* Solaris 2.6 bsearch sucks down on this. */ return NULL; @@ -1086,7 +1078,7 @@ static int unsatisfiedDepend(rpmTransactionSet ts, (rcProvidesString = rpmGetVar(RPMVAR_PROVIDES))) { i = strlen(keyName); while ((start = strstr(rcProvidesString, keyName))) { - if (isspace(start[i]) || start[i] == '\0' || start[i] == ',') { + if (xisspace(start[i]) || start[i] == '\0' || start[i] == ',') { rpmMessage(RPMMESS_DEBUG, _("%s: %-45s YES (rpmrc provides)\n"), keyType, keyDepend+2); goto exit; @@ -1224,6 +1216,7 @@ static int checkPackageDeps(rpmTransactionSet ts, struct problemsSet * psp, if (!hge(h, RPMTAG_REQUIRENAME, &rnt, (void **) &requires, &requiresCount)) { requiresCount = 0; + rvt = RPM_STRING_ARRAY_TYPE; } else { hge(h, RPMTAG_REQUIREFLAGS, &type, (void **) &requireFlags, &requiresCount); @@ -1292,6 +1285,7 @@ static int checkPackageDeps(rpmTransactionSet ts, struct problemsSet * psp, if (!hge(h, RPMTAG_CONFLICTNAME, &cnt, (void **)&conflicts, &conflictsCount)) { conflictsCount = 0; + cvt = RPM_STRING_ARRAY_TYPE; } else { hge(h, RPMTAG_CONFLICTFLAGS, &type, (void **) &conflictFlags, &conflictsCount); @@ -1585,7 +1579,7 @@ static inline int addRelation( const rpmTransactionSet ts, /* Avoid redundant relations. */ /* XXX FIXME: add control bit. */ matchNum = q - ts->addedPackages.list; - if (selected[matchNum]) + if (selected[matchNum] != 0) return 0; selected[matchNum] = 1; @@ -1623,8 +1617,8 @@ static int orderListIndexCmp(const void * one, const void * two) * @retval rp address of last element */ static void addQ(/*@kept@*/ struct availablePackage * p, - /*@out@*/ struct availablePackage ** qp, - /*@out@*/ struct availablePackage ** rp) + struct availablePackage ** qp, + struct availablePackage ** rp) { struct availablePackage *q, *qprev; @@ -1835,7 +1829,7 @@ rescan: sprintf(buf, "%s-%s-%s", p->name, p->version, p->release); rpmMessage(RPMMESS_WARNING, " %-40s %s\n", buf, dp); - dp = _free((void *)dp); + dp = _free(dp); } /* Walk (and erase) linear part of predecessor chain as well. */ @@ -2058,7 +2052,7 @@ int rpmdepCheck(rpmTransactionSet ts, rc = 0; exit: - if (mi) + if (mi != NULL) rpmdbFreeIterator(mi); ps.problems = _free(ps.problems); return rc; diff --git a/lib/depends.h b/lib/depends.h index 41dddac48..c32b71d8e 100644 --- a/lib/depends.h +++ b/lib/depends.h @@ -84,12 +84,12 @@ struct fileIndexEntry { /** \ingroup rpmdep * A directory to be installed/removed. */ -struct dirInfo { +typedef struct dirInfo_s { /*@owned@*/ const char * dirName; /*!< Directory path (+ trailing '/'). */ int dirNameLen; /*!< No. bytes in directory path. */ /*@owned@*/ struct fileIndexEntry * files; /*!< Array of files in directory. */ int numFiles; /*!< No. files in directory. */ -} ; +} * dirInfo ; /** \ingroup rpmdep * Set of available packages, items, and directories. @@ -101,7 +101,7 @@ struct availableList { int size; /*!< No. of pkgs in list. */ int alloced; /*!< No. of pkgs allocated for list. */ int numDirs; /*!< No. of directories. */ -/*@owned@*/ struct dirInfo * dirs; /*!< Set of directories. */ +/*@owned@*/ dirInfo dirs; /*!< Set of directories. */ } ; /** \ingroup rpmdep @@ -144,7 +144,7 @@ struct rpmTransactionSet_s { /*!< Packages sorted by dependencies. */ int orderCount; /*!< No. of transaction elements. */ int orderAlloced; /*!< No. of allocated transaction elements. */ -/*@shared@*/ TFI_t flList; /*!< Transaction element(s) file info. */ +/*@only@*/ TFI_t flList; /*!< Transaction element(s) file info. */ int flEntries; /*!< No. of transaction elements. */ int chrootDone; /*!< Has chroot(2) been been done? */ /*@only@*/ const char * rootDir;/*!< Path to top of install tree. */ diff --git a/lib/fileutil.c b/lib/fileutil.c index 2d2cd19d4..4b2270b2b 100644 --- a/lib/fileutil.c +++ b/lib/fileutil.c @@ -171,7 +171,6 @@ int rpmSyscall(const char * cmd, int noexec) } exit: - if (argv) - free((void *)argv); + argv = _free(argv); return rc; } diff --git a/lib/formats.c b/lib/formats.c index 0c515ba7c..43c35804d 100644 --- a/lib/formats.c +++ b/lib/formats.c @@ -57,7 +57,7 @@ static /*@only@*/ char * permsFormat(int_32 type, const void * data, char * form strcat(formatPrefix, "s"); buf = rpmPermsString(*((int_32 *) data)); sprintf(val, formatPrefix, buf); - free(buf); + buf = _free(buf); } return val; @@ -180,17 +180,19 @@ static int instprefixTag(Header h, /*@out@*/ int_32 * type, /*@out@*/ int * freeData) /*@modifies h, *type, *data, *count, *freeData @*/ { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; + int ipt; char ** array; - if (headerGetEntry(h, RPMTAG_INSTALLPREFIX, type, (void **)data, count)) { + if (hge(h, RPMTAG_INSTALLPREFIX, type, (void **)data, count)) { *freeData = 0; return 0; - } else if (headerGetEntry(h, RPMTAG_INSTPREFIXES, NULL, (void **) &array, - count)) { + } else if (hge(h, RPMTAG_INSTPREFIXES, &ipt, (void **) &array, count)) { *data = xstrdup(array[0]); *freeData = 1; *type = RPM_STRING_TYPE; - free(array); + array = hfd(array, ipt); return 0; } @@ -210,13 +212,13 @@ static int fssizesTag(Header h, /*@out@*/ int_32 * type, /*@out@*/ int * freeData) /*@modifies h, *type, *data, *count, *freeData @*/ { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; const char ** filenames; int_32 * filesizes; uint_32 * usages; int numFiles; - if (!headerGetEntry(h, RPMTAG_FILESIZES, NULL, (void **) &filesizes, - &numFiles)) { + if (!hge(h, RPMTAG_FILESIZES, NULL, (void **) &filesizes, &numFiles)) { filesizes = NULL; numFiles = 0; filenames = NULL; @@ -243,7 +245,7 @@ static int fssizesTag(Header h, /*@out@*/ int_32 * type, *data = usages; - if (filenames) free(filenames); + filenames = _free(filenames); return 0; } @@ -261,6 +263,9 @@ static int triggercondsTag(Header h, /*@out@*/ int_32 * type, /*@out@*/ int * freeData) /*@modifies h, *type, *data, *count, *freeData @*/ { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; + int tnt, tvt, tst; int_32 * indices, * flags; char ** names, ** versions; int numNames, numScripts; @@ -270,17 +275,16 @@ static int triggercondsTag(Header h, /*@out@*/ int_32 * type, int i, j; char buf[5]; - if (!headerGetEntry(h, RPMTAG_TRIGGERNAME, NULL, (void **) &names, - &numNames)) { + if (!hge(h, RPMTAG_TRIGGERNAME, &tnt, (void **) &names, &numNames)) { *freeData = 0; return 0; } - headerGetEntry(h, RPMTAG_TRIGGERINDEX, NULL, (void **) &indices, NULL); - headerGetEntry(h, RPMTAG_TRIGGERFLAGS, NULL, (void **) &flags, NULL); - headerGetEntry(h, RPMTAG_TRIGGERVERSION, NULL, (void **) &versions, NULL); - headerGetEntry(h, RPMTAG_TRIGGERSCRIPTS, NULL, (void **) &s, &numScripts); - free(s); + hge(h, RPMTAG_TRIGGERINDEX, NULL, (void **) &indices, NULL); + hge(h, RPMTAG_TRIGGERFLAGS, NULL, (void **) &flags, NULL); + hge(h, RPMTAG_TRIGGERVERSION, &tvt, (void **) &versions, NULL); + hge(h, RPMTAG_TRIGGERSCRIPTS, &tst, (void **) &s, &numScripts); + s = hfd(s, tst); *freeData = 1; *data = conds = xmalloc(sizeof(char * ) * numScripts); @@ -295,25 +299,24 @@ static int triggercondsTag(Header h, /*@out@*/ int_32 * type, item = xmalloc(strlen(names[j]) + strlen(versions[j]) + 20); if (flags[j] & RPMSENSE_SENSEMASK) { buf[0] = '%', buf[1] = '\0'; - flagsStr = depflagsFormat(RPM_INT32_TYPE, flags, buf, - 0, j); + flagsStr = depflagsFormat(RPM_INT32_TYPE, flags, buf, 0, j); sprintf(item, "%s %s %s", names[j], flagsStr, versions[j]); - free(flagsStr); + flagsStr = _free(flagsStr); } else { strcpy(item, names[j]); } chptr = xrealloc(chptr, strlen(chptr) + strlen(item) + 5); - if (*chptr) strcat(chptr, ", "); + if (*chptr != '\0') strcat(chptr, ", "); strcat(chptr, item); - free(item); + item = _free(item); } conds[i] = chptr; } - free(names); - free(versions); + names = hfd(names, tnt); + versions = hfd(versions, tvt); return 0; } @@ -331,21 +334,23 @@ static int triggertypeTag(Header h, /*@out@*/ int_32 * type, /*@out@*/ int * freeData) /*@modifies h, *type, *data, *count, *freeData @*/ { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; + int tst; int_32 * indices, * flags; - char ** conds, ** s; + const char ** conds; + const char ** s; int i, j; int numScripts, numNames; - if (!headerGetEntry(h, RPMTAG_TRIGGERINDEX, NULL, (void **) &indices, - &numNames)) { + if (!hge(h, RPMTAG_TRIGGERINDEX, NULL, (void **) &indices, &numNames)) { *freeData = 0; return 1; } - headerGetEntry(h, RPMTAG_TRIGGERFLAGS, NULL, (void **) &flags, NULL); - - headerGetEntry(h, RPMTAG_TRIGGERSCRIPTS, NULL, (void **) &s, &numScripts); - free(s); + hge(h, RPMTAG_TRIGGERFLAGS, NULL, (void **) &flags, NULL); + hge(h, RPMTAG_TRIGGERSCRIPTS, &tst, (void **) &s, &numScripts); + s = hfd(s, tst); *freeData = 1; *data = conds = xmalloc(sizeof(char * ) * numScripts); @@ -412,6 +417,7 @@ static int i18nTag(Header h, int_32 tag, /*@out@*/ int_32 * type, /*@out@*/ int * freeData) /*@modifies h, *type, *data, *count, *freeData @*/ { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; char * dstring = rpmExpand(_macro_i18ndomains, NULL); int rc; @@ -461,15 +467,14 @@ static int i18nTag(Header h, int_32 tag, /*@out@*/ int_32 * type, *count = 1; *freeData = 1; } - free(dstring); dstring = NULL; - if (*data) { + dstring = _free(dstring); + if (*data) return 0; - } } - if (dstring) free(dstring); + dstring = _free(dstring); - rc = headerGetEntry(h, tag, type, (void **)data, count); + rc = hge(h, tag, type, (void **)data, count); if (rc) { *data = xstrdup(*data); diff --git a/lib/fprint.c b/lib/fprint.c index 7fea93442..52f07fd3c 100644 --- a/lib/fprint.c +++ b/lib/fprint.c @@ -114,15 +114,16 @@ static fingerPrint doLookup(fingerPrintCache cache, /* as we're stating paths here, we want to follow symlinks */ - if ((cacheHit = cacheContainsDirectory(cache, *buf ? buf : "/"))) { + cacheHit = cacheContainsDirectory(cache, (*buf != '\0' ? buf : "/")); + if (cacheHit != NULL) { fp.entry = cacheHit; - } else if (!stat(*buf ? buf : "/", &sb)) { - size_t nb = sizeof(*fp.entry) + (*buf ? (end-buf) : 1) + 1; + } else if (!stat((*buf != '\0' ? buf : "/"), &sb)) { + size_t nb = sizeof(*fp.entry) + (*buf != '\0' ? (end-buf) : 1) + 1; char * dn = xmalloc(nb); struct fprintCacheEntry_s * newEntry = (void *)dn; dn += sizeof(*newEntry); - strcpy(dn, (*buf ? buf : "/")); + strcpy(dn, (*buf != '\0' ? buf : "/")); newEntry->ino = sb.st_ino; newEntry->dev = sb.st_dev; newEntry->isFake = 0; @@ -178,7 +179,7 @@ unsigned int fpHashFunction(const void * key) ch = 0; chptr = fp->baseName; - while (*chptr) ch ^= *chptr++; + while (*chptr != '\0') ch ^= *chptr++; hash |= ((unsigned)ch) << 24; hash |= (((((unsigned)fp->entry->dev) >> 8) ^ fp->entry->dev) & 0xFF) << 16; @@ -22,9 +22,8 @@ void freeFilesystems(void) if (filesystems) { int i; for (i = 0; i < numFilesystems; i++) - free((void *)filesystems[i].mntPoint); - free(filesystems); - filesystems = NULL; + filesystems[i].mntPoint = _free(filesystems[i].mntPoint); + filesystems = _free(filesystems); } if (fsnames) { #if 0 /* XXX leak/segfault on exit of "rpm -qp --qf '%{#fsnames}' pkg" */ @@ -286,8 +285,8 @@ int rpmGetFilesystemUsage(const char ** fileList, int_32 * fssizes, int numFiles if (errno != ENOENT) { rpmError(RPMERR_STAT, _("failed to stat %s: %s\n"), buf, strerror(errno)); - free((void *)sourceDir); - free(usages); + sourceDir = _free(sourceDir); + usages = _free(usages); return 1; } @@ -307,8 +306,8 @@ int rpmGetFilesystemUsage(const char ** fileList, int_32 * fssizes, int numFiles if (j == numFilesystems) { rpmError(RPMERR_BADDEV, _("file %s is on an unknown device\n"), buf); - free((void *)sourceDir); - free(usages); + sourceDir = _free(sourceDir); + usages = _free(usages); return 1; } @@ -321,9 +320,12 @@ int rpmGetFilesystemUsage(const char ** fileList, int_32 * fssizes, int numFiles usages[lastfs] += fssizes[i]; } - if (sourceDir) free((void *)sourceDir); + sourceDir = _free(sourceDir); - *usagesPtr = usages; + if (usagesPtr) + *usagesPtr = usages; + else + usages = _free(usages); return 0; } @@ -12,20 +12,11 @@ /*@access FD_t @*/ /*@access rpmTransactionSet @*/ /*@access TFI_t @*/ +/*@access FSMI_t @*/ /*@access FSM_t @*/ #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s)) -/** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free - * @retval NULL always - */ -static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this) free((void *)this); - return NULL; -} - int _fsm_debug = 0; rpmTransactionSet fsmGetTs(const FSM_t fsm) { @@ -411,7 +402,7 @@ FSM_t newFSM(void) { FSM_t freeFSM(FSM_t fsm) { if (fsm) { - if (fsm->path) free((void *)fsm->path); + fsm->path = _free(fsm->path); while ((fsm->li = fsm->links) != NULL) { fsm->links = fsm->li->next; fsm->li->next = NULL; @@ -1010,7 +1001,7 @@ static int fsmMkdirs(FSM_t fsm) fsm->path = dn; /* Assume '/' directory exists, otherwise "mkdir -p" if non-existent. */ - for (i = 1, te = dn + 1; *te; te++, i++) { + for (i = 1, te = dn + 1; *te != '\0'; te++, i++) { if (*te != '/') continue; *te = '\0'; @@ -1042,7 +1033,7 @@ static int fsmMkdirs(FSM_t fsm) if (!rc) rpmMessage(RPMMESS_WARNING, _("%s directory created with perms %04o.\n"), - fsm->path, (st->st_mode & 07777)); + fsm->path, (unsigned)(st->st_mode & 07777)); *te = '/'; } if (rc) break; @@ -1089,7 +1080,8 @@ int fsmStage(FSM_t fsm, fileStage stage) if (_fsm_debug && !(stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s %06o%3d (%4d,%4d)%10d %s %s\n", cur, - st->st_mode, st->st_nlink, st->st_uid, st->st_gid, st->st_size, + (unsigned)st->st_mode, (int)st->st_nlink, + (int)st->st_uid, (int)st->st_gid, (int)st->st_size, (fsm->path ? fsm->path : ""), _fafilter(fsm->action)); } else { @@ -1097,7 +1089,8 @@ int fsmStage(FSM_t fsm, fileStage stage) if (_fsm_debug || !(stage & FSM_VERBOSE)) rpmMessage(RPMMESS_DEBUG, "%-8s %06o%3d (%4d,%4d)%10d %s %s\n", cur, - st->st_mode, st->st_nlink, st->st_uid, st->st_gid, st->st_size, + (unsigned)st->st_mode, (int)st->st_nlink, + (int)st->st_uid, (int)st->st_gid, (int)st->st_size, (fsm->path ? fsm->path + fsm->astriplen : ""), _fafilter(fsm->action)); } @@ -1649,7 +1642,7 @@ int fsmStage(FSM_t fsm, fileStage stage) rc = Mkdir(fsm->path, (st->st_mode & 07777)); if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur, - fsm->path, (st->st_mode & 07777), + fsm->path, (unsigned)(st->st_mode & 07777), (rc < 0 ? strerror(errno) : "")); if (rc < 0) rc = CPIOERR_MKDIR_FAILED; break; @@ -1664,7 +1657,7 @@ int fsmStage(FSM_t fsm, fileStage stage) rc = chown(fsm->path, st->st_uid, st->st_gid); if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur, - fsm->path, st->st_uid, st->st_gid, + fsm->path, (int)st->st_uid, (int)st->st_gid, (rc < 0 ? strerror(errno) : "")); if (rc < 0) rc = CPIOERR_CHOWN_FAILED; break; @@ -1673,7 +1666,7 @@ int fsmStage(FSM_t fsm, fileStage stage) rc = lchown(fsm->path, st->st_uid, st->st_gid); if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, %d) %s\n", cur, - fsm->path, st->st_uid, st->st_gid, + fsm->path, (int)st->st_uid, (int)st->st_gid, (rc < 0 ? strerror(errno) : "")); if (rc < 0) rc = CPIOERR_CHOWN_FAILED; #endif @@ -1682,7 +1675,7 @@ int fsmStage(FSM_t fsm, fileStage stage) rc = chmod(fsm->path, (st->st_mode & 07777)); if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur, - fsm->path, (st->st_mode & 07777), + fsm->path, (unsigned)(st->st_mode & 07777), (rc < 0 ? strerror(errno) : "")); if (rc < 0) rc = CPIOERR_CHMOD_FAILED; break; @@ -1716,7 +1709,7 @@ int fsmStage(FSM_t fsm, fileStage stage) rc = mkfifo(fsm->path, (st->st_mode & 07777)); if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%04o) %s\n", cur, - fsm->path, (st->st_mode & 07777), + fsm->path, (unsigned)(st->st_mode & 07777), (rc < 0 ? strerror(errno) : "")); if (rc < 0) rc = CPIOERR_MKFIFO_FAILED; break; @@ -1725,7 +1718,8 @@ int fsmStage(FSM_t fsm, fileStage stage) rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev); if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur, - fsm->path, (st->st_mode & ~07777), (unsigned)st->st_rdev, + fsm->path, (unsigned)(st->st_mode & ~07777), + (unsigned)st->st_rdev, (rc < 0 ? strerror(errno) : "")); if (rc < 0) rc = CPIOERR_MKNOD_FAILED; /*@=unrecog@*/ @@ -1749,7 +1743,7 @@ int fsmStage(FSM_t fsm, fileStage stage) rc = Readlink(fsm->path, fsm->rdbuf, fsm->rdsize - 1); if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (%s, rdbuf, %d) %s\n", cur, - fsm->path, fsm->rdlen, (rc < 0 ? strerror(errno) : "")); + fsm->path, (int)fsm->rdlen, (rc < 0 ? strerror(errno) : "")); if (rc < 0) rc = CPIOERR_READLINK_FAILED; else { fsm->rdnb = rc; @@ -1809,7 +1803,7 @@ int fsmStage(FSM_t fsm, fileStage stage) if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\trdnb %d\n", cur, (fsm->wrbuf == fsm->wrb ? "wrbuf" : "mmap"), - fsm->wrlen, fsm->rdnb); + (int)fsm->wrlen, (int)fsm->rdnb); if (fsm->rdnb != fsm->wrlen) fprintf(stderr, "*** short read, had %d, got %d\n", (int)fsm->rdnb, (int)fsm->wrlen); #ifdef NOTYET if (Ferror(fsm->rfd)) @@ -1823,7 +1817,7 @@ if (fsm->rdnb != fsm->wrlen) fprintf(stderr, "*** short read, had %d, got %d\n", if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (%s, %d, cfd)\twrnb %d\n", cur, (fsm->rdbuf == fsm->rdb ? "rdbuf" : "mmap"), - fsm->rdnb, fsm->wrnb); + (int)fsm->rdnb, (int)fsm->wrnb); if (fsm->rdnb != fsm->wrnb) fprintf(stderr, "*** short write, had %d, got %d\n", (int)fsm->rdnb, (int)fsm->wrnb); #ifdef NOTYET if (Ferror(fsm->wfd)) @@ -1849,7 +1843,7 @@ if (fsm->rdnb != fsm->wrnb) fprintf(stderr, "*** short write, had %d, got %d\n", fsm->rdnb = Fread(fsm->rdbuf, sizeof(*fsm->rdbuf), fsm->rdlen, fsm->rfd); if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (rdbuf, %d, rfd)\trdnb %d\n", - cur, fsm->rdlen, fsm->rdnb); + cur, (int)fsm->rdlen, (int)fsm->rdnb); if (fsm->rdnb != fsm->rdlen) fprintf(stderr, "*** short read, had %d, got %d\n", (int)fsm->rdnb, (int)fsm->rdlen); #ifdef NOTYET if (Ferror(fsm->rfd)) @@ -1880,7 +1874,7 @@ if (fsm->rdnb != fsm->rdlen) fprintf(stderr, "*** short read, had %d, got %d\n", fsm->wrnb = Fwrite(fsm->wrbuf, sizeof(*fsm->wrbuf), fsm->rdnb, fsm->wfd); if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (wrbuf, %d, wfd)\twrnb %d\n", - cur, fsm->rdnb, fsm->wrnb); + cur, (int)fsm->rdnb, (int)fsm->wrnb); if (fsm->rdnb != fsm->wrnb) fprintf(stderr, "*** short write: had %d, got %d\n", (int)fsm->rdnb, (int)fsm->wrnb); #ifdef NOTYET if (Ferror(fsm->wfd)) diff --git a/lib/getdate.y b/lib/getdate.y index c3f18c6ef..e5a4630f7 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -743,7 +743,7 @@ LookupWord(buff) int abbrev; /* Make it lowercase. */ - for (p = buff; *p; p++) + for (p = buff; *p != '\0'; p++) if (isupper(*p)) *p = tolower(*p); @@ -822,7 +822,7 @@ LookupWord(buff) } /* Drop out any periods and try the timezone table again. */ - for (i = 0, p = q = buff; *q; q++) + for (i = 0, p = q = buff; *q != '\0'; q++) if (*q != '.') *p++ = *q; else diff --git a/lib/header.c b/lib/header.c index 9cf0b061c..e53b45ed9 100644 --- a/lib/header.c +++ b/lib/header.c @@ -157,6 +157,7 @@ struct sprintfToken { * @param onDisk data is concatenated strings (with NUL's))? * @return no. bytes in data */ +/*@mayexit@*/ static int dataLength(int_32 type, const void * p, int_32 count, int onDisk) /*@*/ { @@ -1289,7 +1290,7 @@ headerFindI18NString(Header h, struct indexEntry *entry) if ((table = findEntry(h, HEADER_I18NTABLE, RPM_STRING_ARRAY_TYPE)) == NULL) return entry->data; - for (l = lang; *l; l = le) { + for (l = lang; *l != '\0'; l = le) { const char *td; char *ed; int langNum; @@ -1921,7 +1922,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, /* upper limit on number of individual formats */ numTokens = 0; - for (chptr = str; *chptr; chptr++) + for (chptr = str; *chptr != '\0'; chptr++) if (*chptr == '%') numTokens++; numTokens = numTokens * 2 + 1; @@ -1931,7 +1932,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, /*@-infloops@*/ dst = start = str; currToken = -1; - while (*start) { + while (*start != '\0') { switch (*start) { case '%': /* handle %% */ @@ -1984,7 +1985,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, *chptr++ = '\0'; while (start < chptr) { - if (isdigit(*start)) { + if (xisdigit(*start)) { i = strtoul(start, &start, 10); format[currToken].u.tag.pad += i; } else { @@ -2015,7 +2016,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, chptr = start; while (*chptr && *chptr != ':') chptr++; - if (*chptr) { + if (*chptr != '\0') { *chptr++ = '\0'; if (!*chptr) { /*@-observertrans@*/ @@ -2707,7 +2708,7 @@ static char * shescapeFormat(int_32 type, const void * data, result = dst = xmalloc(strlen(buf) * 4 + 3); *dst++ = '\''; - for (src = buf; *src; src++) { + for (src = buf; *src != '\0'; src++) { if (*src == '\'') { *dst++ = '\''; *dst++ = '\\'; diff --git a/lib/header.h b/lib/header.h index d6997e8ee..4bccd08f4 100644 --- a/lib/header.h +++ b/lib/header.h @@ -305,6 +305,7 @@ typedef const char * errmsg_t; * @param c number of values * @return 1 on success, 0 on failure */ +/*@mayexit@*/ int headerAddEntry(Header h, int_32 tag, int_32 type, const void *p, int_32 c) /*@modifies h @*/; diff --git a/lib/manifest.c b/lib/manifest.c index 30345cfa0..9526a2e03 100644 --- a/lib/manifest.c +++ b/lib/manifest.c @@ -4,6 +4,7 @@ #include "system.h" +#include <rpmlib.h> #include <rpmio_internal.h> #include "stringbuf.h" #include "manifest.h" @@ -12,16 +13,6 @@ /*@access StringBuf @*/ -/** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free - * @retval NULL always - */ -static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this) free((void *)this); - return NULL; -} - char * rpmPermsString(int mode) { char *perms = xstrdup("----------"); @@ -69,7 +60,8 @@ char * rpmPermsString(int mode) int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr) { StringBuf sb = newStringBuf(); - char * s, *se; + char * s = NULL; + char * se; int ac = 0; const char ** av = NULL; int argc = (argcPtr ? *argcPtr : 0); diff --git a/lib/misc.c b/lib/misc.c index c8aac96e6..a95774129 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -16,16 +16,6 @@ static int _debug = 0; /*@access Header@*/ /* XXX compared with NULL */ /*@access FD_t@*/ /* XXX compared with NULL */ -/** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free - * @retval NULL always - */ -static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this) free((void *)this); - return NULL; -} - char * RPMVERSION = VERSION; /* just to put a marker in librpm.a */ char ** splitString(const char * str, int length, char sep) @@ -125,8 +115,8 @@ int rpmvercmp(const char * a, const char * b) /* loop through each version segment of str1 and str2 and compare them */ while (*one && *two) { - while (*one && !isalnum(*one)) one++; - while (*two && !isalnum(*two)) two++; + while (*one && !xisalnum(*one)) one++; + while (*two && !xisalnum(*two)) two++; str1 = one; str2 = two; @@ -134,13 +124,13 @@ int rpmvercmp(const char * a, const char * b) /* grab first completely alpha or completely numeric segment */ /* leave one and two pointing to the start of the alpha or numeric */ /* segment and walk str1 and str2 to end of segment */ - if (isdigit(*str1)) { - while (*str1 && isdigit(*str1)) str1++; - while (*str2 && isdigit(*str2)) str2++; + if (xisdigit(*str1)) { + while (*str1 && xisdigit(*str1)) str1++; + while (*str2 && xisdigit(*str2)) str2++; isnum = 1; } else { - while (*str1 && isalpha(*str1)) str1++; - while (*str2 && isalpha(*str2)) str2++; + while (*str1 && xisalpha(*str1)) str1++; + while (*str2 && xisalpha(*str2)) str2++; isnum = 0; } @@ -236,7 +226,7 @@ static int rpmMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid) d = alloca(strlen(path)+2); de = stpcpy(d, path); de[1] = '\0'; - for (de = d; *de; de++) { + for (de = d; *de != '\0'; de++) { struct stat st; char savec; @@ -802,7 +792,7 @@ void providePackageNVR(Header h) *p = '\0'; if (headerGetEntry(h, RPMTAG_EPOCH, NULL, (void **) &epoch, NULL)) { sprintf(p, "%d:", *epoch); - while (*p) + while (*p != '\0') p++; } (void) stpcpy( stpcpy( stpcpy(p, version) , "-") , release); diff --git a/lib/misc.h b/lib/misc.h index 8f443f07e..8cb435647 100644 --- a/lib/misc.h +++ b/lib/misc.h @@ -30,7 +30,8 @@ void freeSplitString( /*@only@*/ char ** list); * @param c character to strip * @return string */ -/*@unused@*/ static inline char * stripTrailingChar(char * s, char c) +/*@unused@*/ static inline +/*@only@*/ char * stripTrailingChar(/*@only@*/ char * s, char c) /*@modifies *s */ { char * t; diff --git a/lib/poptBT.c b/lib/poptBT.c index fd2ba744f..c262f1887 100644 --- a/lib/poptBT.c +++ b/lib/poptBT.c @@ -79,7 +79,7 @@ static void buildArgCallback( /*@unused@*/ poptContext con, case POPT_TP: case POPT_TS: if (rba->buildMode == ' ') { - rba->buildMode = ((unsigned)(opt->val >> 8)) & 0xff; + rba->buildMode = (((unsigned)opt->val) >> 8) & 0xff; rba->buildChar = (opt->val ) & 0xff; } break; diff --git a/lib/poptQV.c b/lib/poptQV.c index 19e4ad3eb..a9c1dc316 100644 --- a/lib/poptQV.c +++ b/lib/poptQV.c @@ -97,7 +97,7 @@ struct poptOption rpmQVSourcePoptTable[] = { static void queryArgCallback(/*@unused@*/poptContext con, /*@unused@*/enum poptCallbackReason reason, const struct poptOption * opt, const char * arg, - const void * data) + /*@unused@*/ const void * data) { QVA_t *qva = &rpmQVArgs; diff --git a/lib/problems.c b/lib/problems.c index 5069304f4..12e032964 100644 --- a/lib/problems.c +++ b/lib/problems.c @@ -86,14 +86,14 @@ void printDepProblems(FILE * fp, struct rpmDependencyConflict * conflicts, } } -#if !defined(HAVE_VSNPRINTF) +#if !defined(HAVE_VSNPRINTF) || defined(__LCLINT__) static inline int vsnprintf(char * buf, /*@unused@*/ int nb, const char * fmt, va_list ap) { return vsprintf(buf, fmt, ap); } #endif -#if !defined(HAVE_SNPRINTF) +#if !defined(HAVE_SNPRINTF) || defined(__LCLINT__) static inline int snprintf(char * buf, int nb, const char * fmt, ...) { va_list ap; @@ -182,7 +182,7 @@ void rpmProblemPrint(FILE *fp, rpmProblem prob) { const char *msg = rpmProblemString(prob); fprintf(fp, "%s\n", msg); - free((void *)msg); + msg = _free(msg); } void rpmProblemSetPrint(FILE *fp, rpmProblemSet probs) @@ -25,16 +25,6 @@ extern int _fsm_debug; -/** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free - * @retval NULL always - */ -static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this) free((void *)this); - return NULL; -} - int rpmVersionCompare(Header first, Header second) { const char * one, * two; @@ -915,7 +905,7 @@ static int runScript(PSM_t psm, Header h, if (ipath && ipath[5] != '%') path = ipath; doputenv(path); - if (ipath) free((void *)ipath); + ipath = _free(ipath); } for (i = 0; i < numPrefixes; i++) { @@ -971,7 +961,7 @@ static int runScript(PSM_t psm, Header h, if (script) { if (!rpmIsDebug()) unlink(fn); - free((void *)fn); + fn = _free(fn); } return rc; @@ -1025,7 +1015,7 @@ static rpmRC runInstScript(PSM_t psm) * @return */ static int handleOneTrigger(PSM_t psm, Header sourceH, Header triggeredH, - int arg2, char * triggersAlreadyRun) + int arg2, unsigned char * triggersAlreadyRun) { const rpmTransactionSet ts = psm->ts; TFI_t fi = psm->fi; @@ -1096,11 +1086,14 @@ static int handleOneTrigger(PSM_t psm, Header sourceH, Header triggeredH, } else { arg1 += psm->countCorrection; index = triggerIndices[i]; - if (!triggersAlreadyRun || !triggersAlreadyRun[index]) { + if (triggersAlreadyRun == NULL || + triggersAlreadyRun[index] == 0) + { rc = runScript(psm, triggeredH, "%trigger", 1, triggerProgs + index, triggerScripts[index], arg1, arg2); - if (triggersAlreadyRun) triggersAlreadyRun[index] = 1; + if (triggersAlreadyRun != NULL) + triggersAlreadyRun[index] = 1; } } } @@ -1172,7 +1165,7 @@ static int runImmedTriggers(PSM_t psm) int_32 * triggerIndices; int_32 tnt, tit; int numTriggerIndices; - char * triggersRun; + unsigned char * triggersRun; rpmRC rc = RPMRC_OK; if (!hge(fi->h, RPMTAG_TRIGGERNAME, &tnt, @@ -1190,7 +1183,7 @@ static int runImmedTriggers(PSM_t psm) for (i = 0; i < numTriggers; i++) { rpmdbMatchIterator mi; - if (triggersRun[triggerIndices[i]]) continue; + if (triggersRun[triggerIndices[i]] != 0) continue; mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_NAME, triggerNames[i], 0); diff --git a/lib/query.c b/lib/query.c index cf3b414ba..73d8b3b5a 100644 --- a/lib/query.c +++ b/lib/query.c @@ -14,18 +14,10 @@ #include "manifest.h" #include "debug.h" -/*@access Header@*/ /* XXX compared with NULL */ /*@access rpmdbMatchIterator@*/ /* XXX compared with NULL */ - -/** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free - * @retval NULL always - */ -static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this) free((void *)this); - return NULL; -} +/*@access Header@*/ /* XXX compared with NULL */ +/*@access rpmdb@*/ /* XXX compared with NULL */ +/*@access FD_t@*/ /* XXX compared with NULL */ /** */ @@ -38,7 +30,7 @@ static void printFileInfo(char * te, const char * name, { char sizefield[15]; char ownerfield[9], groupfield[9]; - char timefield[100] = ""; + char timefield[100]; time_t when = mtime; /* important if sizeof(int_32) ! sizeof(time_t) */ struct tm * tm; static time_t now; @@ -192,7 +184,9 @@ int showQueryPackage(QVA_t *qva, /*@unused@*/rpmdb rpmdb, Header h) t = xrealloc(t, BUFSIZ+sb); te = t + tb; } + /*@-usereleased@*/ te = stpcpy(te, str); + /*@=usereleased@*/ str = _free(str); } } @@ -673,7 +667,7 @@ restart: { const char * s; char * fn; - for (s = arg; *s; s++) + for (s = arg; *s != '\0'; s++) if (!(*s == '.' || *s == '/')) break; if (*s == '\0') { @@ -709,7 +703,7 @@ restart: case RPMQV_DBOFFSET: { int mybase = 10; const char * myarg = arg; - int recOffset; + unsigned recOffset; /* XXX should be in strtoul */ if (*myarg == '0') { @@ -730,7 +724,7 @@ restart: mi = rpmdbInitIterator(rpmdb, RPMDBI_PACKAGES, &recOffset, sizeof(recOffset)); if (mi == NULL) { rpmError(RPMERR_QUERY, - _("record %d could not be read\n"), recOffset); + _("record %u could not be read\n"), recOffset); retcode = 1; } else { retcode = showMatches(qva, mi, showPackage); @@ -769,7 +763,7 @@ int rpmQuery(QVA_t *qva, rpmQVSources source, const char * arg) rc = rpmQueryVerify(qva, source, arg, rpmdb, showQueryPackage); - if (rpmdb) + if (rpmdb != NULL) rpmdbClose(rpmdb); return rc; diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index cfdee01bf..2a311b5e6 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -193,7 +193,7 @@ int rpmReSign(rpmResignFlags add, char *passPhrase, const char **argv) /* Clean up intermediate target */ unlink(sigtarget); - free((void *)sigtarget); sigtarget = NULL; + sigtarget = _free(sigtarget); /* Move final target into place. */ unlink(rpm); @@ -212,8 +212,7 @@ exit: } if (sigtarget) { unlink(sigtarget); - free((void *)sigtarget); - sigtarget = NULL; + sigtarget = _free(sigtarget); } if (tmprpm[0] != '\0') { unlink(tmprpm); @@ -413,7 +412,7 @@ int rpmCheckSig(rpmCheckSigFlags flags, const char **argv) headerFreeIterator(hi); res += res2; unlink(sigtarget); - free((void *)sigtarget); sigtarget = NULL; + sigtarget = _free(sigtarget); if (res2) { if (rpmIsVerbose()) { @@ -449,7 +448,7 @@ int rpmCheckSig(rpmCheckSigFlags flags, const char **argv) if (ofd) manageFile(&ofd, NULL, 0, 0); if (sigtarget) { unlink(sigtarget); - free((void *)sigtarget); sigtarget = NULL; + sigtarget = _free(sigtarget); } } diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 0aa142eb6..1a63de95a 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -68,13 +68,12 @@ static void dbiTagsInit(void) dbiTagStr = rpmExpand("%{_dbi_tags}", NULL); if (!(dbiTagStr && *dbiTagStr && *dbiTagStr != '%')) { - free((void *)dbiTagStr); + dbiTagStr = _free(dbiTagStr); dbiTagStr = xstrdup(_dbiTagStr_default); } if (dbiTagsMax || dbiTags) { - free(dbiTags); - dbiTags = NULL; + dbiTags = _free(dbiTags); dbiTagsMax = 0; } @@ -83,12 +82,12 @@ static void dbiTagsInit(void) dbiTags = xcalloc(1, dbiTagsMax * sizeof(*dbiTags)); for (o = dbiTagStr; o && *o; o = oe) { - while (*o && isspace(*o)) + while (*o && xisspace(*o)) o++; if (*o == '\0') break; for (oe = o; oe && *oe; oe++) { - if (isspace(*oe)) + if (xisspace(*oe)) break; if (oe[0] == ':' && !(oe[1] == '/' && oe[2] == '/')) break; @@ -108,8 +107,7 @@ static void dbiTagsInit(void) dbiTags[dbiTagsMax++] = rpmtag; } - if (dbiTagStr) - free(dbiTagStr); + dbiTagStr = _free(dbiTagStr); } #if USE_DB1 @@ -358,11 +356,11 @@ union _dbswap { * @param dbcursor index database cursor * @param keyp search key * @param keylen search key length (0 will use strlen(key)) - * @param setp address of items retrieved from index database + * @retval setp address of items retrieved from index database * @return -1 error, 0 success, 1 not found */ static int dbiSearch(dbiIndex dbi, DBC * dbcursor, - const char * keyp, size_t keylen, dbiIndexSet * setp) + const char * keyp, size_t keylen, /*@out@*/ dbiIndexSet * setp) { void * datap = NULL; size_t datalen = 0; @@ -464,6 +462,8 @@ static int dbiUpdateIndex(dbiIndex dbi, DBC * dbcursor, for (i = 0; i < set->count; i++) { union _dbswap hdrNum, tagNum; + memset(&hdrNum, 0, sizeof(hdrNum)); + memset(&tagNum, 0, sizeof(tagNum)); hdrNum.ui = set->recs[i].hdrNum; tagNum.ui = set->recs[i].tagNum; if (_dbbyteswapped) { @@ -482,6 +482,7 @@ static int dbiUpdateIndex(dbiIndex dbi, DBC * dbcursor, for (i = 0; i < set->count; i++) { union _dbswap hdrNum; + memset(&hdrNum, 0, sizeof(hdrNum)); hdrNum.ui = set->recs[i].hdrNum; if (_dbbyteswapped) { _DBSWAP(hdrNum); @@ -541,9 +542,11 @@ static INLINE int dbiAppendSet(dbiIndexSet set, const void * recs, if (set == NULL || recs == NULL || nrecs <= 0 || recsize <= 0) return 1; - set->recs = (set->count == 0) - ? xmalloc(nrecs * sizeof(*(set->recs))) - : xrealloc(set->recs, (set->count + nrecs) * sizeof(*(set->recs))); + if (set->count == 0) + set->recs = xmalloc(nrecs * sizeof(*(set->recs))); + else + set->recs = xrealloc(set->recs, + (set->count + nrecs) * sizeof(*(set->recs))); memset(set->recs + set->count, 0, nrecs * sizeof(*(set->recs))); @@ -682,23 +685,11 @@ int rpmdbClose (rpmdb rpmdb) dbiClose(rpmdb->_dbi[dbix], 0); rpmdb->_dbi[dbix] = NULL; } - if (rpmdb->db_errpfx) { - free((void *)rpmdb->db_errpfx); - rpmdb->db_errpfx = NULL; - } - if (rpmdb->db_root) { - free((void *)rpmdb->db_root); - rpmdb->db_root = NULL; - } - if (rpmdb->db_home) { - free((void *)rpmdb->db_home); - rpmdb->db_home = NULL; - } - if (rpmdb->_dbi) { - free((void *)rpmdb->_dbi); - rpmdb->_dbi = NULL; - } - free(rpmdb); + rpmdb->db_errpfx = _free(rpmdb->db_errpfx); + rpmdb->db_root = _free(rpmdb->db_root); + rpmdb->db_home = _free(rpmdb->db_home); + rpmdb->_dbi = _free(rpmdb->_dbi); + rpmdb = _free(rpmdb); return 0; } @@ -882,8 +873,11 @@ int rpmdbInit (const char * prefix, int perms) static int rpmdbFindByFile(rpmdb rpmdb, const char * filespec, /*@out@*/ dbiIndexSet * matches) { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; const char * dirName; const char * baseName; + int bnt, dnt; fingerPrintCache fpc; fingerPrint fp1; dbiIndex dbi = NULL; @@ -948,12 +942,9 @@ static int rpmdbFindByFile(rpmdb rpmdb, const char * filespec, continue; } - headerGetEntryMinMemory(h, RPMTAG_BASENAMES, NULL, - (const void **) &baseNames, NULL); - headerGetEntryMinMemory(h, RPMTAG_DIRNAMES, NULL, - (const void **) &dirNames, NULL); - headerGetEntryMinMemory(h, RPMTAG_DIRINDEXES, NULL, - (const void **) &dirIndexes, NULL); + hge(h, RPMTAG_BASENAMES, &bnt, (void **) &baseNames, NULL); + hge(h, RPMTAG_DIRNAMES, &dnt, (void **) &dirNames, NULL); + hge(h, RPMTAG_DIRINDEXES, NULL, (const void **) &dirIndexes, NULL); do { fingerPrint fp2; @@ -972,15 +963,12 @@ static int rpmdbFindByFile(rpmdb rpmdb, const char * filespec, } while (i < allMatches->count && (i == 0 || offset == prevoff)); - free(baseNames); - free(dirNames); + baseNames = hfd(baseNames, bnt); + dirNames = hfd(dirNames, dnt); headerFree(h); } - if (rec) { - free(rec); - rec = NULL; - } + rec = _free(rec); if (allMatches) { dbiFreeIndexSet(allMatches); allMatches = NULL; @@ -1234,14 +1222,8 @@ void rpmdbFreeIterator(rpmdbMatchIterator mi) dbi->dbi_rmw = NULL; } - if (mi->mi_release) { - free((void *)mi->mi_release); - mi->mi_release = NULL; - } - if (mi->mi_version) { - free((void *)mi->mi_version); - mi->mi_version = NULL; - } + mi->mi_release = _free(mi->mi_release); + mi->mi_version = _free(mi->mi_version); if (mi->mi_dbc) { xx = dbiCclose(dbi, mi->mi_dbc, 1); mi->mi_dbc = NULL; @@ -1250,11 +1232,8 @@ void rpmdbFreeIterator(rpmdbMatchIterator mi) dbiFreeIndexSet(mi->mi_set); mi->mi_set = NULL; } - if (mi->mi_keyp) { - free((void *)mi->mi_keyp); - mi->mi_keyp = NULL; - } - free(mi); + mi->mi_keyp = _free(mi->mi_keyp); + mi = _free(mi); } rpmdb rpmdbGetIteratorRpmDB(rpmdbMatchIterator mi) { @@ -1284,20 +1263,14 @@ int rpmdbGetIteratorCount(rpmdbMatchIterator mi) { void rpmdbSetIteratorRelease(rpmdbMatchIterator mi, const char * release) { if (mi == NULL) return; - if (mi->mi_release) { - free((void *)mi->mi_release); - mi->mi_release = NULL; - } + mi->mi_release = _free(mi->mi_release); mi->mi_release = (release ? xstrdup(release) : NULL); } void rpmdbSetIteratorVersion(rpmdbMatchIterator mi, const char * version) { if (mi == NULL) return; - if (mi->mi_version) { - free((void *)mi->mi_version); - mi->mi_version = NULL; - } + mi->mi_version = _free(mi->mi_version); mi->mi_version = (version ? xstrdup(version) : NULL); } @@ -1619,6 +1592,8 @@ static INLINE int removeIndexEntry(dbiIndex dbi, DBC * dbcursor, /* XXX install.c uninstall.c */ int rpmdbRemove(rpmdb rpmdb, int rid, unsigned int hdrNum) { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; Header h; sigset_t signalMask; @@ -1644,7 +1619,7 @@ int rpmdbRemove(rpmdb rpmdb, int rid, unsigned int hdrNum) { const char *n, *v, *r; headerNVR(h, &n, &v, &r); - rpmMessage(RPMMESS_DEBUG, " --- %10d %s-%s-%s\n", hdrNum, n, v, r); + rpmMessage(RPMMESS_DEBUG, " --- %10u %s-%s-%s\n", hdrNum, n, v, r); } blockSignals(rpmdb, &signalMask); @@ -1686,8 +1661,7 @@ int rpmdbRemove(rpmdb rpmdb, int rid, unsigned int hdrNum) /*@notreached@*/ break; } - if (!headerGetEntry(h, rpmtag, &rpmtype, - (void **) &rpmvals, &rpmcnt)) + if (!hge(h, rpmtag, &rpmtype, (void **) &rpmvals, &rpmcnt)) continue; dbi = dbiOpen(rpmdb, rpmtag, 0); @@ -1759,7 +1733,7 @@ int rpmdbRemove(rpmdb rpmdb, int rid, unsigned int hdrNum) if (!dbi->dbi_no_dbsync) xx = dbiSync(dbi, 0); - rpmvals = headerFreeData(rpmvals, rpmtype); + rpmvals = hfd(rpmvals, rpmtype); rpmtype = 0; rpmcnt = 0; } @@ -1817,10 +1791,12 @@ static INLINE int addIndexEntry(dbiIndex dbi, DBC * dbcursor, /* XXX install.c */ int rpmdbAdd(rpmdb rpmdb, int iid, Header h) { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; sigset_t signalMask; const char ** baseNames; + int bnt; int count = 0; - int type; dbiIndex dbi; int dbix; unsigned int hdrNum; @@ -1839,7 +1815,7 @@ int rpmdbAdd(rpmdb rpmdb, int iid, Header h) * being written to the package header database. */ - headerGetEntry(h, RPMTAG_BASENAMES, &type, (void **) &baseNames, &count); + hge(h, RPMTAG_BASENAMES, &bnt, (void **) &baseNames, &count); if (_noDirTokens) expandFilelist(h); @@ -1927,23 +1903,22 @@ int rpmdbAdd(rpmdb rpmdb, int iid, Header h) xx = dbiSync(dbi, 0); { const char *n, *v, *r; headerNVR(h, &n, &v, &r); - rpmMessage(RPMMESS_DEBUG, " +++ %10d %s-%s-%s\n", hdrNum, n, v, r); + rpmMessage(RPMMESS_DEBUG, " +++ %10u %s-%s-%s\n", hdrNum, n, v, r); } continue; /*@notreached@*/ break; /* XXX preserve legacy behavior */ case RPMTAG_BASENAMES: - rpmtype = type; + rpmtype = bnt; rpmvals = baseNames; rpmcnt = count; break; case RPMTAG_REQUIRENAME: - headerGetEntry(h, rpmtag, &rpmtype, (void **)&rpmvals, &rpmcnt); - headerGetEntry(h, RPMTAG_REQUIREFLAGS, NULL, - (void **)&requireFlags, NULL); + hge(h, rpmtag, &rpmtype, (void **)&rpmvals, &rpmcnt); + hge(h, RPMTAG_REQUIREFLAGS, NULL, (void **)&requireFlags, NULL); break; default: - headerGetEntry(h, rpmtag, &rpmtype, (void **)&rpmvals, &rpmcnt); + hge(h, rpmtag, &rpmtype, (void **)&rpmvals, &rpmcnt); break; } @@ -2046,7 +2021,7 @@ int rpmdbAdd(rpmdb rpmdb, int iid, Header h) xx = dbiSync(dbi, 0); /*@-observertrans@*/ - rpmvals = headerFreeData(rpmvals, rpmtype); + rpmvals = hfd(rpmvals, rpmtype); /*@=observertrans@*/ rpmtype = 0; rpmcnt = 0; @@ -2068,6 +2043,8 @@ exit: int rpmdbFindFpList(rpmdb rpmdb, fingerPrint * fpList, dbiIndexSet * matchList, int numItems) { + HGE_t hge = (HGE_t)headerGetEntryMinMemory; + HFD_t hfd = headerFreeData; rpmdbMatchIterator mi; fingerPrintCache fpc; Header h; @@ -2095,6 +2072,7 @@ int rpmdbFindFpList(rpmdb rpmdb, fingerPrint * fpList, dbiIndexSet * matchList, const char ** dirNames; const char ** baseNames; const char ** fullBaseNames; + int bnt, dnt; int_32 * dirIndexes; int_32 * fullDirIndexes; fingerPrint * fps; @@ -2114,12 +2092,9 @@ int rpmdbFindFpList(rpmdb rpmdb, fingerPrint * fpList, dbiIndexSet * matchList, num = end - start; /* Compute fingerprints for this header's matches */ - headerGetEntryMinMemory(h, RPMTAG_BASENAMES, NULL, - (const void **) &fullBaseNames, NULL); - headerGetEntryMinMemory(h, RPMTAG_DIRNAMES, NULL, - (const void **) &dirNames, NULL); - headerGetEntryMinMemory(h, RPMTAG_DIRINDEXES, NULL, - (const void **) &fullDirIndexes, NULL); + hge(h, RPMTAG_BASENAMES, &bnt, (void **) &fullBaseNames, NULL); + hge(h, RPMTAG_DIRNAMES, &dnt, (void **) &dirNames, NULL); + hge(h, RPMTAG_DIRINDEXES, NULL, (void **) &fullDirIndexes, NULL); baseNames = xcalloc(num, sizeof(*baseNames)); dirIndexes = xcalloc(num, sizeof(*dirIndexes)); @@ -2137,11 +2112,11 @@ int rpmdbFindFpList(rpmdb rpmdb, fingerPrint * fpList, dbiIndexSet * matchList, dbiAppendSet(matchList[im->fpNum], im, 1, sizeof(*im), 0); } - free(fps); - free(dirNames); - free(fullBaseNames); - free(baseNames); - free(dirIndexes); + fps = _free(fps); + dirNames = hfd(dirNames, dnt); + fullBaseNames = hfd(fullBaseNames, bnt); + baseNames = _free(baseNames); + dirIndexes = _free(dirIndexes); mi->mi_setx = end; } @@ -2214,7 +2189,7 @@ static int rpmdbRemoveDatabase(const char * rootdir, sprintf(filename, "%s/%s/%s", rootdir, dbpath, base); (void)rpmCleanPath(filename); xx = unlink(filename); - free((void *)base); + base = _free(base); } break; } @@ -2323,7 +2298,7 @@ static int rpmdbMoveDatabase(const char * rootdir, (void)rpmCleanPath(nfilename); if ((xx = Rename(ofilename, nfilename)) != 0) rc = 1; - free((void *)base); + base = _free(base); } break; } @@ -2372,7 +2347,7 @@ int rpmdbRebuild(const char * rootdir) dbpath = rootdbpath = rpmGetPath(rootdir, tfn, NULL); if (!(rootdir[0] == '/' && rootdir[1] == '\0')) dbpath += strlen(rootdir); - free((void *)tfn); + tfn = _free(tfn); tfn = rpmGetPath("%{_dbpath_rebuild}", NULL); if (!(tfn && tfn[0] != '%' && strcmp(tfn, dbpath))) { @@ -2381,14 +2356,14 @@ int rpmdbRebuild(const char * rootdir) sprintf(pidbuf, "rebuilddb.%d", (int) getpid()); t = xmalloc(strlen(dbpath) + strlen(pidbuf) + 1); (void)stpcpy(stpcpy(t, dbpath), pidbuf); - if (tfn) free((void *)tfn); + tfn = _free(tfn); tfn = t; nocleanup = 0; } newdbpath = newrootdbpath = rpmGetPath(rootdir, tfn, NULL); if (!(rootdir[0] == '/' && rootdir[1] == '\0')) newdbpath += strlen(rootdir); - free((void *)tfn); + tfn = _free(tfn); rpmMessage(RPMMESS_DEBUG, _("rebuilding database %s into %s\n"), rootdbpath, newrootdbpath); @@ -2443,7 +2418,7 @@ int rpmdbRebuild(const char * rootdir) headerIsEntry(h, RPMTAG_BUILDTIME))) { rpmError(RPMERR_INTERNAL, - _("record number %d in database is bad -- skipping.\n"), + _("record number %u in database is bad -- skipping.\n"), _RECNUM); continue; } @@ -2482,7 +2457,7 @@ int rpmdbRebuild(const char * rootdir) if (rc) { rpmError(RPMERR_INTERNAL, - _("cannot add record originally at %d\n"), _RECNUM); + _("cannot add record originally at %u\n"), _RECNUM); failed = 1; break; } @@ -2525,8 +2500,8 @@ exit: rpmMessage(RPMMESS_ERROR, _("failed to remove directory %s: %s\n"), newrootdbpath, strerror(errno)); } - if (newrootdbpath) free((void *)newrootdbpath); - if (rootdbpath) free((void *)rootdbpath); + newrootdbpath = _free(newrootdbpath); + rootdbpath = _free(rootdbpath); return rc; } diff --git a/lib/rpmdb.h b/lib/rpmdb.h index 9beead972..fa84aba51 100644 --- a/lib/rpmdb.h +++ b/lib/rpmdb.h @@ -167,7 +167,7 @@ struct _dbiIndex { int dbi_tflags; /*!< dbenv->txn_begin flags */ int dbi_type; /*!< db index type */ - int dbi_mode; /*!< mode to use on open */ + unsigned dbi_mode; /*!< mode to use on open */ int dbi_perms; /*!< file permission to use on open */ int dbi_api; /*!< Berkeley API type */ diff --git a/lib/rpminstall.c b/lib/rpminstall.c index 0862e87f4..be239fd90 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -13,19 +13,10 @@ #include "debug.h" /*@access rpmTransactionSet@*/ /* XXX compared with NULL */ +/*@access rpmProblemSet@*/ /* XXX compared with NULL */ /*@access Header@*/ /* XXX compared with NULL */ /*@access FD_t@*/ /* XXX compared with NULL */ -/** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free - * @retval NULL always - */ -static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this) free((void *)this); - return NULL; -} - /* Define if you want percentage progress in the hash bars when * writing to a tty (ordinary hash bars otherwise) --claudio */ @@ -228,9 +219,10 @@ int rpmInstall(const char * rootdir, const char ** fileArgv, rc = rpmGlob(*fnp, &ac, &av); if (rc || ac == 0) continue; - argv = (argc == 0) - ? xmalloc((argc+2) * sizeof(*argv)) - : xrealloc(argv, (argc+2) * sizeof(*argv)); + if (argv == NULL) + argv = xmalloc((argc+ac+1) * sizeof(*argv)); + else + argv = xrealloc(argv, (argc+ac+1) * sizeof(*argv)); memcpy(argv+argc, av, ac * sizeof(*av)); argc += ac; argv[argc] = NULL; @@ -245,13 +237,15 @@ restart: /* Allocate sufficient storage for next set of args. */ if (pkgx >= numPkgs) { numPkgs = pkgx + argc; - pkgURL = (pkgURL == NULL) - ? xmalloc( (numPkgs + 1) * sizeof(*pkgURL)) - : xrealloc(pkgURL, (numPkgs + 1) * sizeof(*pkgURL)); + if (pkgURL == NULL) + pkgURL = xmalloc( (numPkgs + 1) * sizeof(*pkgURL)); + else + pkgURL = xrealloc(pkgURL, (numPkgs + 1) * sizeof(*pkgURL)); memset(pkgURL + pkgx, 0, ((argc + 1) * sizeof(*pkgURL))); - pkgState = (pkgState == NULL) - ? xmalloc( (numPkgs + 1) * sizeof(*pkgState)) - : xrealloc(pkgState, (numPkgs + 1) * sizeof(*pkgState)); + if (pkgState == NULL) + pkgState = xmalloc( (numPkgs + 1) * sizeof(*pkgState)); + else + pkgState = xrealloc(pkgState, (numPkgs + 1) * sizeof(*pkgState)); memset(pkgState + pkgx, 0, ((argc + 1) * sizeof(*pkgState))); } @@ -333,10 +327,13 @@ restart: if ((rpmrc == RPMRC_OK || rpmrc == RPMRC_BADSIZE) && isSource) { rpmMessage(RPMMESS_DEBUG, "\tadded source package [%d]\n", numSRPMS); - sourceURL = (sourceURL == NULL) - ? xmalloc( (numSRPMS + 2) * sizeof(*sourceURL)) - : xrealloc(sourceURL, (numSRPMS + 2) * sizeof(*sourceURL)); + if (sourceURL == NULL) + sourceURL = xmalloc((numSRPMS + 2) * sizeof(*sourceURL)); + else + sourceURL = xrealloc(sourceURL, + (numSRPMS + 2) * sizeof(*sourceURL)); sourceURL[numSRPMS++] = *fnp; + sourceURL[numSRPMS] = NULL; *fnp = NULL; continue; } @@ -400,7 +397,6 @@ restart: if (count == 0) { headerFree(h); continue; - break; /* XXX out of switch */ } /* Package is newer than those currently installed. */ } @@ -516,7 +512,7 @@ restart: rpmProblemSetPrint(stderr, probs); } - if (probs) rpmProblemSetFree(probs); + if (probs != NULL) rpmProblemSetFree(probs); } if (numSRPMS && !stopInstall) { diff --git a/lib/rpmlib.h b/lib/rpmlib.h index 3046b95af..4fa11bec0 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -32,6 +32,16 @@ extern "C" { #endif /** + * 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; +} + +/** * Return package signatures and header from file handle. * @param fd file handle * @retval signatures address of signatures pointer (or NULL) @@ -858,10 +868,14 @@ typedef int (*HGE_t) (Header h, int_32 tag, /*@out@*/ int_32 * type, /*@out@*/ void ** p, /*@out@*/int_32 * c) /*@modifies *type, *p, *c @*/; -/* we pass these around as an array with a sentinel */ +/** + * We pass these around as an array with a sentinel. + */ typedef struct rpmRelocation_s { - const char * oldPath; /*!< NULL here evals to RPMTAG_DEFAULTPREFIX, */ - const char * newPath; /*!< NULL means to omit the file completely! */ +/*@only@*/ /*@null@*/ const char * oldPath; + /*!< NULL here evals to RPMTAG_DEFAULTPREFIX, */ +/*@only@*/ /*@null@*/ const char * newPath; + /*!< NULL means to omit the file completely! */ } rpmRelocation; /** @@ -878,7 +892,7 @@ rpmRC rpmInstallSourcePackage(const char * root, FD_t fd, /*@out@*/ const char ** specFile, rpmCallbackFunction notify, rpmCallbackData notifyData, /*@out@*/ char ** cookie) - /*@modifies *specFile, *cookie @*/; + /*@modifies fd, *specFile, *cookie @*/; /** * Compare headers to determine which header is "newer". @@ -1386,8 +1400,8 @@ typedef struct rpmQVArguments { int qva_sourceCount;/*!< Exclusive check (>1 is error). */ int qva_flags; /*!< Bit(s) to control operation. */ int qva_verbose; /*!< (unused) */ - const char *qva_queryFormat;/*!< Format for headerSprintf(). */ - const char *qva_prefix; /*!< Path to top of install tree. */ +/*@only@*/ const char *qva_queryFormat;/*!< Format for headerSprintf(). */ +/*@dependent@*/ const char *qva_prefix; /*!< Path to top of install tree. */ char qva_mode; /*!< 'q' is query, 'v' is verify mode. */ char qva_char; /*!< (unused) always ' ' */ } QVA_t; diff --git a/lib/rpmrc.c b/lib/rpmrc.c index 55b4272d6..2ac66987b 100644 --- a/lib/rpmrc.c +++ b/lib/rpmrc.c @@ -144,7 +144,7 @@ static int machCompatCacheAdd(char * name, const char * fn, int linenum, int i; struct machCacheEntry * entry = NULL; - while (*name && isspace(*name)) name++; + while (*name && xisspace(*name)) name++; chptr = name; while (*chptr && *chptr != ':') chptr++; @@ -157,10 +157,10 @@ static int machCompatCacheAdd(char * name, const char * fn, int linenum, return 1; } - while (*chptr == ':' || isspace(*chptr)) chptr--; + while (*chptr == ':' || xisspace(*chptr)) chptr--; *(++chptr) = '\0'; equivs = chptr + 1; - while (*equivs && isspace(*equivs)) equivs++; + while (*equivs && xisspace(*equivs)) equivs++; if (!*equivs) { delEntry = 1; } @@ -169,9 +169,8 @@ static int machCompatCacheAdd(char * name, const char * fn, int linenum, entry = machCacheFindEntry(cache, name); if (entry) { for (i = 0; i < entry->count; i++) - free((void *)entry->equivs[i]); - free((void *)entry->equivs); - entry->equivs = NULL; + entry->equivs[i] = _free(entry->equivs[i]); + entry->equivs = _free(entry->equivs); entry->count = 0; } } @@ -266,12 +265,11 @@ static void machFindEquivs(struct machCache * cache, cache->cache[i].visited = 0; while (table->count > 0) { - free((void *)table->list[--table->count].name); - table->list[table->count].name = NULL; + --table->count; + table->list[table->count].name = _free(table->list[table->count].name); } table->count = 0; - if (table->list) free((void *)table->list); - table->list = NULL; + table->list = _free(table->list); /* * We have a general graph built using strings instead of pointers. @@ -409,8 +407,8 @@ int rpmReadConfigFiles(const char * file, const char * target) { const char *cpu = rpmExpand("%{_target_cpu}", NULL); const char *os = rpmExpand("%{_target_os}", NULL); rpmSetMachine(cpu, os); - free((void *)cpu); - free((void *)os); + cpu = _free(cpu); + os = _free(os); } return 0; @@ -445,7 +443,7 @@ static void setPathDefault(int var, const char *macroname, const char *subdir) strcat(fn, subdir); rpmSetVar(var, fn); - if (topdir) free((void *)topdir); + topdir = _free(topdir); } if (macroname != NULL) { @@ -577,17 +575,17 @@ int rpmReadRC(const char * rcfiles) } if (rc) break; } - if (myrcfiles) free(myrcfiles); + myrcfiles = _free(myrcfiles); if (rc) return rc; rpmSetMachine(NULL, NULL); /* XXX WTFO? Why bother? */ - { const char *macrofiles; - if ((macrofiles = rpmGetVar(RPMVAR_MACROFILES)) != NULL) { - macrofiles = strdup(macrofiles); - rpmInitMacros(NULL, macrofiles); - free((void *)macrofiles); + { const char *mfpath; + if ((mfpath = rpmGetVar(RPMVAR_MACROFILES)) != NULL) { + mfpath = xstrdup(mfpath); + rpmInitMacros(NULL, mfpath); + mfpath = _free(mfpath); } } @@ -624,38 +622,38 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) next[nb + 1] = '\0'; } - while (*next) { + while (*next != '\0') { linenum++; s = se = next; /* Find end-of-line. */ while (*se && *se != '\n') se++; - if (*se) *se++ = '\0'; + if (*se != '\0') *se++ = '\0'; next = se; /* Trim leading spaces */ - while (*s && isspace(*s)) s++; + while (*s && xisspace(*s)) s++; /* We used to allow comments to begin anywhere, but not anymore. */ if (*s == '#' || *s == '\0') continue; /* Find end-of-keyword. */ se = (char *)s; - while (*se && !isspace(*se) && *se != ':') se++; + while (*se && !xisspace(*se) && *se != ':') se++; - if (isspace(*se)) { + if (xisspace(*se)) { *se++ = '\0'; - while (*se && isspace(*se) && *se != ':') se++; + while (*se && xisspace(*se) && *se != ':') se++; } if (*se != ':') { rpmError(RPMERR_RPMRC, _("missing ':' (found 0x%02x) at %s:%d\n"), - (0xff & *se), urlfn, linenum); + (unsigned)(0xff & *se), urlfn, linenum); return 1; } *se++ = '\0'; /* terminate keyword or option, point to value */ - while (*se && isspace(*se)) se++; + while (*se && xisspace(*se)) se++; /* Find keyword in table */ searchOption.name = s; @@ -677,8 +675,8 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) { FD_t fdinc; s = se; - while (*se && !isspace(*se)) se++; - if (*se) *se++ = '\0'; + while (*se && !xisspace(*se)) se++; + if (*se != '\0') *se++ = '\0'; rpmRebuildTargetVars(NULL, NULL); @@ -686,7 +684,7 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) if (fn == NULL || *fn == '\0') { rpmError(RPMERR_RPMRC, _("%s expansion failed at %s:%d \"%s\"\n"), option->name, urlfn, linenum, s); - if (fn) free((void *)fn); + fn = _free(fn); return 1; /*@notreached@*/ } @@ -699,7 +697,7 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) } else { rc = doReadRC(fdinc, fn); } - if (fn) free((void *)fn); + fn = _free(fn); if (rc) return rc; continue; /* XXX don't save include value as var/macro */ } /*@notreached@*/ break; @@ -708,7 +706,7 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) if (fn == NULL || *fn == '\0') { rpmError(RPMERR_RPMRC, _("%s expansion failed at %s:%d \"%s\"\n"), option->name, urlfn, linenum, fn); - if (fn) free((void *)fn); + fn = _free(fn); return 1; } se = (char *)fn; @@ -718,9 +716,9 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) s = rpmGetVar(RPMVAR_PROVIDES); if (s == NULL) s = ""; fn = t = xmalloc(strlen(s) + strlen(se) + 2); - while (*s) *t++ = *s++; + while (*s != '\0') *t++ = *s++; *t++ = ' '; - while (*se) *t++ = *se++; + while (*se != '\0') *t++ = *se++; *t++ = '\0'; se = (char *)fn; } break; @@ -730,7 +728,7 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) if (option->archSpecific) { arch = se; - while (*se && !isspace(*se)) se++; + while (*se && !xisspace(*se)) se++; if (*se == '\0') { rpmError(RPMERR_RPMRC, _("missing architecture for %s at %s:%d\n"), @@ -738,7 +736,7 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) return 1; } *se++ = '\0'; - while (*se && isspace(*se)) se++; + while (*se && xisspace(*se)) se++; if (*se == '\0') { rpmError(RPMERR_RPMRC, _("missing argument for %s at %s:%d\n"), @@ -761,7 +759,7 @@ static int doReadRC( /*@killref@*/ FD_t fd, const char * urlfn) free(name); } rpmSetVarArch(option->var, val, arch); - if (fn) free((void *)fn); + fn = _free(fn); } else { /* For arch/os compatibilty tables ... */ int gotit; @@ -975,7 +973,7 @@ static void defaultMachine(/*@out@*/ const char ** arch, /*@out@*/ const char ** for (fd = 0; (un.release[fd] != 0 && (fd < sizeof(un.release))); fd++) { - if (!isdigit(un.release[fd]) && (un.release[fd] != '.')) { + if (!xisdigit(un.release[fd]) && (un.release[fd] != '.')) { un.release[fd] = 0; break; } @@ -1031,7 +1029,7 @@ static void defaultMachine(/*@out@*/ const char ** arch, /*@out@*/ const char ** #endif /* __linux__ */ /* get rid of the hyphens in the sysname */ - for (chptr = un.machine; *chptr; chptr++) + for (chptr = un.machine; *chptr != '\0'; chptr++) if (*chptr == '/') *chptr = '-'; # if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) @@ -1193,16 +1191,10 @@ static void freeRpmVar(struct rpmvarValue * orig) { while (var) { next = var->next; - if (var->arch) { - free((void *)var->arch); - var->arch = NULL; - } - if (var->value) { - free((void *)var->value); - var->value = NULL; - } + var->arch = _free(var->arch); + var->value = _free(var->value); - if (var != orig) free(var); + if (var != orig) var = _free(var); var = next; } } @@ -1229,8 +1221,8 @@ static void rpmSetVarArch(int var, const char * val, const char * arch) { } if (next->arch && arch && !strcmp(next->arch, arch)) { - if (next->value) free((void *)next->value); - if (next->arch) free((void *)next->arch); + next->value = _free(next->value); + next->arch = _free(next->arch); } else if (next->arch || arch) { next->next = xmalloc(sizeof(*next->next)); next = next->next; @@ -1296,14 +1288,14 @@ void rpmSetMachine(const char * arch, const char * os) { } if (!current[ARCH] || strcmp(arch, current[ARCH])) { - if (current[ARCH]) free((void *)current[ARCH]); + current[ARCH] = _free(current[ARCH]); current[ARCH] = xstrdup(arch); rebuildCompatTables(ARCH, host_cpu); } if (!current[OS] || strcmp(os, current[OS])) { char * t = xstrdup(os); - if (current[OS]) free((void *)current[OS]); + current[OS] = _free(current[OS]); /* * XXX Capitalizing the 'L' is needed to insure that old * XXX os-from-uname (e.g. "Linux") is compatible with the new @@ -1408,16 +1400,16 @@ void rpmRebuildTargetVars(const char **buildtarget, const char ** canontarget) defaultMachine(&a, NULL); ca = (a) ? xstrdup(a) : NULL; } - for (x = 0; ca[x]; x++) - ca[x] = tolower(ca[x]); + for (x = 0; ca[x] != '\0'; x++) + ca[x] = xtolower(ca[x]); if (co == NULL) { const char *o = NULL; defaultMachine(NULL, &o); co = (o) ? xstrdup(o) : NULL; } - for (x = 0; co[x]; x++) - co[x] = tolower(co[x]); + for (x = 0; co[x] != '\0'; x++) + co[x] = xtolower(co[x]); /* XXX For now, set canonical target to arch-os */ if (ct == NULL) { @@ -1448,9 +1440,9 @@ void rpmRebuildTargetVars(const char **buildtarget, const char ** canontarget) if (canontarget) *canontarget = ct; else - free(ct); - free(ca); - free(co); + ct = _free(ct); + ca = _free(ca); + co = _free(co); } void rpmFreeRpmrc(void) @@ -1461,11 +1453,9 @@ void rpmFreeRpmrc(void) struct tableType *t; t = tables + i; if (t->equiv.list) { - for (j = 0; j < t->equiv.count; j++) { - if (t->equiv.list[j].name) free((void *)t->equiv.list[j].name); - } - free((void *)t->equiv.list); - t->equiv.list = NULL; + for (j = 0; j < t->equiv.count; j++) + t->equiv.list[j].name = _free(t->equiv.list[j].name); + t->equiv.list = _free(t->equiv.list); t->equiv.count = 0; } if (t->cache.cache) { @@ -1473,34 +1463,30 @@ void rpmFreeRpmrc(void) struct machCacheEntry *e; e = t->cache.cache + j; if (e == NULL) continue; - if (e->name) free((void *)e->name); + e->name = _free(e->name); if (e->equivs) { - for (k = 0; k < e->count; k++) { - if (e->equivs[k]) free((void *)e->equivs[k]); - } - free((void *)e->equivs); + for (k = 0; k < e->count; k++) + e->equivs[k] = _free(e->equivs[k]); + e->equivs = _free(e->equivs); } } - free((void *)t->cache.cache); - t->cache.cache = NULL; + t->cache.cache = _free(t->cache.cache); t->cache.size = 0; } if (t->defaults) { for (j = 0; j < t->defaultsLength; j++) { - if (t->defaults[j].name) free((void *)t->defaults[j].name); - if (t->defaults[j].defName) free((void *)t->defaults[j].defName); + t->defaults[j].name = _free(t->defaults[j].name); + t->defaults[j].defName = _free(t->defaults[j].defName); } - free((void *)t->defaults); - t->defaults = NULL; + t->defaults = _free(t->defaults); t->defaultsLength = 0; } if (t->canons) { for (j = 0; j < t->canonsLength; j++) { - if (t->canons[j].name) free((void *)t->canons[j].name); - if (t->canons[j].short_name) free((void *)t->canons[j].short_name); + t->canons[j].name = _free(t->canons[j].name); + t->canons[j].short_name = _free(t->canons[j].short_name); } - free((void *)t->canons); - t->canons = NULL; + t->canons = _free(t->canons); t->canonsLength = 0; } } @@ -1509,23 +1495,15 @@ void rpmFreeRpmrc(void) struct rpmvarValue *this; while ((this = values[i].next) != NULL) { values[i].next = this->next; - if (this->value) free((void *)this->value); - if (this->arch) free((void *)this->arch); - free((void *)this); + this->value = _free(this->value); + this->arch = _free(this->arch); + this = _free(this); } - if (values[i].value) - free((void *)values[i].value); - values[i].value = NULL; - if (values[i].arch) - free((void *)values[i].arch); - values[i].arch = NULL; + values[i].value = _free(values[i].value); + values[i].arch = _free(values[i].arch); } - if (current[OS]) - free((void *)current[OS]); - current[OS] = NULL; - if (current[ARCH]) - free((void *)current[ARCH]); - current[ARCH] = NULL; + current[OS] = _free(current[OS]); + current[ARCH] = _free(current[ARCH]); defaultsInitialized = 0; return; } diff --git a/lib/signature.c b/lib/signature.c index f4894fa14..908319a7f 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -60,7 +60,7 @@ int rpmLookupSignatureType(int action) rc = RPMSIGTAG_GPG; else rc = -1; /* Invalid %_signature spec in macro file */ - free((void *)name); + name = _free(name); } break; } return rc; @@ -83,7 +83,7 @@ const char * rpmDetectPGPVersion(pgpVersion * pgpVer) struct stat st; if (!(pgpbin && pgpbin[0] != '%')) { - if (pgpbin) free((void *)pgpbin); + pgpbin = _free(pgpbin); saved_pgp_version = -1; return NULL; } @@ -131,10 +131,10 @@ static inline rpmRC checkSize(FD_t fd, int siglen, int pad, int datalen) rpmMessage((rc == RPMRC_OK ? RPMMESS_DEBUG : RPMMESS_WARNING), _("Expected size: %12d = lead(%d)+sigs(%d)+pad(%d)+data(%d)\n"), - sizeof(struct rpmlead)+siglen+pad+datalen, - sizeof(struct rpmlead), siglen, pad, datalen); + (int)sizeof(struct rpmlead)+siglen+pad+datalen, + (int)sizeof(struct rpmlead), siglen, pad, datalen); rpmMessage((rc == RPMRC_OK ? RPMMESS_DEBUG : RPMMESS_WARNING), - _(" Actual size: %12d\n"), st.st_size); + _(" Actual size: %12d\n"), (int)st.st_size); return rc; } @@ -525,7 +525,7 @@ verifyPGPSignature(const char * datafile, const void * sig, int count, /* Write out the signature */ { const char *tmppath = rpmGetPath("%{_tmppath}", NULL); sigfile = tempnam(tmppath, "rpmsig"); - free((void *)tmppath); + tmppath = _free(tmppath); } sfd = Fopen(sigfile, "w.fdio"); (void)Fwrite(sig, sizeof(char), count, sfd); @@ -620,7 +620,7 @@ verifyGPGSignature(const char * datafile, const void * sig, int count, /* Write out the signature */ { const char *tmppath = rpmGetPath("%{_tmppath}", NULL); sigfile = tempnam(tmppath, "rpmsig"); - free((void *)tmppath); + tmppath = _free(tmppath); } sfd = Fopen(sigfile, "w.fdio"); (void)Fwrite(sig, sizeof(char), count, sfd); @@ -766,7 +766,7 @@ char *rpmGetPassPhrase(const char * prompt, const int sigTag) case RPMSIGTAG_GPG: { const char *name = rpmExpand("%{_gpg_name}", NULL); aok = (name && *name != '%'); - free((void *)name); + name = _free(name); } if (!aok) { rpmError(RPMERR_SIGGEN, @@ -778,7 +778,7 @@ char *rpmGetPassPhrase(const char * prompt, const int sigTag) case RPMSIGTAG_PGP: { const char *name = rpmExpand("%{_pgp_name}", NULL); aok = (name && *name != '%'); - free((void *)name); + name = _free(name); } if (!aok) { rpmError(RPMERR_SIGGEN, diff --git a/lib/stringbuf.c b/lib/stringbuf.c index 3c3d3ff78..0be19a708 100644 --- a/lib/stringbuf.c +++ b/lib/stringbuf.c @@ -9,6 +9,13 @@ #define BUF_CHUNK 1024 +/** + * Locale insensitive isspace(3). + */ +/*@unused@*/ static inline int xisspace(int c) { + 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 */ @@ -48,7 +55,7 @@ void truncStringBuf(StringBuf sb) void stripTrailingBlanksStringBuf(StringBuf sb) { while (sb->free != sb->allocated) { - if (! isspace(*(sb->tail - 1))) { + if (! xisspace(*(sb->tail - 1))) { break; } sb->free++; diff --git a/lib/tagName.c b/lib/tagName.c index 38cd8ead9..02c9fa137 100644 --- a/lib/tagName.c +++ b/lib/tagName.c @@ -41,8 +41,8 @@ const char *const tagName(int tag) if (tag != rpmTagTable[i].val) continue; strcpy(nameBuf, rpmTagTable[i].name + 7); - for (s = nameBuf+1; *s; s++) - *s = tolower(*s); + for (s = nameBuf+1; *s != '\0'; s++) + *s = xtolower(*s); break; } return nameBuf; diff --git a/lib/transaction.c b/lib/transaction.c index 190446236..b80c64d54 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -62,17 +62,6 @@ struct diskspaceInfo { #define XSTRCMP(a, b) ((!(a) && !(b)) || ((a) && (b) && !strcmp((a), (b)))) - -/** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free - * @retval NULL always - */ -static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this) free((void *)this); - return NULL; -} - static void freeFl(rpmTransactionSet ts, TFI_t flList) { TFI_t fi; @@ -1294,17 +1283,17 @@ static void skipFiles(const rpmTransactionSet ts, TFI_t fi) */ if (fi->flangs && languages && *fi->flangs[i]) { const char **lang, *l, *le; - for (lang = languages; *lang; lang++) { + for (lang = languages; *lang != '\0'; lang++) { if (!strcmp(*lang, "all")) break; - for (l = fi->flangs[i]; *l; l = le) { - for (le = l; *le && *le != '|'; le++) + for (l = fi->flangs[i]; *l != '\0'; l = le) { + for (le = l; *le != '\0' && *le != '|'; le++) ; if ((le-l) > 0 && !strncmp(*lang, l, (le-l))) break; if (*le == '|') le++; /* skip over | */ } - if (*l) break; + if (*l != '\0') break; } if (*lang == NULL) { drc[ix]--; dff[ix] = 1; diff --git a/lib/verify.c b/lib/verify.c index 32a28bb8a..eb4acef2e 100644 --- a/lib/verify.c +++ b/lib/verify.c @@ -13,8 +13,10 @@ #include "misc.h" #include "debug.h" -/*@ access TFI_t */ -/*@ access PSM_t */ +/*@access TFI_t*/ +/*@access PSM_t*/ +/*@access FD_t*/ /* XXX compared with NULL */ +/*@access rpmdb*/ /* XXX compared with NULL */ static int _ie = 0x44332211; static union _vendian { int i; char b[4]; } *_endian = (union _vendian *)&_ie; @@ -69,16 +71,6 @@ struct poptOption rpmVerifyPoptTable[] = { POPT_TABLEEND }; -/** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param this memory to free - * @retval NULL always - */ -static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this) free((void *)this); - return NULL; -} - /* ======================================================================== */ int rpmVerifyFile(const char * prefix, Header h, int filenum, int * result, int omitMask) @@ -298,7 +290,7 @@ int rpmVerifyScript(const char * rootDir, Header h, FD_t scriptFd) PSM_t psm = &psmbuf; int rc; - if (scriptFd) + if (scriptFd != NULL) ts->scriptFd = fdLink(scriptFd, "rpmVerifyScript"); fi->magic = TFIMAGIC; loadFi(h, fi); @@ -493,7 +485,7 @@ int rpmVerify(QVA_t *qva, rpmQVSources source, const char *arg) rc = rpmQueryVerify(qva, source, arg, rpmdb, showVerifyPackage); - if (rpmdb) + if (rpmdb != NULL) rpmdbClose(rpmdb); return rc; diff --git a/popt/popt.h b/popt/popt.h index f66db84f3..70bb40869 100644 --- a/popt/popt.h +++ b/popt/popt.h @@ -169,9 +169,11 @@ typedef void (*poptCallbackType) (poptContext con, * @param flags or'd POPT_CONTEXT_* bits * @return initialized popt context */ -/*@only@*/ poptContext poptGetContext(/*@keep@*/ const char * name, - int argc, /*@keep@*/ const char ** argv, - /*@keep@*/ const struct poptOption * options, int flags); +/*@only@*/ poptContext poptGetContext( + /*@dependent@*/ /*@keep@*/ const char * name, + int argc, /*@dependent@*/ /*@keep@*/ const char ** argv, + /*@dependent@*/ /*@keep@*/ const struct poptOption * options, + int flags); /** \ingroup popt * Reinitialize popt context. diff --git a/rpmio/.lclintrc b/rpmio/.lclintrc index c5e1d3e49..5da960259 100644 --- a/rpmio/.lclintrc +++ b/rpmio/.lclintrc @@ -11,20 +11,20 @@ -unrecogcomments # don't-bother-me-yet parameters --branchstate +-branchstate # ~43 occurences #-immediatetrans --mustfree +-mustfree # alloca is painful #-observertrans #-statictrans # not-yet normal parameters -boolops # w->n --fixedformalarray --null --predboolint # w->n --predboolothers # w->n --retvalint # w->n --type +#-fixedformalarray +-null # ugh +-predboolint # w->n ~144 +#-predboolothers # w->n ~8 +-retvalint # w->n ~48 +-type # ~449 # not-yet -weak paramaters #+boolint diff --git a/rpmio/digest.c b/rpmio/digest.c index 434ce6acf..8fa83dea4 100644 --- a/rpmio/digest.c +++ b/rpmio/digest.c @@ -9,6 +9,8 @@ typedef unsigned int uint32; typedef unsigned char byte; +/*@access DIGEST_CTX@*/ + /** * MD5/SHA1 digest private data. */ diff --git a/rpmio/macro.c b/rpmio/macro.c index 301c7addf..9fb896507 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -378,7 +378,7 @@ printExpansion(MacroBuf *mb, const char *t, const char *te) #define COPYNAME(_ne, _s, _c) \ { SKIPBLANK(_s,_c); \ - while(((_c) = *(_s)) && (isalnum(_c) || (_c) == '_')) \ + while(((_c) = *(_s)) && (xisalnum(_c) || (_c) == '_')) \ *(_ne)++ = *(_s)++; \ *(_ne) = '\0'; \ } @@ -578,7 +578,7 @@ doDefine(MacroBuf *mb, const char *se, int level, int expandbody) se = s; /* Names must start with alphabetic or _ and be at least 3 chars */ - if (!((c = *n) && (isalpha(c) || c == '_') && (ne - n) > 2)) { + if (!((c = *n) && (xisalpha(c) || c == '_') && (ne - n) > 2)) { rpmError(RPMERR_BADSPEC, _("Macro %%%s has illegal name (%%define)\n"), n); return se; @@ -627,7 +627,7 @@ doUndefine(MacroContext *mc, const char *se) se = s; /* Names must start with alphabetic or _ and be at least 3 chars */ - if (!((c = *n) && (isalpha(c) || c == '_') && (ne - n) > 2)) { + if (!((c = *n) && (xisalpha(c) || c == '_') && (ne - n) > 2)) { rpmError(RPMERR_BADSPEC, _("Macro %%%s has illegal name (%%undefine)\n"), n); return se; @@ -947,7 +947,7 @@ doFoo(MacroBuf *mb, int negate, const char *f, size_t fn, const char *g, size_t } b = be; } else if (STREQ("S", f, fn)) { - for (b = buf; (c = *b) && isdigit(c);) + for (b = buf; (c = *b) && xisdigit(c);) b++; if (!c) { /* digit index */ b++; @@ -955,7 +955,7 @@ doFoo(MacroBuf *mb, int negate, const char *f, size_t fn, const char *g, size_t } else b = buf; } else if (STREQ("P", f, fn)) { - for (b = buf; (c = *b) && isdigit(c);) + for (b = buf; (c = *b) && xisdigit(c);) b++; if (!c) { /* digit index */ b++; @@ -1041,7 +1041,7 @@ expandMacro(MacroBuf *mb) f = se = s; if (*se == '-') se++; - while((c = *se) && (isalnum(c) || c == '_')) + while((c = *se) && (xisalnum(c) || c == '_')) se++; /* Recognize non-alnum macros too */ switch (*se) { @@ -1256,7 +1256,7 @@ expandMacro(MacroBuf *mb) /* Setup args for "%name " macros with opts */ if (me && me->opts != NULL) { - if (grab) { + if (grab != '\0') { se = grabArgs(mb, me, fe, grab); } else { addMacro(mb->mc, "**", NULL, "", mb->depth); @@ -1407,7 +1407,7 @@ rpmInitMacros(MacroContext *mc, const char *macrofiles) if (mc == NULL) mc = &rpmGlobalMacroContext; - for (mfile = m = xstrdup(macrofiles); *mfile; mfile = me) { + for (mfile = m = xstrdup(macrofiles); *mfile != '\0'; mfile = me) { FD_t fd; char buf[BUFSIZ]; @@ -1595,7 +1595,7 @@ char *rpmCleanPath(char * path) /*fprintf(stderr, "*** RCP %s ->\n", path); */ s = t = te = path; - while (*s) { + while (*s != '\0') { /*fprintf(stderr, "*** got \"%.*s\"\trest \"%s\"\n", (t-path), path, s); */ switch(*s) { case ':': /* handle url's */ diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index d7edec90e..d9b5606a5 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -93,6 +93,16 @@ static int httpTimeoutSecs = TIMEOUT_SECS; int _ftp_debug = 0; int _rpmio_debug = 0; +/** + * 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; +} + /* =============================================================== */ static /*@observer@*/ const char * fdbg(FD_t fd) @@ -237,8 +247,8 @@ DBGREFS(0, (stderr, "--> fd %p -- %d %s at %s:%u\n", fd, FDNREFS(fd), msg, file DBGREFS(fd, (stderr, "--> fd %p -- %d %s at %s:%u %s\n", fd, fd->nrefs, msg, file, line, fdbg(fd))); if (--fd->nrefs > 0) /*@-refcounttrans@*/ return fd; /*@=refcounttrans@*/ - if (fd->stats) free(fd->stats); - if (fd->digest) free(fd->digest); + fd->stats = _free(fd->stats); + fd->digest = _free(fd->digest); /*@-refcounttrans@*/ free(fd); /*@=refcounttrans@*/ } return NULL; @@ -608,7 +618,7 @@ static int mygethostbyname(const char * host, struct in_addr * address) static int getHostAddress(const char * host, struct in_addr * address) { - if (isdigit(host[0])) { + if (xisdigit(host[0])) { if (! /*@-unrecog@*/ inet_aton(host, address) /*@=unrecog@*/ ) { return FTPERR_BAD_HOST_ADDR; } @@ -798,7 +808,7 @@ fprintf(stderr, "<- %s\n", s); /* FTP: look for "123-" and/or "123 " */ if (strchr("0123456789", *s)) { - if (errorCode[0]) { + if (errorCode[0] != '\0') { if (!strncmp(s, errorCode, sizeof("123")-1) && s[3] == ' ') moretodo = 0; } else { @@ -1027,7 +1037,7 @@ int ftpReq(FD_t data, const char * ftpCmd, const char * ftpArg) } chptr = passReply; - while (*chptr++) { + while (*chptr++ != '\0') { if (*chptr == ',') *chptr = '.'; } @@ -2407,9 +2417,9 @@ static inline void cvtfmode (const char *m, } *stdio = *other = '\0'; - if (end) - *end = (*m ? m : NULL); - if (f) + if (end != NULL) + *end = (*m != '\0' ? m : NULL); + if (f != NULL) *f = flags; } @@ -2474,7 +2484,7 @@ fprintf(stderr, "*** Fdopen fpio fp %p\n", fp); fdPush(fd, fpio, fp, fdno); /* Push fpio onto stack */ } } - } else if (other[0]) { + } else if (other[0] != '\0') { for (end = other; *end && strchr("0123456789fh", *end); end++) ; if (*end == '\0') { diff --git a/rpmio/rpmio.h b/rpmio/rpmio.h index e8896d5ec..40e4d9c8e 100644 --- a/rpmio/rpmio.h +++ b/rpmio/rpmio.h @@ -430,6 +430,27 @@ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length); /*@observer@*/ extern FDIO_t fadio; /*@}*/ +/*@unused@*/ static inline int xislower(int c) {return (c >= 'a' && c <= 'z');} +/*@unused@*/ static inline int xisupper(int c) {return (c >= 'A' && c <= 'Z');} +/*@unused@*/ static inline int xisalpha(int c) { + return (xislower(c) || xisupper(c)); +} +/*@unused@*/ static inline int xisdigit(int c) {return (c >= '0' && c <= '9');} +/*@unused@*/ static inline int xisalnum(int c) { + return (xisalpha(c) || xisdigit(c)); +} +/*@unused@*/ static inline int xisblank(int c) {return (c == ' ' || c == '\t');} +/*@unused@*/ static inline int xisspace(int c) { + return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v'); +} + +/*@unused@*/ static inline int xtolower(int c) { + return ((xisupper(c)) ? (c | ('a' - 'A')) : c); +} +/*@unused@*/ static inline int xtoupper(int c) { + return ((xislower(c)) ? (c & ~('a' - 'A')) : c); +} + /** \ingroup rpmio * Locale insensitive strcasecmp(3). */ diff --git a/rpmio/rpmlog.c b/rpmio/rpmlog.c index 526aae3a6..94e4d1ecb 100644 --- a/rpmio/rpmlog.c +++ b/rpmio/rpmlog.c @@ -112,6 +112,7 @@ static void vrpmlog (unsigned code, const char *fmt, va_list ap) int mask = RPMLOG_MASK(pri); /*@unused@*/ int fac = RPMLOG_FAC(code); char *msgbuf, *msg; + int freeMsgbuf = 1; int msgnb = BUFSIZ, nb; FILE * msgout = stderr; rpmlogRec rec; @@ -125,10 +126,8 @@ static void vrpmlog (unsigned code, const char *fmt, va_list ap) /* Allocate a sufficently large buffer for output. */ while (1) { va_list apc; - __va_copy(apc, ap); - /*@-unrecog@*/ - nb = vsnprintf(msgbuf, msgnb, fmt, apc); - /*@=unrecog@*/ + /*@-sysunrecog@*/ __va_copy(apc, ap); /*@=sysunrecog@*/ + /*@-unrecog@*/ nb = vsnprintf(msgbuf, msgnb, fmt, apc); /*@=unrecog@*/ if (nb > -1 && nb < msgnb) break; if (nb > -1) /* glibc 2.1 */ @@ -154,12 +153,10 @@ static void vrpmlog (unsigned code, const char *fmt, va_list ap) rec->code = code; rec->message = msgbuf; - msgbuf = NULL; + freeMsgbuf = 0; if (_rpmlogCallback) { _rpmlogCallback(); - if (msgbuf) - free(msgbuf); return; /* XXX Preserve legacy rpmError behavior. */ } } @@ -181,15 +178,12 @@ static void vrpmlog (unsigned code, const char *fmt, va_list ap) break; } - /* Silly FORTRAN-like carriage control. */ - if (*msg == '+') - msg++; - else if (rpmlogMsgPrefix[pri] && *rpmlogMsgPrefix[pri]) + if (rpmlogMsgPrefix[pri] && *rpmlogMsgPrefix[pri]) fputs(_(rpmlogMsgPrefix[pri]), msgout); fputs(msg, msgout); fflush(msgout); - if (msgbuf) + if (freeMsgbuf) free(msgbuf); if (pri <= RPMLOG_CRIT) exit(EXIT_FAILURE); diff --git a/rpmio/rpmlog.h b/rpmio/rpmlog.h index b259c3531..24c7164d7 100644 --- a/rpmio/rpmlog.h +++ b/rpmio/rpmlog.h @@ -208,7 +208,7 @@ int rpmlogSetMask (int mask); /** * Generate a log message using FMT string and option arguments. */ -void rpmlog (int pri, const char *fmt, ...); +/*@mayexit@*/ /*@printflike@*/ void rpmlog (int pri, const char *fmt, ...); /** * Set rpmlog callback function. diff --git a/rpmio/strcasecmp.c b/rpmio/strcasecmp.c index 4fcb37d60..669522b4a 100644 --- a/rpmio/strcasecmp.c +++ b/rpmio/strcasecmp.c @@ -6,16 +6,11 @@ #include "rpmio.h" #include "debug.h" -static inline unsigned char xtolower(unsigned char c) +int xstrcasecmp(const char * s1, const char * s2) { - return ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c); -} - -int xstrcasecmp(const char *s1, const char *s2) -{ - const unsigned char *p1 = (const unsigned char *) s1; - const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; + const char * p1 = s1; + const char * p2 = s2; + char c1, c2; if (p1 == p2) return 0; @@ -29,14 +24,14 @@ int xstrcasecmp(const char *s1, const char *s2) } while (c1 == c2); - return c1 - c2; + return (int)(c1 - c2); } int xstrncasecmp(const char *s1, const char *s2, size_t n) { - const unsigned char *p1 = (const unsigned char *) s1; - const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; + const char * p1 = s1; + const char * p2 = s2; + char c1, c2; if (p1 == p2 || n == 0) return 0; @@ -46,8 +41,8 @@ int xstrncasecmp(const char *s1, const char *s2, size_t n) c1 = xtolower (*p1++); c2 = xtolower (*p2++); if (c1 == '\0' || c1 != c2) - return c1 - c2; + break; } while (--n > 0); - return c1 - c2; + return (int)(c1 - c2); } diff --git a/rpmio/ugid.c b/rpmio/ugid.c index 3a529311e..67fbf76e4 100644 --- a/rpmio/ugid.c +++ b/rpmio/ugid.c @@ -15,24 +15,24 @@ int unameToUid(const char * thisUname, uid_t * uid) { - /*@only@*/ static char * lastUname = NULL; - static int lastUnameLen = 0; - static int lastUnameAlloced; +/*@only@*/ static char * lastUname = NULL; + static size_t lastUnameLen = 0; + static size_t lastUnameAlloced; static uid_t lastUid; struct passwd * pwent; - int thisUnameLen; + size_t thisUnameLen; if (!thisUname) { lastUnameLen = 0; return -1; - } else if (!strcmp(thisUname, "root")) { + } else if (strcmp(thisUname, "root") == 0) { *uid = 0; return 0; } thisUnameLen = strlen(thisUname); - if (!lastUname || thisUnameLen != lastUnameLen || - strcmp(thisUname, lastUname)) { + if (lastUname == NULL || thisUnameLen != lastUnameLen || + strcmp(thisUname, lastUname) != 0) { if (lastUnameAlloced < thisUnameLen + 1) { lastUnameAlloced = thisUnameLen + 10; lastUname = xrealloc(lastUname, lastUnameAlloced); /* XXX memory leak */ @@ -40,10 +40,10 @@ int unameToUid(const char * thisUname, uid_t * uid) strcpy(lastUname, thisUname); pwent = getpwnam(thisUname); - if (!pwent) { + if (pwent == NULL) { endpwent(); pwent = getpwnam(thisUname); - if (!pwent) return -1; + if (pwent == NULL) return -1; } lastUid = pwent->pw_uid; @@ -56,24 +56,25 @@ int unameToUid(const char * thisUname, uid_t * uid) int gnameToGid(const char * thisGname, gid_t * gid) { - /*@only@*/ static char * lastGname = NULL; - static int lastGnameLen = 0; - static int lastGnameAlloced; - static uid_t lastGid; - int thisGnameLen; +/*@only@*/ static char * lastGname = NULL; + static size_t lastGnameLen = 0; + static size_t lastGnameAlloced; + static gid_t lastGid; + size_t thisGnameLen; struct group * grent; - if (!thisGname) { + if (thisGname == NULL) { lastGnameLen = 0; return -1; - } else if (!strcmp(thisGname, "root")) { + } else if (strcmp(thisGname, "root") == 0) { *gid = 0; return 0; } thisGnameLen = strlen(thisGname); - if (!lastGname || thisGnameLen != lastGnameLen || - strcmp(thisGname, lastGname)) { + if (lastGname == NULL || thisGnameLen != lastGnameLen || + strcmp(thisGname, lastGname) != 0) + { if (lastGnameAlloced < thisGnameLen + 1) { lastGnameAlloced = thisGnameLen + 10; lastGname = xrealloc(lastGname, lastGnameAlloced); /* XXX memory leak */ @@ -81,10 +82,10 @@ int gnameToGid(const char * thisGname, gid_t * gid) strcpy(lastGname, thisGname); grent = getgrnam(thisGname); - if (!grent) { + if (grent == NULL) { endgrent(); grent = getgrnam(thisGname); - if (!grent) return -1; + if (grent == NULL) return -1; } lastGid = grent->gr_gid; } @@ -96,22 +97,22 @@ int gnameToGid(const char * thisGname, gid_t * gid) char * uidToUname(uid_t uid) { - static int lastUid = -1; - /*@only@*/ static char * lastUname = NULL; - static int lastUnameLen = 0; - struct passwd * pwent; - int len; + static uid_t lastUid = (uid_t) -1; +/*@only@*/ static char * lastUname = NULL; + static size_t lastUnameLen = 0; if (uid == (uid_t) -1) { - lastUid = -1; + lastUid = (uid_t) -1; return NULL; - } else if (!uid) { + } else if (uid == (uid_t) 0) { return "root"; } else if (uid == lastUid) { return lastUname; } else { - pwent = getpwuid(uid); - if (!pwent) return NULL; + struct passwd * pwent = getpwuid(uid); + size_t len; + + if (pwent == NULL) return NULL; lastUid = uid; len = strlen(pwent->pw_name); @@ -127,22 +128,22 @@ char * uidToUname(uid_t uid) char * gidToGname(gid_t gid) { - static int lastGid = -1; - /*@only@*/ static char * lastGname = NULL; - static int lastGnameLen = 0; - struct group * grent; - int len; + static gid_t lastGid = (gid_t) -1; +/*@only@*/ static char * lastGname = NULL; + static size_t lastGnameLen = 0; if (gid == (gid_t) -1) { - lastGid = -1; + lastGid = (gid_t) -1; return NULL; - } else if (!gid) { + } else if (gid == (gid_t) 0) { return "root"; } else if (gid == lastGid) { return lastGname; } else { - grent = getgrgid(gid); - if (!grent) return NULL; + struct group * grent = getgrgid(gid); + size_t len; + + if (grent == NULL) return NULL; lastGid = gid; len = strlen(grent->gr_name); @@ -2,7 +2,7 @@ #define _AUTOHELP -#if defined(IAM_RPM) +#if defined(IAM_RPM) || defined(__LCLINT__) #define IAM_RPMBT #define IAM_RPMDB #define IAM_RPMEIU @@ -387,7 +387,8 @@ static struct poptOption optionsTable[] = { long _stksize = 64 * 1024L; #endif -static void argerror(const char * desc) { +/*@exits@*/ static void argerror(const char * desc) +{ fprintf(stderr, _("rpm: %s\n"), desc); exit(EXIT_FAILURE); } @@ -697,7 +698,7 @@ int main(int argc, const char ** argv) #endif #ifdef IAM_RPMEIU - rpmRelocation * relocations = NULL; +/*@only@*/ rpmRelocation * relocations = NULL; int numRelocations = 0; #endif @@ -766,7 +767,7 @@ int main(int argc, const char ** argv) freeSpecVec = freeSpec; /* set up the correct locale */ - setlocale(LC_ALL, "" ); + (void) setlocale(LC_ALL, "" ); #ifdef __LCLINT__ #define LOCALEDIR "/usr/share/locale" @@ -1175,23 +1176,26 @@ int main(int argc, const char ** argv) if (signIt) { if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD || bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) { - const char ** argv; + const char ** av; struct stat sb; int errors = 0; - if ((argv = poptGetArgs(optCon)) == NULL) { + if ((av = poptGetArgs(optCon)) == NULL) { fprintf(stderr, _("no files to sign\n")); errors++; } else - while (*argv) { - if (stat(*argv, &sb)) { - fprintf(stderr, _("cannot access file %s\n"), *argv); + while (*av) { + if (stat(*av, &sb)) { + fprintf(stderr, _("cannot access file %s\n"), *av); errors++; } - argv++; + av++; } - if (errors) return errors; + if (errors) { + ec = errors; + goto exit; + } if (poptPeekArg(optCon)) { int sigTag; @@ -1202,13 +1206,15 @@ int main(int argc, const char ** argv) if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) && !rpmDetectPGPVersion(NULL)) { fprintf(stderr, _("pgp not found: ")); - exit(EXIT_FAILURE); + ec = EXIT_FAILURE; + goto exit; } /*@fallthrough@*/ case RPMSIGTAG_GPG: passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag); if (passPhrase == NULL) { fprintf(stderr, _("Pass phrase check failed\n")); - exit(EXIT_FAILURE); + ec = EXIT_FAILURE; + goto exit; } fprintf(stderr, _("Pass phrase is good.\n")); passPhrase = xstrdup(passPhrase); @@ -1216,7 +1222,8 @@ int main(int argc, const char ** argv) default: fprintf(stderr, _("Invalid %%_signature spec in macro file.\n")); - exit(EXIT_FAILURE); + ec = EXIT_FAILURE; + goto exit; /*@notreached@*/ break; } } @@ -1254,6 +1261,7 @@ int main(int argc, const char ** argv) case MODE_REBUILDDB: ec = rpmdbRebuild(rootdir); break; +#if !defined(__LCLINT__) case MODE_QUERY: case MODE_VERIFY: case MODE_QUERYTAGS: @@ -1267,6 +1275,7 @@ int main(int argc, const char ** argv) case MODE_RESIGN: if (!showVersion && !help && !noUsageMsg) printUsage(); break; +#endif #endif /* IAM_RPMDB */ #ifdef IAM_RPMBT @@ -1361,6 +1370,7 @@ int main(int argc, const char ** argv) } } break; +#if !defined(__LCLINT__) case MODE_QUERY: case MODE_VERIFY: case MODE_QUERYTAGS: @@ -1372,6 +1382,7 @@ int main(int argc, const char ** argv) case MODE_REBUILDDB: if (!showVersion && !help && !noUsageMsg) printUsage(); break; +#endif #endif /* IAM_RPMBT */ #ifdef IAM_RPMEIU @@ -1425,6 +1436,7 @@ int main(int argc, const char ** argv) transFlags, installInterfaceFlags, probFilter, relocations); break; +#if !defined(__LCLINT__) case MODE_QUERY: case MODE_VERIFY: case MODE_QUERYTAGS: @@ -1438,6 +1450,7 @@ int main(int argc, const char ** argv) case MODE_REBUILDDB: if (!showVersion && !help && !noUsageMsg) printUsage(); break; +#endif #endif /* IAM_RPMEIU */ #ifdef IAM_RPMQV @@ -1486,6 +1499,7 @@ int main(int argc, const char ** argv) rpmDisplayQueryTags(stdout); break; +#if !defined(__LCLINT__) case MODE_INSTALL: case MODE_UNINSTALL: case MODE_BUILD: @@ -1498,6 +1512,7 @@ int main(int argc, const char ** argv) case MODE_REBUILDDB: if (!showVersion && !help && !noUsageMsg) printUsage(); break; +#endif #endif /* IAM_RPMQV */ #ifdef IAM_RPMK @@ -1519,6 +1534,7 @@ int main(int argc, const char ** argv) /* XXX don't overflow single byte exit status */ if (ec > 255) ec = 255; break; +#if !defined(__LCLINT__) case MODE_QUERY: case MODE_VERIFY: case MODE_QUERYTAGS: @@ -1532,6 +1548,7 @@ int main(int argc, const char ** argv) case MODE_REBUILDDB: if (!showVersion && !help && !noUsageMsg) printUsage(); break; +#endif #endif /* IAM_RPMK */ case MODE_UNKNOWN: @@ -1540,6 +1557,7 @@ int main(int argc, const char ** argv) } +exit: poptFreeContext(optCon); rpmFreeMacros(NULL); rpmFreeMacros(&rpmCLIMacroContext); @@ -1556,12 +1574,12 @@ int main(int argc, const char ** argv) urlFreeCache(); #ifdef IAM_RPMQV - if (qva->qva_queryFormat) free((void *)qva->qva_queryFormat); + qva->qva_queryFormat = _free(qva->qva_queryFormat); #endif #ifdef IAM_RPMBT - if (ba->buildRootOverride) free((void *)ba->buildRootOverride); - if (ba->targets) free(ba->targets); + ba->buildRootOverride = _free(ba->buildRootOverride); + ba->targets = _free(ba->targets); #endif #if HAVE_MCHECK_H && HAVE_MTRACE @@ -194,7 +194,7 @@ char *alloca (); /*@only@*/ void * xmalloc (size_t size); /*@only@*/ void * xcalloc (size_t nmemb, size_t size); -/*@only@*/ void * xrealloc (/*@only@*/ void *ptr, size_t size); +/*@only@*/ void * xrealloc (/*@only@*/ /*@null@*/ void * ptr, size_t size); /*@only@*/ char * xstrdup (const char *str); /*@only@*/ void *vmefail(size_t size); |