/* Sort the array in order for the tests to be predictable. This way we can
* still traverse the directory instead of guessing names (in case there is
* 'index1' and 'index3' but no 'index2'). */
- qsort(caps->host.cache.banks, caps->host.cache.nbanks,
- sizeof(*caps->host.cache.banks), virCapsHostCacheBankSorter);
+ if (caps->host.cache.banks) {
+ qsort(caps->host.cache.banks, caps->host.cache.nbanks,
+ sizeof(*caps->host.cache.banks), virCapsHostCacheBankSorter);
+ }
if (virCapabilitiesInitResctrlMemory(caps) < 0)
goto cleanup;
* paths in the same order and thus no deadlock can occur.
* Lastly, it makes searching for duplicate paths below
* simpler. */
- qsort(paths, npaths, sizeof(*paths), cmpstringp);
+ if (paths)
+ qsort(paths, npaths, sizeof(*paths), cmpstringp);
for (i = 0; i < npaths; i++) {
const char *p = paths[i];
sortAddr(leaseAddress *tmpAddress,
size_t ntmpAddress)
{
- qsort(tmpAddress, ntmpAddress, sizeof(*tmpAddress), leaseAddressSorter);
+ if (tmpAddress)
+ qsort(tmpAddress, ntmpAddress, sizeof(*tmpAddress), leaseAddressSorter);
}