]> git.sur5r.net Git - openldap/commitdiff
ITS#7913 mdb_cursor_get(*_DUP) cleanup
authorHoward Chu <hyc@symas.com>
Thu, 31 Jul 2014 16:59:52 +0000 (09:59 -0700)
committerHoward Chu <hyc@symas.com>
Thu, 31 Jul 2014 16:59:52 +0000 (09:59 -0700)
FIRST_DUP/LAST_DUP should succeed even on non-duplicate values
PREV_DUP should reset cursor's EOF flag.

libraries/liblmdb/mdb.c

index e1d774887b65fe7796661a1bc6a762dc0fff5fbe..96f5772903ea9e338883b69185327ed49f77308b 100644 (file)
@@ -5355,8 +5355,10 @@ mdb_cursor_prev(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)
                        if (op == MDB_PREV || op == MDB_PREV_DUP) {
                                rc = mdb_cursor_prev(&mc->mc_xcursor->mx_cursor, data, NULL, MDB_PREV);
                                if (op != MDB_PREV || rc != MDB_NOTFOUND) {
-                                       if (rc == MDB_SUCCESS)
+                                       if (rc == MDB_SUCCESS) {
                                                MDB_GET_KEY(leaf, key);
+                                               mc->mc_flags &= ~C_EOF;
+                                       }
                                        return rc;
                                }
                        } else {
@@ -5833,6 +5835,15 @@ fetchm:
                        rc = MDB_INCOMPATIBLE;
                        break;
                }
+               {
+                       MDB_node *leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
+                       if (!F_ISSET(leaf->mn_flags, F_DUPDATA)) {
+                               MDB_GET_KEY(leaf, key);
+                               if (data)
+                                       rc = mdb_node_read(mc->mc_txn, leaf, data);
+                               break;
+                       }
+               }
                if (!(mc->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED)) {
                        rc = EINVAL;
                        break;