Avoid calling qsort() and bsearch() with NULL base

These are all rather old offenses with no known ill effects on any
systems, but at least on glibc these are marked as non-null and
not doing so is certainly on the safe side.
This commit is contained in:
Panu Matilainen 2019-03-07 15:20:04 +02:00
parent e7b80af136
commit 6f21184c9c
3 changed files with 10 additions and 4 deletions

View File

@ -1051,8 +1051,10 @@ static void genCpioListAndHeader(FileList fl, Package pkg, int isSrc)
}
/* Sort the big list */
qsort(fl->files.recs, fl->files.used,
sizeof(*(fl->files.recs)), compareFileListRecs);
if (fl->files.recs) {
qsort(fl->files.recs, fl->files.used,
sizeof(*(fl->files.recs)), compareFileListRecs);
}
pkg->dpaths = xmalloc((fl->files.used + 1) * sizeof(*pkg->dpaths));

View File

@ -92,7 +92,8 @@ int argvSort(ARGV_t argv, int (*compar)(const void *, const void *))
{
if (compar == NULL)
compar = argvCmp;
qsort(argv, argvCount(argv), sizeof(*argv), compar);
if (argv)
qsort(argv, argvCount(argv), sizeof(*argv), compar);
return 0;
}

View File

@ -72,7 +72,10 @@ rpmKeyring rpmKeyringFree(rpmKeyring keyring)
static rpmPubkey rpmKeyringFindKeyid(rpmKeyring keyring, rpmPubkey key)
{
rpmPubkey *found = NULL;
found = bsearch(&key, keyring->keys, keyring->numkeys, sizeof(*keyring->keys), keyidcmp);
if (key && keyring->keys) {
found = bsearch(&key, keyring->keys, keyring->numkeys,
sizeof(*keyring->keys), keyidcmp);
}
return found ? *found : NULL;
}