Skip to content

Commit

Permalink
Fix possible read-off-the-end bug from example Cfour file
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Oct 15, 2024
1 parent ad21c32 commit 88df5ad
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions avogadro/quantumio/molden.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ bool MoldenFile::read(std::istream& in, Core::Molecule& molecule)
{
// Read the log file line by line, most sections are terminated by an empty
// line, so they should be retained.
while (!in.eof())
while (!in.eof() && in.good()) {
processLine(in);
}

auto* basis = new GaussianSet;

Expand Down Expand Up @@ -246,12 +247,16 @@ void MoldenFile::processLine(std::istream& in)
getline(in, line);
line = Core::trimmed(line);
}
} else {
// we shouldn't hit this, but better to be safe
break;
}

// okay, we're either done reading
// or we're at the next vibration
if (m_vibDisplacements.size() == m_frequencies.size()) {
// TODO: might need to go back to read intensities
// reset to make sure we don't miss any other sections
// (e.g., intensities)
in.seekg(currentPos);
break;
}
Expand Down

0 comments on commit 88df5ad

Please sign in to comment.