Code

store_expr: Fix iter_has_next if the first elements are filtered.
authorSebastian Harl <sh@tokkee.org>
Wed, 11 Mar 2015 19:01:19 +0000 (20:01 +0100)
committerSebastian Harl <sh@tokkee.org>
Wed, 11 Mar 2015 19:01:19 +0000 (20:01 +0100)
src/core/store_expr.c

index d9f6e0462b65c39e5e67c4b787139507c3969e43..8fc063d11e64ca621fd2206ad9a46b242d36cc48 100644 (file)
@@ -385,8 +385,21 @@ sdb_store_expr_iter_has_next(sdb_store_expr_iter_t *iter)
        if (! iter)
                return 0;
 
-       if (iter->tree)
+       if (iter->tree) {
+               /* this function may be called before get_next,
+                * so we'll have to apply filters here as well */
+               if (iter->filter) {
+                       sdb_store_obj_t *child;
+                       while ((child = STORE_OBJ(sdb_avltree_iter_peek_next(iter->tree)))) {
+                               if (sdb_store_matcher_matches(iter->filter, child, NULL))
+                                       break;
+                               (void)sdb_avltree_iter_get_next(iter->tree);
+                       }
+               }
+
                return sdb_avltree_iter_has_next(iter->tree);
+       }
+
        return iter->array_idx < iter->array.data.array.length;
 } /* sdb_store_expr_iter_has_next */