From d9d9bd65e22a3bd61cce6d88849a794bb0918d7b Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 27 Sep 2021 15:18:00 +0200 Subject: [PATCH] Don't dereference empty optional ...after 183729b7bdb98561dae2a3e8c9518fe4787ee6e3 "no need to allocate these SfxItemSet on the heap", as seen causing SIGABRT at > #1 0x00007f5b61e6a8a4 in abort () at /lib64/libc.so.6 > #2 0x00007f5b30a2414b in std::_Optional_base_impl >::_M_get() const (this=0x7f5ae4f52030) at ~/gcc/trunk/inst/include/c++/12.0.0/optional:443 > #3 0x00007f5b30a219bc in std::optional::operator*() const & (this=0x7f5ae4f52030) at ~/gcc/trunk/inst/include/c++/12.0.0/optional:919 > #4 0x00007f5b30a1eb35 in FlatFndBox::GetItemSet(unsigned short, unsigned short) const (this=0x7f5b337fb730, n_Col=1, n_Row=4) at sw/source/core/doc/docsort.cxx:929 during JunitTest_sw_unoapi_4. Change-Id: If409ce86863faf4617c636616f814237ff62c7ca Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122710 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- sw/source/core/doc/docsort.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index 24dcba033a30..fbd7ff9e9bcb 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -926,7 +926,11 @@ const SfxItemSet* FlatFndBox::GetItemSet(sal_uInt16 n_Col, sal_uInt16 n_Row) con { OSL_ENSURE( m_vItemSets.empty() || ( n_Col < m_nCols && n_Row < m_nRows), "invalid array access"); - return !m_vItemSets.empty() ? &*m_vItemSets[unsigned(n_Row * m_nCols) + n_Col] : nullptr; + if (m_vItemSets.empty()) { + return nullptr; + } + auto const & el = m_vItemSets[unsigned(n_Row * m_nCols) + n_Col]; + return el ? &*el : nullptr; } sal_uInt16 SwMovedBoxes::GetPos(const SwTableBox* pTableBox) const -- 2.11.4.GIT