[libc] [llvm] [libc] Add hardening for FixedVector data structure and fix exposed bug. (PR #122159)

Michael Jones via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 12:35:39 PST 2025


================
@@ -23,55 +24,71 @@ template <typename T, size_t CAPACITY> class FixedVector {
   size_t item_count = 0;
 
 public:
-  constexpr FixedVector() = default;
+  LIBC_INLINE constexpr FixedVector() = default;
 
   using iterator = typename cpp::array<T, CAPACITY>::iterator;
-  constexpr FixedVector(iterator begin, iterator end) : store{}, item_count{} {
+  LIBC_INLINE constexpr FixedVector(iterator begin, iterator end) : store{}, item_count{} {
     for (; begin != end; ++begin)
-      push_back(*begin);
+      LIBC_ASSERT(push_back(*begin));
   }
 
   using const_iterator = typename cpp::array<T, CAPACITY>::const_iterator;
-  constexpr FixedVector(const_iterator begin, const_iterator end)
+  LIBC_INLINE constexpr FixedVector(const_iterator begin, const_iterator end)
       : store{}, item_count{} {
     for (; begin != end; ++begin)
-      push_back(*begin);
+      LIBC_ASSERT(push_back(*begin));
----------------
michaelrj-google wrote:

nevermind, you caught this already.

https://github.com/llvm/llvm-project/pull/122159


More information about the llvm-commits mailing list