From e99a505b3b155f75b735472878725789e4311461 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 3 Dec 2024 23:34:09 -0500 Subject: [PATCH] bytevector: don't deadlock on operator<< operator<< was a friend class that locked the ByteVector, then invoked hexdump on the bytevector, which used ByteVector::operator[]...which locked the ByteVector, resulting in a deadlock. operator<< shouldn't be a friend class anyway. Make hexdump use the normal public access methods for ByteVector. Signed-off-by: Zygo Blaxell --- include/crucible/bytevector.h | 3 ++- lib/bytevector.cc | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/crucible/bytevector.h b/include/crucible/bytevector.h index 469f3d1..f68bcbd 100644 --- a/include/crucible/bytevector.h +++ b/include/crucible/bytevector.h @@ -55,7 +55,6 @@ namespace crucible { Pointer m_ptr; size_t m_size = 0; mutable mutex m_mutex; - friend ostream & operator<<(ostream &os, const ByteVector &bv); }; template @@ -74,6 +73,8 @@ namespace crucible { THROW_CHECK2(out_of_range, size(), sizeof(T), size() >= sizeof(T)); return reinterpret_cast(data()); } + + ostream& operator<<(ostream &os, const ByteVector &bv); } #endif // _CRUCIBLE_BYTEVECTOR_H_ diff --git a/lib/bytevector.cc b/lib/bytevector.cc index 5cf5069..9cbefd7 100644 --- a/lib/bytevector.cc +++ b/lib/bytevector.cc @@ -183,7 +183,6 @@ namespace crucible { ostream& operator<<(ostream &os, const ByteVector &bv) { - unique_lock lock(bv.m_mutex); hexdump(os, bv); return os; }