sw/source/core/doc/textboxhelper.cxx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
New commits: commit 8d4d80dd86994fbac570bd92d239bffb7883cf45 Author: Mike Kaganski <[email protected]> AuthorDate: Fri Aug 9 08:18:10 2024 +0200 Commit: Mike Kaganski <[email protected]> CommitDate: Fri Aug 9 17:16:01 2024 +0200 It seems that SdrPage must not contain nullptr It takes precautions to not insert nullptr (see SdrObjList::InsertObject), so it would be a programming error to find one here. Change-Id: If5e267743ac6d786575f2c7ca6e7b3e9cc67b082 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171671 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 480da763ea83..470fe00a8f75 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -47,7 +47,6 @@ #include <frmatr.hxx> #include <com/sun/star/document/XActionLockable.hpp> -#include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/text/SizeType.hpp> #include <com/sun/star/text/WrapTextMode.hpp> @@ -343,7 +342,8 @@ sal_Int32 SwTextBoxHelper::getCount(SdrPage const* pPage) sal_Int32 nRet = 0; for (const rtl::Reference<SdrObject>& p : *pPage) { - if (p && p->IsTextBox()) + assert(p); + if (p->IsTextBox()) continue; ++nRet; } @@ -369,14 +369,11 @@ uno::Any SwTextBoxHelper::getByIndex(SdrPage const* pPage, sal_Int32 nIndex) sal_Int32 nCount = 0; // Current logical index. for (const rtl::Reference<SdrObject>& p : *pPage) { - if (p && p->IsTextBox()) + assert(p); + if (p->IsTextBox()) continue; if (nCount == nIndex) - { - if (!p) - throw lang::IllegalArgumentException(); return uno::Any(p->getUnoShape()); - } ++nCount; } @@ -390,7 +387,8 @@ sal_Int32 SwTextBoxHelper::getOrdNum(const SdrObject* pObject) sal_Int32 nOrder = 0; // Current logical order. for (const rtl::Reference<SdrObject>& p : *pPage) { - if (p && p->IsTextBox()) + assert(p); + if (p->IsTextBox()) continue; if (p == pObject) return nOrder; commit 76a1a9bbb14e6c9278f1e4fc5da1621d748ba3cc Author: Mike Kaganski <[email protected]> AuthorDate: Fri Aug 9 08:03:15 2024 +0200 Commit: Mike Kaganski <[email protected]> CommitDate: Fri Aug 9 17:15:55 2024 +0200 Simplify a bit Change-Id: I5d876ce05f070df48d36acbd988de5781fcd1543 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171670 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 3c202d998c08..480da763ea83 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -47,6 +47,7 @@ #include <frmatr.hxx> #include <com/sun/star/document/XActionLockable.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/text/SizeType.hpp> #include <com/sun/star/text/WrapTextMode.hpp> @@ -365,7 +366,6 @@ uno::Any SwTextBoxHelper::getByIndex(SdrPage const* pPage, sal_Int32 nIndex) if (nIndex < 0) throw lang::IndexOutOfBoundsException(); - SdrObject* pRet = nullptr; sal_Int32 nCount = 0; // Current logical index. for (const rtl::Reference<SdrObject>& p : *pPage) { @@ -373,16 +373,14 @@ uno::Any SwTextBoxHelper::getByIndex(SdrPage const* pPage, sal_Int32 nIndex) continue; if (nCount == nIndex) { - pRet = p.get(); - break; + if (!p) + throw lang::IllegalArgumentException(); + return uno::Any(p->getUnoShape()); } ++nCount; } - if (!pRet) - throw lang::IndexOutOfBoundsException(); - - return uno::Any(uno::Reference<drawing::XShape>(pRet->getUnoShape(), uno::UNO_QUERY)); + throw lang::IndexOutOfBoundsException(); } sal_Int32 SwTextBoxHelper::getOrdNum(const SdrObject* pObject)
