From 4903369109de3bb1bcd2a7fd0623a3d1faf0e7a1 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Tue, 21 Jan 2025 18:57:31 -0800 Subject: [PATCH] fix warning violations of array-bounds in small_vector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Fixes or works around the following warning violations: ``` In file included from folly/small_vector.h:17, from folly/container/test/small_vector_test.cpp:17: In lambda function, inlined from ‘void folly::detail::populateMemForward(T*, std::size_t, const Function&) [with T = int; Function = folly::small_vector::constructImpl(size_type, const value_type&, std::true_type)::]’ at folly/container/small_vector.h:229:9, inlined from ‘void folly::small_vector::doConstruct(size_type, InitFunc&&) [with InitFunc = folly::small_vector::constructImpl(size_type, const value_type&, std::true_type)::; Value = int; long unsigned int RequestedMaxInline = 1; Policy = void]’ at folly/container/small_vector.h:1164:33, inlined from ‘void folly::small_vector::constructImpl(size_type, const value_type&, std::true_type) [with Value = int; long unsigned int RequestedMaxInline = 1; Policy = void]’ at folly/container/small_vector.h:1172:16, inlined from ‘folly::small_vector::small_vector(Arg, Arg) [with Arg = int; Value = int; long unsigned int RequestedMaxInline = 1; Policy = void]’ at folly/container/small_vector.h:575:18, inlined from ‘virtual void smallVector_InsertTrivial_Test::TestBody()’ at folly/container/test/small_vector_test.cpp:406:40: folly/container/small_vector.h:1172:35: warning: array subscript 4 is outside array bounds of ‘folly::small_vector [1]’ [-Warray-bounds=] 1172 | doConstruct(n, [&](void* p) { new (p) value_type(val); }); | ^~~~~~~~~~~~~~~~~~~~~~~ ``` Reviewed By: ilvokhin Differential Revision: D68424534 fbshipit-source-id: 9ba06273d38b6008fa4e759fdcf4e40859567c4c --- third-party/folly/src/folly/container/small_vector.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/third-party/folly/src/folly/container/small_vector.h b/third-party/folly/src/folly/container/small_vector.h index a404301a4e3905..7f34b5a2d2e1df 100644 --- a/third-party/folly/src/folly/container/small_vector.h +++ b/third-party/folly/src/folly/container/small_vector.h @@ -560,11 +560,17 @@ class small_vector } explicit small_vector(size_type n) { + FOLLY_PUSH_WARNING + FOLLY_GCC_DISABLE_WARNING("-Warray-bounds") doConstruct(n, [&](void* p) { new (p) value_type(); }); + FOLLY_POP_WARNING } small_vector(size_type n, value_type const& t) { + FOLLY_PUSH_WARNING + FOLLY_GCC_DISABLE_WARNING("-Warray-bounds") doConstruct(n, [&](void* p) { new (p) value_type(t); }); + FOLLY_POP_WARNING } template @@ -773,7 +779,10 @@ class small_vector void resize(size_type sz, value_type const& v) { if (sz < size()) { + FOLLY_PUSH_WARNING + FOLLY_GCC_DISABLE_WARNING("-Warray-bounds") erase(begin() + sz, end()); + FOLLY_POP_WARNING return; } auto extra = sz - size(); @@ -1169,7 +1178,10 @@ class small_vector // The true_type means we should forward to the size_t,value_type // overload. void constructImpl(size_type n, value_type const& val, std::true_type) { + FOLLY_PUSH_WARNING + FOLLY_GCC_DISABLE_WARNING("-Warray-bounds") doConstruct(n, [&](void* p) { new (p) value_type(val); }); + FOLLY_POP_WARNING } /*