From 9bc97d489223dd5f13db7116b96ca1ad9fd4de49 Mon Sep 17 00:00:00 2001
From: Xavier Robin <xavalias-github@xavier.robin.name>
Date: Tue, 21 Nov 2023 17:13:29 +0100
Subject: [PATCH] fix static_cast overflow in LocateAtom

An overflow would happen when the residue contains unknown atoms that
are not in the compound, and can prevent bonds from being properly
created in ConnectAtomsOfResidue.
---
 modules/conop/src/processor.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/modules/conop/src/processor.cc b/modules/conop/src/processor.cc
index 840c8b4a7..e3206b0b4 100644
--- a/modules/conop/src/processor.cc
+++ b/modules/conop/src/processor.cc
@@ -327,10 +327,10 @@ void Processor::ReorderAtoms(mol::ResidueHandle residue,
   mol::impl::AtomImplList::iterator i=impl->GetAtomList().begin();
   for (; i!=impl->GetAtomList().end(); ++i) {
     mol::impl::AtomImplPtr atom=*i;
-    atom->SetState(std::numeric_limits<unsigned int>::max());
+    atom->SetState(std::numeric_limits<int>::max());
     int index=compound->GetAtomSpecIndex(atom->GetName());
     if (index==-1) {
-      atom->SetState(std::numeric_limits<unsigned int>::max());
+      atom->SetState(std::numeric_limits<int>::max());
       continue;
     }
     atom->SetState((compound->GetAtomSpecs())[index].ordinal);
@@ -350,7 +350,7 @@ bool Processor::HasUnknownAtoms(mol::ResidueHandle res,
   mol::AtomHandleList atoms=res.GetAtomList();
   for (mol::AtomHandleList::iterator 
        i=atoms.begin(), e=atoms.end(); i!=e; ++i) {
-    if ((*i).Impl()->GetState()==std::numeric_limits<unsigned int>::max()) {
+    if ((*i).Impl()->GetState()==std::numeric_limits<int>::max()) {
       if (((*i).GetElement()=="H" || (*i).GetElement()=="D") && 
           !strict_hydrogens) {
         continue;
-- 
GitLab