diff options
author | jbj <devnull@localhost> | 2001-04-29 01:05:43 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2001-04-29 01:05:43 +0000 |
commit | 3b5820c4205e440d9aad5c5d626721ee30b12292 (patch) | |
tree | b1f0a694903aef1dd937539e1b06c8b0947fb67c /lib | |
parent | 6a0524ed57548de92daa4b6cf8ee9d2ab39d7a42 (diff) | |
download | librpm-tizen-3b5820c4205e440d9aad5c5d626721ee30b12292.tar.gz librpm-tizen-3b5820c4205e440d9aad5c5d626721ee30b12292.tar.bz2 librpm-tizen-3b5820c4205e440d9aad5c5d626721ee30b12292.zip |
- globalize _free(3) wrapper in rpmlib.h, consistent usage throughout.
- internalize locale insensitive ctype(3) in rpmio.h
- boring lclint annotations and fiddles.
CVS patchset: 4721
CVS date: 2001/04/29 01:05:43
Diffstat (limited to 'lib')
-rw-r--r-- | lib/.lclintrc | 8 | ||||
-rw-r--r-- | lib/cpio.c | 12 | ||||
-rw-r--r-- | lib/db1.c | 26 | ||||
-rw-r--r-- | lib/db2.c | 6 | ||||
-rw-r--r-- | lib/db3.c | 6 | ||||
-rw-r--r-- | lib/dbconfig.c | 24 | ||||
-rw-r--r-- | lib/depends.c | 54 | ||||
-rw-r--r-- | lib/depends.h | 8 | ||||
-rw-r--r-- | lib/fileutil.c | 3 | ||||
-rw-r--r-- | lib/formats.c | 73 | ||||
-rw-r--r-- | lib/fprint.c | 11 | ||||
-rw-r--r-- | lib/fs.c | 20 | ||||
-rw-r--r-- | lib/fsm.c | 46 | ||||
-rw-r--r-- | lib/getdate.y | 4 | ||||
-rw-r--r-- | lib/header.c | 13 | ||||
-rw-r--r-- | lib/header.h | 1 | ||||
-rw-r--r-- | lib/manifest.c | 14 | ||||
-rw-r--r-- | lib/misc.c | 28 | ||||
-rw-r--r-- | lib/misc.h | 3 | ||||
-rw-r--r-- | lib/poptBT.c | 2 | ||||
-rw-r--r-- | lib/poptQV.c | 2 | ||||
-rw-r--r-- | lib/problems.c | 6 | ||||
-rw-r--r-- | lib/psm.c | 27 | ||||
-rw-r--r-- | lib/query.c | 26 | ||||
-rw-r--r-- | lib/rpmchecksig.c | 9 | ||||
-rw-r--r-- | lib/rpmdb.c | 165 | ||||
-rw-r--r-- | lib/rpmdb.h | 2 | ||||
-rw-r--r-- | lib/rpminstall.c | 44 | ||||
-rw-r--r-- | lib/rpmlib.h | 26 | ||||
-rw-r--r-- | lib/rpmrc.c | 166 | ||||
-rw-r--r-- | lib/signature.c | 18 | ||||
-rw-r--r-- | lib/stringbuf.c | 9 | ||||
-rw-r--r-- | lib/tagName.c | 4 | ||||
-rw-r--r-- | lib/transaction.c | 19 | ||||
-rw-r--r-- | lib/verify.c | 20 |
35 files changed, 402 insertions, 503 deletions
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; |