Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17f6b972 authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

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
parent 953b7fd0
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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()); }