commit:     4194414477473b6da6031425fbb52cf403b2c6f2
Author:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
AuthorDate: Tue Nov  5 23:49:01 2024 +0000
Commit:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
CommitDate: Wed Nov  6 19:51:44 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=41944144

kde-frameworks/ktexteditor: Fix segfaults

KDE-bug: https://bugs.kde.org/show_bug.cgi?id=494826

Signed-off-by: Andreas Sturmlechner <asturm <AT> gentoo.org>

 .../files/ktexteditor-6.7.0-fix-segfault.patch     | 70 ++++++++++++++++++++++
 .../ktexteditor/ktexteditor-6.7.0-r1.ebuild        | 54 +++++++++++++++++
 2 files changed, 124 insertions(+)

diff --git 
a/kde-frameworks/ktexteditor/files/ktexteditor-6.7.0-fix-segfault.patch 
b/kde-frameworks/ktexteditor/files/ktexteditor-6.7.0-fix-segfault.patch
new file mode 100644
index 000000000000..9ae8ebff41b0
--- /dev/null
+++ b/kde-frameworks/ktexteditor/files/ktexteditor-6.7.0-fix-segfault.patch
@@ -0,0 +1,70 @@
+From 43c148b2664e15e2c517ba1eb53dc04447b7d499 Mon Sep 17 00:00:00 2001
+From: Waqar Ahmed <[email protected]>
+Date: Wed, 16 Oct 2024 10:32:36 +0500
+Subject: [PATCH] Fix multiblock range handling when unwrapping line
+
+BUG: 494826
+(cherry picked from commit 2c7e0711efd65e68687d530240bb46a1cf8de122)
+---
+ src/buffer/katetextblock.cpp | 17 ++++++++++++-----
+ 1 file changed, 12 insertions(+), 5 deletions(-)
+
+diff --git a/src/buffer/katetextblock.cpp b/src/buffer/katetextblock.cpp
+index 90ed4e480..d1e767dfd 100644
+--- a/src/buffer/katetextblock.cpp
++++ b/src/buffer/katetextblock.cpp
+@@ -219,7 +219,7 @@ void TextBlock::unwrapLine(int line, TextBlock 
*previousBlock, int fixStartLines
+ 
+         // move all cursors because of the unwrapped line
+         // remember all ranges modified, optimize for the standard case of a 
few ranges
+-        QVarLengthArray<TextRange *, 32> changedRanges;
++        QVarLengthArray<QPair<TextRange *, bool>, 32> changedRanges;
+         for (TextCursor *cursor : m_cursors) {
+             // this is the unwrapped line
+             if (cursor->lineInBlock() == 0) {
+@@ -230,7 +230,7 @@ void TextBlock::unwrapLine(int line, TextBlock 
*previousBlock, int fixStartLines
+                 auto range = cursor->kateRange();
+                 if (range && !range->isValidityCheckRequired()) {
+                     range->setValidityCheckRequired();
+-                    changedRanges.push_back(range);
++                    changedRanges.push_back({range, false});
+                 }
+             }
+         }
+@@ -239,15 +239,18 @@ void TextBlock::unwrapLine(int line, TextBlock 
*previousBlock, int fixStartLines
+         for (auto it = previousBlock->m_cursors.begin(); it != 
previousBlock->m_cursors.end();) {
+             auto cursor = *it;
+             if (cursor->lineInBlock() == lastLineOfPreviousBlock) {
++                Kate::TextRange *range = cursor->kateRange();
++                // get the value before changing the block
++                const bool spansMultipleBlocks = range && 
range->spansMultipleBlocks();
+                 cursor->m_line = 0;
+                 cursor->m_block = this;
+                 m_cursors.insert(cursor);
+ 
+                 // remember range, if any, avoid double insert
+-                auto range = cursor->kateRange();
+                 if (range && !range->isValidityCheckRequired()) {
+                     range->setValidityCheckRequired();
+-                    changedRanges.push_back(range);
++                    // the range might not span multiple blocks anymore
++                    changedRanges.push_back({range, spansMultipleBlocks});
+                 }
+ 
+                 // remove from previous block
+@@ -261,7 +264,11 @@ void TextBlock::unwrapLine(int line, TextBlock 
*previousBlock, int fixStartLines
+         // fixup the ranges that might be effected, because they moved from 
last line to this block
+         // we might need to invalidate ranges or notify about their changes
+         // checkValidity might trigger delete of the range!
+-        for (TextRange *range : std::as_const(changedRanges)) {
++        for (auto [range, wasMultiblock] : changedRanges) {
++            // if the range doesn't span multiple blocks anymore remove it 
from buffer multiline range cache
++            if (!range->spansMultipleBlocks() && wasMultiblock) {
++                m_buffer->removeMultilineRange(range);
++            }
+             // afterwards check validity, might delete this range!
+             range->checkValidity();
+         }
+-- 
+2.47.0
+

diff --git a/kde-frameworks/ktexteditor/ktexteditor-6.7.0-r1.ebuild 
b/kde-frameworks/ktexteditor/ktexteditor-6.7.0-r1.ebuild
new file mode 100644
index 000000000000..9a041c7561e2
--- /dev/null
+++ b/kde-frameworks/ktexteditor/ktexteditor-6.7.0-r1.ebuild
@@ -0,0 +1,54 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+PVCUT=$(ver_cut 1-2)
+QTMIN=6.6.2
+inherit ecm frameworks.kde.org
+
+DESCRIPTION="Framework providing a full text editor component"
+
+LICENSE="LGPL-2+"
+KEYWORDS="~amd64 ~arm64 ~ppc64 ~riscv ~x86"
+IUSE="+editorconfig"
+
+RESTRICT="test"
+
+DEPEND="
+       >=dev-qt/qtbase-${QTMIN}:6[gui,widgets]
+       >=dev-qt/qtdeclarative-${QTMIN}:6
+       >=dev-qt/qtspeech-${QTMIN}:6
+       =kde-frameworks/karchive-${PVCUT}*:6
+       =kde-frameworks/kauth-${PVCUT}*:6
+       =kde-frameworks/kcodecs-${PVCUT}*:6
+       =kde-frameworks/kcompletion-${PVCUT}*:6
+       =kde-frameworks/kconfig-${PVCUT}*:6
+       =kde-frameworks/kconfigwidgets-${PVCUT}*:6
+       =kde-frameworks/kcoreaddons-${PVCUT}*:6
+       =kde-frameworks/kguiaddons-${PVCUT}*:6
+       =kde-frameworks/ki18n-${PVCUT}*:6
+       =kde-frameworks/kiconthemes-${PVCUT}*:6
+       =kde-frameworks/kio-${PVCUT}*:6
+       =kde-frameworks/kitemviews-${PVCUT}*:6
+       =kde-frameworks/kjobwidgets-${PVCUT}*:6
+       =kde-frameworks/kparts-${PVCUT}*:6
+       =kde-frameworks/kwidgetsaddons-${PVCUT}*:6
+       =kde-frameworks/kwindowsystem-${PVCUT}*:6
+       =kde-frameworks/kxmlgui-${PVCUT}*:6
+       =kde-frameworks/sonnet-${PVCUT}*:6
+       =kde-frameworks/syntax-highlighting-${PVCUT}*:6
+       editorconfig? ( app-text/editorconfig-core-c )
+"
+RDEPEND="${DEPEND}"
+BDEPEND="test? ( >=kde-frameworks/kservice-${PVCUT}:6 )"
+
+PATCHES=( "${FILESDIR}/${P}-fix-segfault.patch" ) # KDE-bug 494826
+
+src_configure() {
+       local mycmakeargs=(
+               $(cmake_use_find_package editorconfig EditorConfig)
+       )
+
+       ecm_src_configure
+}

Reply via email to