Code

store: Advance expression iterators even if array access fails.
authorSebastian Harl <sh@tokkee.org>
Sun, 8 Mar 2015 21:47:51 +0000 (22:47 +0100)
committerSebastian Harl <sh@tokkee.org>
Sun, 8 Mar 2015 21:47:51 +0000 (22:47 +0100)
Else, we'd have an endless loop as the caller doesn't know about that.

src/core/store_expr.c

index 42ebcaa26954a42ab279fbd20728c98f591e8e35..11370bb438455f6fcf3b08a34a4bcfa5607a98af 100644 (file)
@@ -395,6 +395,7 @@ sdb_store_expr_iter_get_next(sdb_store_expr_iter_t *iter)
 {
        sdb_data_t null = SDB_DATA_INIT;
        sdb_data_t ret = SDB_DATA_INIT;
+       sdb_data_t tmp = SDB_DATA_INIT;
 
        if (! iter)
                return null;
@@ -426,10 +427,13 @@ sdb_store_expr_iter_get_next(sdb_store_expr_iter_t *iter)
 
        if (iter->array_idx >= iter->array.data.array.length)
                return null;
-       if (sdb_data_array_get(&iter->array, iter->array_idx, &ret))
-               return null;
 
        ++iter->array_idx;
+       if (sdb_data_array_get(&iter->array, iter->array_idx - 1, &ret))
+               return null;
+       if (sdb_data_copy(&tmp, &ret))
+               return null;
+       ret = tmp;
        return ret;
 } /* sdb_store_expr_iter_get_next */