diff options
author | 2022-01-25 13:41:52 -0800 | |
---|---|---|
committer | 2022-02-15 16:40:46 -0800 | |
commit | 17f6b97257ef79f6252a5a45ac3a1e647b3a5fd0 (patch) | |
tree | 5ff26555ebda65667f718e90cf6ac747576d1cad | |
parent | 953b7fd033714607ac14e106102835ecf03e3dc5 (diff) |
FTL: Prevent InitializerList overflow
Users so far use the deduction guide, but this should not compile:
ftl::StaticVector<int, 1> vector = ftl::init::list<int>(0)(1);
Bug: 185536303
Test: m ftl_test
Change-Id: Icc1263ebdb9326948f0fc2f9c9f01f21b0b8302d
-rw-r--r-- | include/ftl/static_vector.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/include/ftl/static_vector.h b/include/ftl/static_vector.h index b7f8c29dec..70f1721d4a 100644 --- a/include/ftl/static_vector.h +++ b/include/ftl/static_vector.h @@ -178,7 +178,9 @@ class StaticVector final : details::ArrayTraits<T>, template <typename U, std::size_t Size, std::size_t... Sizes, typename... Types> StaticVector(InitializerList<U, std::index_sequence<Size, Sizes...>, Types...>&& list) : StaticVector(std::index_sequence<0, 0, Size>{}, std::make_index_sequence<Size>{}, - std::index_sequence<Sizes...>{}, list.tuple) {} + std::index_sequence<Sizes...>{}, list.tuple) { + static_assert(sizeof...(Sizes) < N, "Too many elements"); + } ~StaticVector() { std::destroy(begin(), end()); } |