minor ZSET code cleanup: Remove dead guard in deleteRangeCore and enhance buffer contracts - #4715
rainsupreme wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe change adds ChangesScore Range Contracts
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~4 minutes Merge Risk: ⚪ Minimal · up to The cleanup preserves the existing score and deletion contracts, so the change is mergeable with normal checks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…fix buffer contracts
deleteRangeCore handles only ranges whose two boundary leaves differ:
fbtreeDeleteRangeByRank descends distinct children (li != ri) before
calling it, and the value and score paths route same-leaf ranges to
deleteRangeSameLeaf. The guard
if (bp->end_idx < 0 && bp->start_leaf == bp->end_leaf) return 0;
therefore never fires. It also sat directly under a comment explaining
that no local empty-range short-circuit belongs at that point, so the
code contradicted its own documentation. Replace it with an assert that
states the precondition every caller already satisfies, and restore the
split_depth declaration to the block that uses it.
Every score-prefix parameter of the static helpers in fbtree.c now
asserts that it must reference at least SCORE_SIZE readable bytes:
read-only prefixes become `const char name[static SCORE_SIZE]`, and the
two exact-size output buffers in scoreRangeBounds are upgraded from
`[SCORE_SIZE]` to `[static SCORE_SIZE]`, so the contract is visible at
every call site and compilers can diagnose undersized buffers.
The public fbtreeSeekToScore, fbtreeDeleteRangeByScore and
fbtreeCountRangeByScore keep `const char *`. Their prototypes in
fbtree.h must stay plain because a C99 array parameter with a `static`
size qualifier is invalid C++ and the header is included by
test_fbtree.cpp, and GCC 11+ rejects a definition whose array bound
differs from its prototype (-Werror=array-parameter).
No behavioral change.
Signed-off-by: Rain Valentine <rsg000@gmail.com>
b3c260b to
b0e0534
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #4715 +/- ##
============================================
+ Coverage 80.63% 80.82% +0.18%
============================================
Files 192 192
Lines 100803 100807 +4
============================================
+ Hits 81287 81475 +188
+ Misses 19516 19332 -184
🚀 New features to boost your workflow:
|
deleteRangeCore handles only ranges whose two boundary leaves differ: fbtreeDeleteRangeByRank descends distinct children (li != ri) before calling it, and the value and score paths route same-leaf ranges to deleteRangeSameLeaf. The guard
therefore never fires. It also sat directly under a comment explaining that no local empty-range short-circuit belongs at that point, so the code contradicted its own documentation. Replace it with an assert that states the precondition every caller already satisfies, and move the split_depth declaration to the block that uses it.
Every score-prefix parameter in fbtree.c now asserts that it must reference at least SCORE_SIZE readable bytes: read-only prefixes become
const char name[static SCORE_SIZE], and the two exact-size output buffers in scoreRangeBounds are upgraded from[SCORE_SIZE]to[static SCORE_SIZE], so the contract is visible at every call site and compilers can diagnose undersized buffers.fbtreeSeekToScore, fbtreeDeleteRangeByScore and fbtreeCountRangeByScore are public, but only their definitions are annotated. A C99 array parameter with a
staticsize qualifier is invalid C++, and fbtree.h is included by test_fbtree.cpp, so the header prototypes stayconst char *; C permits a definition to carry array qualifiers its declaration lacks.No behavioral change.