From a881b303b322eb643ae4e99c9c1e3823e85bb754 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Wed, 22 Jul 2026 14:14:05 +0200 Subject: [PATCH] tdf#130857 formula: Only use selection indices if selection exists The bool return value of weld::TextWidget::get_selection_bounds indicates whether a text selection actually exists. Only use the start and end indices from the out params if that is the case and otherwise return a default-constructed Selection object (i.e. one using start and end indices of 0). Otherwise, this would result in an assertion due to the use of invalid string indices as seen with the qt6 vcl plugin and native widgets enabled (SAL_VCL_QT_USE_WELDED_WIDGETS=1) for the following scenario with upcoming commit Change-Id: I10fcd9c326a047cf4abd34369f02be1847d77ae1 Author: Michael Weghorn Date: Wed Jul 22 14:20:53 2026 +0200 tdf#130857 qt weld: Support Calc "Edit Print Ranges" dialog in place: * start Calc * "Format" -> "Print Ranges" -> "Edit..." * click on the "Shrink" button in the "Print Range" section * click anywhere in the sheet Assertion: soffice.bin: /home/michi/development/git/libreoffice/sal/rtl/strtmpl.hxx:1059: void rtl::str::newReplaceStrAt(rtl_tString **, rtl_tString *, sal_Int32, sal_Int32, rtl_tString *) [rtl_tString = _rtl_uString]: Assertion `nIndex >= 0 && nIndex <= pStr->length' failed. This is because QtInstanceEntry::get_selection_bounds sets the indices to -1 if no selection exists. Change-Id: Ifc8fd6f6a6d676fe26364da9077cb10acb439a5a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208474 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- formula/source/ui/dlg/funcutl.cxx | 9 +++++++++ include/formula/funcutl.hxx | 7 +------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/formula/source/ui/dlg/funcutl.cxx b/formula/source/ui/dlg/funcutl.cxx index 9b4fb3a55be0..83d0eb192549 100644 --- a/formula/source/ui/dlg/funcutl.cxx +++ b/formula/source/ui/dlg/funcutl.cxx @@ -337,6 +337,15 @@ void RefEdit::SetReferences(IControlReferenceHandler* pDlg, weld::Frame* pFrame) maGetLabelTextForShrinkModeFunc = [pFrame] { return pFrame->get_label(); }; } +Selection RefEdit::GetSelection() const +{ + int nStartPos, nEndPos; + if (mxEntry->get_selection_bounds(nStartPos, nEndPos)) + return Selection(nStartPos, nEndPos); + + return Selection(); +} + OUString RefEdit::GetLabelTextForShrinkMode() { if (maGetLabelTextForShrinkModeFunc) diff --git a/include/formula/funcutl.hxx b/include/formula/funcutl.hxx index 390ae2799c16..3d3d4e6c1e8c 100644 --- a/include/formula/funcutl.hxx +++ b/include/formula/funcutl.hxx @@ -117,12 +117,7 @@ public: mxEntry->set_position(-1); } - Selection GetSelection() const - { - int nStartPos, nEndPos; - mxEntry->get_selection_bounds(nStartPos, nEndPos); - return Selection(nStartPos, nEndPos); - } + Selection GetSelection() const; OUString GetLabelTextForShrinkMode();