Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/editors/diamond/files/patch-e8f0d274471cf0a50a78aec102ffa87541887f2e.patch
16461 views
1
From e8f0d274471cf0a50a78aec102ffa87541887f2e Mon Sep 17 00:00:00 2001
2
From: Adriaan de Groot <[email protected]>
3
Date: Sun, 20 Feb 2022 16:23:53 +0100
4
Subject: [PATCH] Fix crash when passing filenames on command-line
5
6
Consider running `diamond file.txt`. If previously there
7
was an untitled tab open and nothing else, we arrive
8
here with 2 tabs, `cnt==2`. The first for-loop finds
9
an untitled tab at index `k==0` and decrements `cnt`,
10
then the for-loop increments `k` and the for-loop terminates
11
(because `1 < 1` is false). We have `cnt==1` but an **empty**
12
list `m_openedFiles`. This crashes with an out-of-bounds access
13
in the second for-loop, because `cnt` doesn't match the length
14
of the list anymore.
15
16
As a fix:
17
- do not modify `cnt` in the first for-loop, always check
18
all of the current tabs,
19
- re-calculate the `cnt` based on the files that are actually
20
opened, before the second loop.
21
---
22
src/recent_tabs.cpp | 8 +++-----
23
1 file changed, 3 insertions(+), 5 deletions(-)
24
25
diff --git a/src/recent_tabs.cpp b/src/recent_tabs.cpp
26
index b3359ac..3eef680 100644
27
--- src/recent_tabs.cpp
28
+++ src/recent_tabs.cpp
29
@@ -31,15 +31,13 @@ void MainWindow::openTab_CreateMenus()
30
for (int k = 0; k < cnt; ++k) {
31
fullName = this->get_curFileName(k);
32
33
- if (fullName.isEmpty()) {
34
- --cnt;
35
-
36
- } else {
37
+ if (!fullName.isEmpty()) {
38
m_openedFiles.append(fullName);
39
m_openedModified.append(false);
40
}
41
}
42
-
43
+ // How many were really opened
44
+ cnt = m_openedFiles.count();
45
//
46
QMenu *windowMenu = m_ui->menuWindow;
47
windowMenu->addSeparator();
48
49