1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 10:51:20 +03:00

util: fix segfault in prioq_remove() with empty Prioq object

This commit is contained in:
Yu Watanabe 2018-10-16 22:27:30 +09:00
parent d13b5f5a85
commit cd86deefa1
2 changed files with 6 additions and 0 deletions

View File

@ -211,6 +211,9 @@ _pure_ static struct prioq_item* find_item(Prioq *q, void *data, unsigned *idx)
assert(q);
if (q->n_items <= 0)
return NULL;
if (idx) {
if (*idx == PRIOQ_IDX_NULL ||
*idx > q->n_items)

View File

@ -86,6 +86,7 @@ static void test_struct(void) {
while ((t = set_steal_first(s))) {
assert_se(prioq_remove(q, t, &t->idx) == 1);
assert_se(prioq_remove(q, t, &t->idx) == 0);
assert_se(prioq_remove(q, t, NULL) == 0);
free(t);
}
@ -94,6 +95,8 @@ static void test_struct(void) {
assert_se(prioq_size(q) == (SET_SIZE * 3 / 4) - i);
assert_se(t = prioq_pop(q));
assert_se(prioq_remove(q, t, &t->idx) == 0);
assert_se(prioq_remove(q, t, NULL) == 0);
assert_se(previous <= t->value);
previous = t->value;