Skip to content

Commit

Permalink
fix: Fix segfault in table (#3268)
Browse files Browse the repository at this point in the history
* change a range based loop that modifies the ranged container to a standard iterator loop. Isolate busted range bound in std::vector usage
  • Loading branch information
rrsettgast committed Sep 17, 2024
1 parent 510cbcd commit 75f21d0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/coreComponents/fileIO/Table/TableFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 75f21d0

Please sign in to comment.