]> git.apps.os.sepia.ceph.com Git - ceph.git/commit
squid: crush: use std::vector instead of variable length arrays 61956/head
authorKefu Chai <tchaikov@gmail.com>
Sun, 24 Mar 2024 10:41:40 +0000 (18:41 +0800)
committerPrashant D <pdhange@redhat.com>
Sat, 22 Feb 2025 01:57:56 +0000 (20:57 -0500)
commit4f60e8d9ff039fbc9fda3cea88f81f1796e90b1f
tree574ac81edf33fa1ac9c1164fbfce0f568daa28e0
parentd5f77b91f4241913b4495fe116b286cf6dad30e2
squid: crush: use std::vector instead of variable length arrays

despite that variable length arrays (VLA for short) has been around
for a long time, it is an extension supported by GCC and Clang, and is
not a part of C++ standard, its implementation allocates the dynamically
sized array on stack, hence is a source of potential stack overflow.

when compiling with Clang, it complains. so in this change, we switch
to std::vector<>, which is defined by the C++ standard, and it allocates
the storage on heap, so it is immune to the possible stack overflow problem.

```
/home/kefu/dev/ceph/src/crush/CrushWrapper.h:1613:16: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
 1613 |     int rawout[maxout];
      |                ^~~~~~
/home/kefu/dev/ceph/src/crush/CrushWrapper.h:1613:16: note: function parameter 'maxout' with unknown value cannot be used in a constant expression
/home/kefu/dev/ceph/src/crush/CrushWrapper.h:1610:60: note: declared here
 1610 |   void do_rule(int rule, int x, std::vector<int>& out, int maxout,
      |                                                            ^
/home/kefu/dev/ceph/src/crush/CrushWrapper.h:1614:15: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
 1614 |     char work[crush_work_size(crush, maxout)];
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/kefu/dev/ceph/src/crush/CrushWrapper.h:1614:31: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
 1614 |     char work[crush_work_size(crush, maxout)];
      |                               ^
2 warnings generated.
```

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
(cherry picked from commit 13169741c318443de0e8e889ff4616fe075a17ef)
src/crush/CrushWrapper.h