Skip to content

Commit

Permalink
Fix MDL test - off-by-one in line length for M CHG etc.
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Jan 23, 2025
1 parent 176c59f commit 6cf3503
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions avogadro/io/mdlformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
getline(in, buffer);
// should be long enough, e.g.
// 5 4 0 0 0 0 0 0 0 0999 V2000
if (buffer.size() < 39) {
if (!in.good() || buffer.size() < 39) {
appendError("Error reading counts line.");
return false;
}
Expand Down Expand Up @@ -214,6 +214,8 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
static_cast<unsigned char>(order));
}

std::cout << "read atoms and bonds" << std::endl;

// Parse the properties block until the end of the file.
// Property lines count is not used, as it it now unsupported.
bool foundEnd(false);
Expand All @@ -222,6 +224,8 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
if (!in.good() || buffer.size() < 6) {
break;
}
std::cout << " prefix " << buffer.substr(0, 6) << std::endl;

string prefix = buffer.substr(0, 6);
if (prefix == "M END") {
foundEnd = true;
Expand All @@ -230,8 +234,9 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
if (!foundChgProperty)
chargeList.clear(); // Forget old-style charges
size_t entryCount(lexicalCast<int>(buffer.substr(6, 3), ok));
if (buffer.length() < 17 + 8 * entryCount) {
if (buffer.length() < 17 + 8 * (entryCount - 1)) {
appendError("Error parsing charge block.");
std::cout << " " << entryCount << " " << buffer.length() << std::endl;
return false;
}

Expand All @@ -255,7 +260,7 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
// radical center
spinMultiplicity = 1; // reset and count
size_t entryCount(lexicalCast<int>(buffer.substr(6, 3), ok));
if (buffer.length() < 17 + 8 * entryCount) {
if (buffer.length() < 17 + 8 * (entryCount - 1)) {
appendError("Error parsing radical block.");
return false;
}
Expand Down Expand Up @@ -283,7 +288,7 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
} else if (prefix == "M ISO") {
// isotope
size_t entryCount(lexicalCast<int>(buffer.substr(6, 3), ok));
if (buffer.length() < 17 + 8 * entryCount) {
if (buffer.length() < 17 + 8 * (entryCount - 1)) {
appendError("Error parsing isotope block.");
return false;
}
Expand All @@ -307,6 +312,8 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
}
}

std::cout << " read properties " << std::endl;

if (!foundEnd) {
appendError("Error, ending tag for file not found.");
return false;
Expand Down Expand Up @@ -338,7 +345,7 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
bool inValue(false);
string dataName;
string dataValue;
while (getline(in, buffer)) {
while (getline(in, buffer) && in.good()) {
if (trimmed(buffer) == "$$$$")
break;
if (inValue) {
Expand Down

1 comment on commit 6cf3503

@github-actions
Copy link

Choose a reason for hiding this comment

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

ERROR: clang-format-diff detected formatting issues. See the artifact for a patch or run clang-format on your branch.

Please sign in to comment.