Skip to content

Commit 2d53565

Browse files
author
Zygo Blaxell
committed
progress: work around GCC-16 -Warray-bounds bug
`make_shared<ProgressTrackerState>()` keeps triggering GCC bugs. The latest failure on GCC-16.0 and GCC-16.1: /usr/include/c++/16.1.1/bits/stl_tree.h:1383:19: error: array subscript 1 is outside array bounds of ‘std::_Sp_counted_ptr_inplace<crucible::ProgressTracker<long unsigned int>::ProgressHolderState, std::allocator<void>, __gnu_cxx::_S_atomic> [1]’ [-Werror=array-bounds=] ../include/crucible/progress.h:46:24: error: array subscript ‘crucible::ProgressTracker<long unsigned int>::ProgressTrackerState[0]’ is partly outside array bounds of ‘unsigned char [40]’ [-Werror=array-bounds=] The regression is already reported to the GCC project: https://www.mail-archive.com/gcc-bugs%40gcc.gnu.org/msg895281.html https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123912 (and its duplicates) The problem is that GCC's static analyzer forgets that make_shared intentionally allocated a control block and an object in the same allocation, and thinks that accesses beyond the end of the control block are out-of-bounds array accesses. This workaround is the shortest: start with a unique_ptr (which has no control block but does have an exception-safe allocator), then convert to shared_ptr. This breaks the allocation into two parts so that GCC is no longer confused. As there are typically fewer than 10k progress tracking items, the separate control blocks will only add a few hundred KiB of RAM usage. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
1 parent 3812e3d commit 2d53565

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

include/crucible/progress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace crucible {
9090

9191
template <class T>
9292
ProgressTracker<T>::ProgressTracker(const ProgressTracker::value_type &t) :
93-
m_state(make_shared<ProgressTrackerState>())
93+
m_state(make_unique<ProgressTrackerState>())
9494
{
9595
m_state->m_begin = t;
9696
m_state->m_end = t;

0 commit comments

Comments
 (0)