Skip to content
Snippets Groups Projects
Verified Commit 98e4ebc9 authored by Xavier Robin's avatar Xavier Robin
Browse files

fix: guard against invalid handles

GetPrev() or GetNext() may return invalid residue handles. It is
unclear what happens next, find() may simply (hopefully) find nothing,
however this feels unsafe. This fix guards against this possibility
by checking for handles validity before giving them to find().
parent 34da23eb
No related branches found
No related tags found
No related merge requests found
......@@ -110,24 +110,28 @@ public:
}
// educated guess: we are trying to connect to the previous/next residue
std::map<ResidueHandle, ResidueHandle>::const_iterator j;
j = to_from_->find(dst_res.GetPrev());
if (j != to_from_->end()) {
if (j->second == r) {
if (CheckInsertionCode(
j->first.FindAtom(src_atom.GetName()).GetResidue(),
r, dst_res)) {
return j->first.FindAtom(src_atom.GetName());
if (dst_res.GetPrev().IsValid()) {
j = to_from_->find(dst_res.GetPrev());
if (j != to_from_->end()) {
if (j->second == r) {
if (CheckInsertionCode(
j->first.FindAtom(src_atom.GetName()).GetResidue(),
r, dst_res)) {
return j->first.FindAtom(src_atom.GetName());
}
}
}
}
j = to_from_->find(dst_res.GetNext());
if (j != to_from_->end()) {
if (j->second == r) {
if (CheckInsertionCode(
j->first.FindAtom(src_atom.GetName()).GetResidue(),
r, dst_res)) {
return j->first.FindAtom(src_atom.GetName());
}
if (dst_res.GetNext().IsValid()) {
j = to_from_->find(dst_res.GetNext());
if (j != to_from_->end()) {
if (j->second == r) {
if (CheckInsertionCode(
j->first.FindAtom(src_atom.GetName()).GetResidue(),
r, dst_res)) {
return j->first.FindAtom(src_atom.GetName());
}
}
}
}
// still nothing. scan linearly through all residues.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment