From 4dfa47e2e128bec7106efb2ffb62c85430a3377a Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 8 May 2026 08:55:03 +0800 Subject: [PATCH] include/cpp-btree: fix false -Warray-bounds in child accessors After inlining, GCC's VRP sees mutable_child() reaching a leaf-root node whose static type only bounds values[], not children[], and fires even though the if(!leaf()) guard prevents it at runtime: btree.h:522: warning: array subscript [33, 287] is outside array bounds of 'struct M[32]' [-Warray-bounds] Decay children[] to a raw pointer in child()/mutable_child() so GCC has no array bounds to check. Signed-off-by: Kefu Chai --- src/include/cpp-btree/btree.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/include/cpp-btree/btree.h b/src/include/cpp-btree/btree.h index a689b2d43a2e..5fafd467a3a8 100644 --- a/src/include/cpp-btree/btree.h +++ b/src/include/cpp-btree/btree.h @@ -511,8 +511,14 @@ public: const_reference value(int i) const { return params_type::element(slot(i)); } // Getters/setter for the child at position i in the node. - btree_node* child(int i) const { return *(GetField<&internal_fields::children>() + i); } - btree_node*& mutable_child(int i) { return *(GetField<&internal_fields::children>() + i); } + btree_node* child(int i) const { + auto* p = GetField<&internal_fields::children>(); + return p[i]; + } + btree_node*& mutable_child(int i) { + auto* p = GetField<&internal_fields::children>(); + return p[i]; + } void clear_child(int i) { #ifndef NDEBUG memset(&mutable_child(i), 0, sizeof(btree_node*)); -- 2.47.3