From 76399bd6436414e4ca73e53ca744b6a1595f15be Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Thu, 25 Nov 2021 19:16:05 +0300 Subject: [PATCH] mdbx: fix returning `MDBX_NOTFOUND` for non-exact seek case of `MDBX_GET_BOTH`. Fixed https://github.com/erthink/libmdbx/issues/243 --- src/core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core.c b/src/core.c index 1f85064c..c3490505 100644 --- a/src/core.c +++ b/src/core.c @@ -14139,6 +14139,10 @@ got_node: MDBX_SET_RANGE); if (unlikely(ret.err != MDBX_SUCCESS)) return ret; + if (op == MDBX_GET_BOTH && !ret.exact) { + ret.err = MDBX_NOTFOUND; + return ret; + } } } else if (likely(data)) { if (op == MDBX_GET_BOTH || op == MDBX_GET_BOTH_RANGE) { @@ -14170,12 +14174,12 @@ got_node: break; } } - MDBX_val olddata; - ret.err = mdbx_node_read(mc, node, &olddata, + MDBX_val actual_data; + ret.err = mdbx_node_read(mc, node, &actual_data, pp_txnid4chk(mc->mc_pg[mc->mc_top], mc->mc_txn)); if (unlikely(ret.err != MDBX_SUCCESS)) return ret; - const int cmp = mc->mc_dbx->md_dcmp(&aligned_data, &olddata); + const int cmp = mc->mc_dbx->md_dcmp(&aligned_data, &actual_data); if (cmp) { mdbx_cassert(mc, mc->mc_ki[mc->mc_top] < page_numkeys(mc->mc_pg[mc->mc_top]) || @@ -14185,7 +14189,7 @@ got_node: return ret; } } - *data = olddata; + *data = actual_data; } else { ret.err = mdbx_node_read(mc, node, data, pp_txnid4chk(mc->mc_pg[mc->mc_top], mc->mc_txn));