Skip to content

Skip processing of blank lines in CSV input and ensure minimum column count#421

Open
drbergman wants to merge 1 commit into
MathCancer:developmentfrom
drbergman:fix/blank-cellscsv-lines
Open

Skip processing of blank lines in CSV input and ensure minimum column count#421
drbergman wants to merge 1 commit into
MathCancer:developmentfrom
drbergman:fix/blank-cellscsv-lines

Conversation

@drbergman

Copy link
Copy Markdown
Collaborator

For misspecified cells.csv rows, the error is a cryptic segfault. This makes the error clear and also skips over any blank lines, including a file that ends with two blank lines. Now, the following cells.csv files work for the template project (with initial condition enabled)

extra blank line at end:

x,y,z,type
0,0,0,default

skipped line (perhaps to separate cell types or just an innocent mistake):

x,y,z,type
0,0,0,default

10,0,0,default

throws a clear error message on misspecified csvs:

x,y,z,type
0,0,0,default
0,1,default

Copilot AI review requested due to automatic review settings July 24, 2026 14:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves robustness of CSV-based initial condition loading by skipping blank lines and adding early validation to avoid cryptic crashes when parsing malformed cells.csv rows.

Changes:

  • Skip processing of empty/blank lines when loading v1 CSV cell position files.
  • Add a minimum-column-count check for v2 CSV row parsing to fail fast with a clearer error.
Comments suppressed due to low confidence (1)

modules/PhysiCell_geometry.cpp:748

  • process_csv_v2_line() only checks tokens.size()==0 for blank lines, but whitespace-only lines will produce a single token and currently hard-error. Also, later code indexes labels[k] up to tokens.size()-1; if a row has more columns than the header, this will read past labels and can still segfault on malformed CSVs. Consider treating whitespace-only lines as blank and validating tokens/labels column counts before continuing.
	// check that we have enough tokens and protect against blank lines
	if ( tokens.size() == 0 )
	{ return NULL; }
	else if (tokens.size() < 4)
	{

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modules/PhysiCell_geometry.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants