Skip to content

Commit 4bb627d

Browse files
committed
fix: avoid dereferencing past-the-end vector iterators in serialize.hpp
Two write() overloads in serialize.hpp used `&*buf.end()` to get a pointer to the newly-appended region after resize(). Under _GLIBCXX_DEBUG (enabled in asan-fast and debug presets since #22218), dereferencing end() triggers a debug assertion abort. Replace with `buf.data() + buf.size()` which achieves the same pointer arithmetic without dereferencing any iterator.
1 parent ed6069d commit 4bb627d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

barretenberg/cpp/src/barretenberg/common/serialize.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void read(std::vector<uint8_t> const& buf, std::integral auto& value)
163163
void write(std::vector<uint8_t>& buf, const std::integral auto& value)
164164
{
165165
buf.resize(buf.size() + sizeof(value));
166-
uint8_t* ptr = &*buf.end() - sizeof(value);
166+
uint8_t* ptr = buf.data() + buf.size() - sizeof(value);
167167
write(ptr, value);
168168
}
169169

@@ -248,7 +248,7 @@ inline void write(std::ostream& os, std::vector<uint8_t> const& value)
248248
template <size_t N> inline void write(std::vector<uint8_t>& buf, std::array<uint8_t, N> const& value)
249249
{
250250
buf.resize(buf.size() + N);
251-
auto* ptr = &*buf.end() - N;
251+
auto* ptr = buf.data() + buf.size() - N;
252252
write(ptr, value);
253253
}
254254

0 commit comments

Comments
 (0)