summaryrefslogtreecommitdiff
path: root/sci-electronics/ktechlab/files/ktechlab-0.50.0-crashfix-connectors-diverging.patch
blob: 20222c89daab9f1a3ec9731210c32988e62c9ab3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
From 1b814b266f1bd25d92b701e071473f2267330933 Mon Sep 17 00:00:00 2001
From: "Martin T. H. Sandsmark" <martin.sandsmark@kde.org>
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