From: Sebastian Harl Date: Sat, 17 Jan 2015 00:26:07 +0000 (+0100) Subject: store: Don't report an error in scan() if the store is still empty. X-Git-Tag: sysdb-0.7.0~51 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2faa3926a2836c0fe560bc73c7a8df4b9993b3be;p=sysdb.git store: Don't report an error in scan() if the store is still empty. --- diff --git a/src/core/store.c b/src/core/store.c index e6aeaf6..345b5ea 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -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)) { diff --git a/t/unit/core/store_test.c b/t/unit/core/store_test.c index 262f681..aab93aa 100644 --- a/t/unit/core/store_test.c +++ b/t/unit/core/store_test.c @@ -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);