]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
include/cpp-btree: fix false -Warray-bounds in child accessors 68811/head
authorKefu Chai <k.chai@proxmox.com>
Fri, 8 May 2026 00:55:03 +0000 (08:55 +0800)
committerKefu Chai <k.chai@proxmox.com>
Fri, 8 May 2026 06:39:49 +0000 (14:39 +0800)
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 <k.chai@proxmox.com>
src/include/cpp-btree/btree.h

index a689b2d43a2e591efe9fd9575cd5bc73763a8985..5fafd467a3a81602b3ea1c58fd5d594d41d4a3e1 100644 (file)
@@ -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*));