DBusHashIter *iter)
{
DBusRealHashIter *real;
- DBusHashEntry *entry;
- DBusHashEntry **bucket;
+ DBusHashEntry *entry = NULL;
+ DBusHashEntry **bucket = NULL;
_DBUS_STATIC_ASSERT (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
entry = (* table->find_function) (table, key, create_if_not_found, &bucket, NULL);
+ /* entry == NULL means not found, and either !create_if_not_found or OOM */
if (entry == NULL)
return FALSE;
+ _dbus_assert (bucket != NULL);
+ _dbus_assert (table->n_buckets >= 1);
+ _dbus_assert (bucket >= table->buckets);
+ _dbus_assert (bucket <= &table->buckets[table->n_buckets - 1]);
+
if (create_if_not_found)
{
if (table->free_key_function && entry->key != key)
real->next_bucket = (bucket - table->buckets) + 1;
real->n_entries_on_init = table->n_entries;
+ _dbus_assert (real->next_bucket >= 0);
+ _dbus_assert (real->next_bucket <= table->n_buckets);
_dbus_assert (&(table->buckets[real->next_bucket-1]) == real->bucket);
return TRUE;
}
add_allocated_entry (table, entry, idx, key, bucket);
+ _dbus_assert (bucket == NULL || *bucket != NULL);
return entry;
}
}
if (create_if_not_found)
- entry = add_entry (table, idx, key, bucket, preallocated);
+ {
+ entry = add_entry (table, idx, key, bucket, preallocated);
+
+ if (entry == NULL) /* OOM */
+ return NULL;
+
+ _dbus_assert (bucket == NULL || *bucket != NULL);
+ }
else if (preallocated)
- _dbus_hash_table_free_preallocated_entry (table, preallocated);
-
+ {
+ _dbus_hash_table_free_preallocated_entry (table, preallocated);
+ }
+
return entry;
}