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 authored Aug 4, 2024
1 parent 41b1018 commit b31d792
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/coreComponents/LvArray
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 b31d792

Please sign in to comment.