chiark / gitweb /
bus: properly handle if new objects are installed in the node tree while we are dispa...
[elogind.git] / src / shared / prioq.c
index 64c44aef8266bfef9bab49ea12cb397f6cb777f7..537befc623a1554bd4b57bb115ca223bacddbbb4 100644 (file)
@@ -159,7 +159,7 @@ int prioq_put(Prioq *q, void *data, unsigned *idx) {
                 unsigned n;
                 struct prioq_item *j;
 
-                n = MAX((q->n_items+1) * 2, 16);
+                n = MAX((q->n_items+1) * 2, 16u);
                 j = realloc(q->items, sizeof(struct prioq_item) * n);
                 if (!j)
                         return -ENOMEM;
@@ -211,13 +211,14 @@ static void remove_item(Prioq *q, struct prioq_item *i) {
         }
 }
 
-static struct prioq_item* find_item(Prioq *q, void *data, unsigned *idx) {
+_pure_ static struct prioq_item* find_item(Prioq *q, void *data, unsigned *idx) {
         struct prioq_item *i;
 
         assert(q);
 
         if (idx) {
-                if (*idx > q->n_items)
+                if (*idx == PRIOQ_IDX_NULL ||
+                    *idx > q->n_items)
                         return NULL;
 
                 i = q->items + *idx;