From b31d792bbf70f9859c44fd6e2c95558d2832c2d3 Mon Sep 17 00:00:00 2001 From: Randolph Settgast Date: Sat, 3 Aug 2024 17:58:36 -1000 Subject: [PATCH] fix: Fix segfault in table (#3268) * change a range based loop that modifies the ranged container to a standard iterator loop. Isolate busted range bound in std::vector usage --- src/coreComponents/LvArray | 2 +- src/coreComponents/fileIO/Table/TableFormatter.cpp | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/coreComponents/LvArray b/src/coreComponents/LvArray index 02ce362c009..e7bf1096d57 160000 --- a/src/coreComponents/LvArray +++ b/src/coreComponents/LvArray @@ -1 +1 @@ -Subproject commit 02ce362c009f11ddb2ade0286df23408d7334c4f +Subproject commit e7bf1096d57558be720f177141c40e4ab69b3f5e diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 8d564e83ce5..d6e145b6a9c 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -103,17 +103,21 @@ void formatColumnsFromLayout( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > & tableDataRows ) { integer idxColumn = 0; - for( auto & column : columns ) + for( auto iterColumn = columns.begin(); iterColumn!=columns.end(); ) { - if( !column.m_parameter.enabled ) + if( !iterColumn->m_parameter.enabled ) { - columns.erase( columns.begin() + idxColumn ); + iterColumn = columns.erase( iterColumn ); for( auto & row : tableDataRows ) { row.erase( row.begin() + idxColumn ); } } - ++idxColumn; + else + { + ++iterColumn; + ++idxColumn; + } } } @@ -377,7 +381,7 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c auto const & columnContent = section == TableLayout::Section::header ? columns[idxColumn].m_parameter.splitColumnNameLines : columns[idxColumn].m_columnValues; - string cell = columnContent[idxRow]; + string cell = columnContent.at( idxRow ); integer const cellSize = currentColumn.m_maxStringSize.length(); tableOutput << buildCell( currentColumn.m_parameter.alignment, cell, cellSize );