Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit fd6e426

Browse files
authored
Merge pull request #1103 from igchor/radix_tree_signed_fix
radix_tree: fix key comparison in internal_bound
2 parents 22fa029 + c25cf1d commit fd6e426

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

include/libpmemobj++/experimental/radix_tree.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,8 @@ radix_tree<Key, Value, BytesView>::internal_bound(const K &k) const
22372237
* The left siblings of *slot are all less than the
22382238
* looked-for key (this is the case fo AXXB from the
22392239
* example above). */
2240-
if (key[diff] < leaf_key[diff]) {
2240+
if (static_cast<unsigned char>(key[diff]) <
2241+
static_cast<unsigned char>(leaf_key[diff])) {
22412242
auto target_leaf =
22422243
find_leaf<node::direction::Forward>(n);
22432244

@@ -2248,7 +2249,9 @@ radix_tree<Key, Value, BytesView>::internal_bound(const K &k) const
22482249
} else if (slot == &root) {
22492250
result = const_iterator(nullptr, this);
22502251
} else {
2251-
assert(key[diff] > leaf_key[diff]);
2252+
assert(static_cast<unsigned char>(key[diff]) >
2253+
static_cast<unsigned char>(
2254+
leaf_key[diff]));
22522255

22532256
/* Since next byte in key is greater
22542257
* than in leaf_key, the target node

tests/radix_tree/radix_basic.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ test_find(nvobj::pool<root> &pop)
301301
}
302302

303303
{
304-
auto r = pop.root();
305-
306304
nvobj::transaction::run(pop, [&] {
307305
r->radix_str =
308306
nvobj::make_persistent<container_string>();
@@ -399,6 +397,44 @@ test_find(nvobj::pool<root> &pop)
399397

400398
UT_ASSERTeq(num_allocs(pop), 0);
401399
}
400+
401+
{
402+
nvobj::transaction::run(pop, [&] {
403+
r->radix_str =
404+
nvobj::make_persistent<container_string>();
405+
});
406+
407+
r->radix_str->try_emplace(std::string(1, char(1)), "");
408+
409+
auto ub = r->radix_str->upper_bound(std::string(1, char(-1)));
410+
UT_ASSERT(ub == r->radix_str->end());
411+
412+
nvobj::transaction::run(pop, [&] {
413+
nvobj::delete_persistent<container_string>(
414+
r->radix_str);
415+
});
416+
417+
UT_ASSERTeq(num_allocs(pop), 0);
418+
}
419+
420+
{
421+
nvobj::transaction::run(pop, [&] {
422+
r->radix_str =
423+
nvobj::make_persistent<container_string>();
424+
});
425+
426+
r->radix_str->try_emplace(std::string(1, char(-1)), "");
427+
428+
auto ub = r->radix_str->upper_bound(std::string(1, char(1)));
429+
UT_ASSERT(ub == r->radix_str->begin());
430+
431+
nvobj::transaction::run(pop, [&] {
432+
nvobj::delete_persistent<container_string>(
433+
r->radix_str);
434+
});
435+
436+
UT_ASSERTeq(num_allocs(pop), 0);
437+
}
402438
}
403439

404440
const auto compressed_path_len = 4;

0 commit comments

Comments
 (0)