mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
spa: allow spa_dict.items to be NULL for zero items
For dicts with zero items, don't dereference dict->items, or give it to qsort or bsearch where passing in NULL is not allowed.
This commit is contained in:
parent
5a72e2769a
commit
870cd0136a
1 changed files with 5 additions and 3 deletions
|
|
@ -74,6 +74,7 @@ static inline int spa_dict_item_compare(const void *i1, const void *i2)
|
||||||
|
|
||||||
static inline void spa_dict_qsort(struct spa_dict *dict)
|
static inline void spa_dict_qsort(struct spa_dict *dict)
|
||||||
{
|
{
|
||||||
|
if (dict->n_items > 0)
|
||||||
qsort((void*)dict->items, dict->n_items, sizeof(struct spa_dict_item),
|
qsort((void*)dict->items, dict->n_items, sizeof(struct spa_dict_item),
|
||||||
spa_dict_item_compare);
|
spa_dict_item_compare);
|
||||||
SPA_FLAG_SET(dict->flags, SPA_DICT_FLAG_SORTED);
|
SPA_FLAG_SET(dict->flags, SPA_DICT_FLAG_SORTED);
|
||||||
|
|
@ -84,7 +85,8 @@ static inline const struct spa_dict_item *spa_dict_lookup_item(const struct spa_
|
||||||
{
|
{
|
||||||
const struct spa_dict_item *item;
|
const struct spa_dict_item *item;
|
||||||
|
|
||||||
if (SPA_FLAG_IS_SET(dict->flags, SPA_DICT_FLAG_SORTED)) {
|
if (SPA_FLAG_IS_SET(dict->flags, SPA_DICT_FLAG_SORTED) &&
|
||||||
|
dict->n_items > 0) {
|
||||||
struct spa_dict_item k = SPA_DICT_ITEM_INIT(key, NULL);
|
struct spa_dict_item k = SPA_DICT_ITEM_INIT(key, NULL);
|
||||||
item = (const struct spa_dict_item *)bsearch(&k,
|
item = (const struct spa_dict_item *)bsearch(&k,
|
||||||
(const void *) dict->items, dict->n_items,
|
(const void *) dict->items, dict->n_items,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue