static enum wl_iterator_result
for_each_helper(struct wl_array *entries, wl_iterator_func_t func, void *data)
{
- union map_entry *start, *end, *p;
enum wl_iterator_result ret = WL_ITERATOR_CONTINUE;
+ union map_entry entry, *start;
+ size_t count;
- start = entries->data;
- end = (union map_entry *) ((char *) entries->data + entries->size);
+ start = (union map_entry *) entries->data;
+ count = entries->size / sizeof(union map_entry);
- for (p = start; p < end; p++)
- if (p->data && !map_entry_is_free(*p)) {
- ret = func(map_entry_get_data(*p), data, map_entry_get_flags(*p));
+ for (size_t idx = 0; idx < count; idx++) {
+ entry = start[idx];
+ if (entry.data && !map_entry_is_free(entry)) {
+ ret = func(map_entry_get_data(entry), data, map_entry_get_flags(entry));
if (ret != WL_ITERATOR_CONTINUE)
break;
}
+ }
return ret;
}
wl_map_release(&map);
}
+
+static enum wl_iterator_result never_run(void *element, void *data, uint32_t flags)
+{
+ assert(0);
+}
+
+TEST(map_iter_empty)
+{
+ struct wl_map map;
+
+ wl_map_init(&map, WL_MAP_SERVER_SIDE);
+
+ wl_map_for_each(&map, never_run, NULL);
+
+ wl_map_release(&map);
+}