From 1b814b266f1bd25d92b701e071473f2267330933 Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Mon, 22 Mar 2021 12:49:26 +0100 Subject: [PATCH] fix crash when looking for where connectors diverge --- src/electronics/ecnode.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/electronics/ecnode.cpp b/src/electronics/ecnode.cpp index 385844c1..28f2a556 100644 --- a/src/electronics/ecnode.cpp +++ b/src/electronics/ecnode.cpp @@ -225,10 +225,18 @@ QPoint ECNode::findConnectorDivergePoint(bool *found) if (!gotP1 || !gotP2 ) return QPoint(0,0); - unsigned maxLength = p1.size() > p2.size() ? p1.size() : p2.size(); + // If they are differing lengths, return the end of the shortest + if (p1.size() < p2.size()) { + *found = true; + return p1.last(); + } else if (p2.size() < p1.size()) { + *found = true; + return p2.last(); + } + + Q_ASSERT(p1.size() == p2.size()); - for ( unsigned i = 1; i < maxLength; ++i ) - { + for (unsigned i = 1; i < qMin(p1.size(), p2.size()); ++i) { if ( p1[i] != p2[i] ) { *found = true; return p1[i-1]; -- GitLab