Skip to content

Commit 3da2230

Browse files
committed
fix: use resize instead of reserve in batch_invert to fix UB
batch_invert used reserve() for its temporaries and skipped vectors, then accessed elements via operator[]. reserve() only allocates capacity without changing size, making operator[] access undefined behavior. This crashes in debug builds with _GLIBCXX_ASSERTIONS enabled. Fixed by using direct size-construction: vector(n) instead of reserve(n).
1 parent cf1a239 commit 3da2230

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,8 @@ void field<T>::batch_invert(C& coeffs) noexcept
419419
{
420420
const size_t n = coeffs.size();
421421

422-
std::vector<field> temporaries;
423-
std::vector<bool> skipped;
424-
temporaries.reserve(n);
425-
skipped.reserve(n);
422+
std::vector<field> temporaries(n);
423+
std::vector<bool> skipped(n);
426424

427425
field accumulator = one();
428426
for (size_t i = 0; i < n; ++i) {

0 commit comments

Comments
 (0)