From 19e4df476dd8969209585903effa935de09771dc Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 6 Oct 2011 16:11:25 -0700 Subject: [PATCH] Fix subcursor initialization --- libraries/libmdb/mdb.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index fb547ac222..dc333e91ab 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -3349,7 +3349,7 @@ mdb_cursor_next(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op) return rc; } } else { - mc->mc_xcursor->mx_cursor.mc_flags = 0; + mc->mc_xcursor->mx_cursor.mc_flags &= ~C_INITIALIZED; if (op == MDB_NEXT_DUP) return MDB_NOTFOUND; } @@ -3419,7 +3419,7 @@ mdb_cursor_prev(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op) if (op != MDB_PREV || rc == MDB_SUCCESS) return rc; } else { - mc->mc_xcursor->mx_cursor.mc_flags = 0; + mc->mc_xcursor->mx_cursor.mc_flags &= ~C_INITIALIZED; if (op == MDB_PREV_DUP) return MDB_NOTFOUND; } @@ -3623,7 +3623,7 @@ set1: } else { if (mc->mc_xcursor) - mc->mc_xcursor->mx_cursor.mc_flags = 0; + mc->mc_xcursor->mx_cursor.mc_flags &= ~C_INITIALIZED; if ((rc = mdb_node_read(mc->mc_txn, leaf, data)) != MDB_SUCCESS) return rc; } @@ -3671,7 +3671,7 @@ mdb_cursor_first(MDB_cursor *mc, MDB_val *key, MDB_val *data) return rc; } else { if (mc->mc_xcursor) - mc->mc_xcursor->mx_cursor.mc_flags = 0; + mc->mc_xcursor->mx_cursor.mc_flags &= ~C_INITIALIZED; if ((rc = mdb_node_read(mc->mc_txn, leaf, data)) != MDB_SUCCESS) return rc; } @@ -3718,7 +3718,7 @@ mdb_cursor_last(MDB_cursor *mc, MDB_val *key, MDB_val *data) return rc; } else { if (mc->mc_xcursor) - mc->mc_xcursor->mx_cursor.mc_flags = 0; + mc->mc_xcursor->mx_cursor.mc_flags &= ~C_INITIALIZED; if ((rc = mdb_node_read(mc->mc_txn, leaf, data)) != MDB_SUCCESS) return rc; } @@ -3918,7 +3918,7 @@ mdb_cursor_put(MDB_cursor *mc, MDB_val *key, MDB_val *data, int exact = 0; MDB_val d2; rc = mdb_cursor_set(mc, key, &d2, MDB_SET, &exact); - if (flags == MDB_NOOVERWRITE && rc == 0) { + if ((flags & MDB_NOOVERWRITE) && rc == 0) { DPRINTF("duplicate key [%s]", DKEY(key)); *data = d2; return MDB_KEYEXIST; @@ -4571,6 +4571,8 @@ mdb_xcursor_init0(MDB_cursor *mc) mx->mx_cursor.mc_dbx = &mx->mx_dbx; mx->mx_cursor.mc_dbi = mc->mc_dbi+1; mx->mx_cursor.mc_dbflag = &mx->mx_dbflag; + mx->mx_cursor.mc_snum = 0; + mx->mx_cursor.mc_flags = C_SUB; mx->mx_dbx.md_cmp = mc->mc_dbx->md_dcmp; mx->mx_dbx.md_dcmp = NULL; mx->mx_dbx.md_rel = mc->mc_dbx->md_rel; @@ -5548,6 +5550,8 @@ done: m3 = &m2->mc_xcursor->mx_cursor; else m3 = m2; + if (!(m3->mc_flags & C_INITIALIZED)) + continue; if (new_root) { /* root split */ for (i=m3->mc_top; i>0; i--) { -- 2.39.5