Skip to content

Commit

Permalink
Resolve off by one error in bug 489 by ensuring substring doesn't fail.
Browse files Browse the repository at this point in the history
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Jan 2, 2015
1 parent a25a2da commit 09ef737
Show file tree
Hide file tree
Showing 3 changed files with 12,341 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,19 +651,19 @@ private PDBAtom readAtom(String cLine, int lineLength) {
oAtom.setAtomTypeName(oAtom.getResName() + "." + rawAtomName);
}
if (lineLength >= 59) {
String frag = cLine.substring(54, 60).trim();
String frag = cLine.substring(54, Math.min(lineLength, 60)).trim();
if (frag.length() > 0) {
oAtom.setOccupancy(Double.parseDouble(frag));
}
}
if (lineLength >= 65) {
String frag = cLine.substring(60, 66).trim();
String frag = cLine.substring(60, Math.min(lineLength, 66)).trim();
if (frag.length() > 0) {
oAtom.setTempFactor(Double.parseDouble(frag));
}
}
if (lineLength >= 75) {
oAtom.setSegID(cLine.substring(72, 76).trim());
oAtom.setSegID(cLine.substring(72, Math.min(lineLength, 76)).trim());
}
// if (lineLength >= 78) {
// oAtom.setSymbol((new String(cLine.substring(76, 78))).trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,4 +590,12 @@ public void test1D66() throws Exception {

}

/**
* @cdk.bug 489
*/
@Category(SlowTest.class)
@Test public void readFinalPump() throws Exception {
IChemFile chemFile = new PDBReader(getClass().getResourceAsStream("finalPump96.09.06.pdb")).read(new ChemFile());
}

}

0 comments on commit 09ef737

Please sign in to comment.