From 88df5ad9fd7d3a0150f7490fe258cf68b061bcb5 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Mon, 14 Oct 2024 21:02:26 -0400 Subject: [PATCH] Fix possible read-off-the-end bug from example Cfour file Signed-off-by: Geoff Hutchison --- avogadro/quantumio/molden.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/avogadro/quantumio/molden.cpp b/avogadro/quantumio/molden.cpp index e551dca45b..f0ce43461c 100644 --- a/avogadro/quantumio/molden.cpp +++ b/avogadro/quantumio/molden.cpp @@ -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; @@ -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; }