From: Kefu Chai Date: Fri, 8 May 2026 00:55:03 +0000 (+0800) Subject: include/cpp-btree: fix false -Warray-bounds in child accessors X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F68811%2Fhead;p=ceph.git 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 --- 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*));