Code

store: Don't report an error in scan() if the store is still empty.
authorSebastian Harl <sh@tokkee.org>
Sat, 17 Jan 2015 00:26:07 +0000 (01:26 +0100)
committerSebastian Harl <sh@tokkee.org>
Sat, 17 Jan 2015 19:31:40 +0000 (11:31 -0800)
src/core/store.c
t/unit/core/store_test.c

index e6aeaf63e86f3c8a6d56e7682f065801396e481d..345b5ea86bf2555c42961b4778ccb800743066b7 100644 (file)
@@ -953,7 +953,7 @@ int
 sdb_store_scan(int type, sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
                sdb_store_lookup_cb cb, void *user_data)
 {
-       sdb_avltree_iter_t *host_iter;
+       sdb_avltree_iter_t *host_iter = NULL;
        int status = 0;
 
        if (! cb)
@@ -966,9 +966,11 @@ sdb_store_scan(int type, sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
 
        pthread_rwlock_rdlock(&host_lock);
 
-       host_iter = sdb_avltree_get_iter(hosts);
-       if (! host_iter)
-               status = -1;
+       if (hosts) {
+               host_iter = sdb_avltree_get_iter(hosts);
+               if (! host_iter)
+                       status = -1;
+       }
 
        /* has_next returns false if the iterator is NULL */
        while (sdb_avltree_iter_has_next(host_iter)) {
index 262f681de1ba8a7b69ca846ba20525b60cf67820..aab93aab1671a6995818b3da64fede48ec4d37b5 100644 (file)
@@ -693,8 +693,8 @@ START_TEST(test_scan)
        /* empty store */
        check = sdb_store_scan(SDB_HOST, /* m, filter = */ NULL, NULL,
                        scan_count, &i);
-       fail_unless(check == -1,
-                       "sdb_store_scan(HOST), empty store = %d; expected: -1", check);
+       fail_unless(check == 0,
+                       "sdb_store_scan(HOST), empty store = %d; expected: 0", check);
        fail_unless(i == 0,
                        "sdb_store_scan(HOST) called callback %d times; "
                        "expected: 0", (int)i);