From cb1cc6483136b1404de29731279f81878fdf1199 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 1 Apr 2013 19:49:40 -0700 Subject: [PATCH] More fixes for MDB_LAST Make sure C_INITIALIZED gets set on successful call --- libraries/liblmdb/mdb.c | 2 +- libraries/liblmdb/mtest.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 5980384..28f3452 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -4669,9 +4669,9 @@ mdb_cursor_last(MDB_cursor *mc, MDB_val *key, MDB_val *data) } assert(IS_LEAF(mc->mc_pg[mc->mc_top])); - mc->mc_flags |= C_INITIALIZED|C_EOF; mc->mc_ki[mc->mc_top] = NUMKEYS(mc->mc_pg[mc->mc_top]) - 1; } + mc->mc_flags |= C_INITIALIZED|C_EOF; leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]); if (IS_LEAF2(mc->mc_pg[mc->mc_top])) { diff --git a/libraries/liblmdb/mtest.c b/libraries/liblmdb/mtest.c index 42b8658..55cdd43 100644 --- a/libraries/liblmdb/mtest.c +++ b/libraries/liblmdb/mtest.c @@ -101,6 +101,11 @@ int main(int argc,char * argv[]) (int) key.mv_size, (char *) key.mv_data, (int) data.mv_size, (char *) data.mv_data); } + printf("Cursor last\n"); + rc = mdb_cursor_get(cursor, &key, &data, MDB_LAST); + printf("key: %.*s, data: %.*s\n", + (int) key.mv_size, (char *) key.mv_data, + (int) data.mv_size, (char *) data.mv_data); printf("Cursor prev\n"); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) { printf("key: %.*s, data: %.*s\n",