From abc005bce908874a33e4ec80844c8d6bd447ae11 Mon Sep 17 00:00:00 2001 From: Daniel Bergman Date: Fri, 24 Jul 2026 10:36:39 -0400 Subject: [PATCH] Skip processing of blank lines in CSV input and ensure minimum column count --- modules/PhysiCell_geometry.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/PhysiCell_geometry.cpp b/modules/PhysiCell_geometry.cpp index a995422ea..a2738bec6 100644 --- a/modules/PhysiCell_geometry.cpp +++ b/modules/PhysiCell_geometry.cpp @@ -311,7 +311,9 @@ void load_cells_csv_v1( std::string filename ) std::vector data; csv_to_vector( line.c_str() , data ); - if( data.size() != 4 ) + if (data.size() == 0) + { continue; } // skip blank lines + else if( data.size() != 4 ) { std::cout << "Error! Importing cells from a CSV file expects each row to be x,y,z,typeID." << std::endl; exit(-1); @@ -739,6 +741,15 @@ Cell* process_csv_v2_line( std::string line , std::vector labels ) while( std::getline( stream , s , ',' ) ) { tokens.push_back(s); } + // check that we have enough tokens and protect against blank lines + if ( tokens.size() == 0 ) + { return NULL; } + else if (tokens.size() < 4) + { + std::cerr << "Error: CSV file expects at least 4 columns (x,y,z,cell_type) but found " << tokens.size() << std::endl; + exit(-1); + } + // get the cell position std::vector position; char* pTemp;