From 389226b82e61679df3c8f5172fd2046d41a1265e Mon Sep 17 00:00:00 2001 From: Marcin Wojdyr Date: Sat, 31 Aug 2024 20:01:02 +0200 Subject: [PATCH] two more checks, in align_sequence_to_polymer and superpose_positions calculate_superposition() segfaulted when called with empty ResidueSpan --- include/gemmi/align.hpp | 3 ++- include/gemmi/qcp.hpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/gemmi/align.hpp b/include/gemmi/align.hpp index d50256469..ceb8327f7 100644 --- a/include/gemmi/align.hpp +++ b/include/gemmi/align.hpp @@ -35,12 +35,13 @@ inline std::vector prepare_target_gapo(const ConstResidueSpan& polymer, return gaps; } -// pre: !!polymer inline AlignmentResult align_sequence_to_polymer( const std::vector& full_seq, const ConstResidueSpan& polymer, PolymerType polymer_type, const AlignmentScoring* scoring=nullptr) { + if (!polymer) + return AlignmentResult(); std::map encoding; if (!scoring) scoring = AlignmentScoring::partial_model(); diff --git a/include/gemmi/qcp.hpp b/include/gemmi/qcp.hpp index 56a45abad..7e0be7a74 100644 --- a/include/gemmi/qcp.hpp +++ b/include/gemmi/qcp.hpp @@ -303,6 +303,11 @@ inline SupResult superpose_positions(const Position* pos1, const Position* pos2, result.center1 = qcp_calculate_center(pos1, len, weight); result.center2 = qcp_calculate_center(pos2, len, weight); + if (len == 0) { + result.rmsd = NAN; + return result; + } + double wsum = 0.0; if (weight == nullptr) wsum = (double) len;