sc/source/core/tool/interpr1.cxx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
New commits: commit 5b933213384796552650489a17b0af899eb03a0c Author: Eike Rathke <er...@redhat.com> AuthorDate: Tue May 27 22:14:41 2025 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed May 28 00:51:40 2025 +0200 Resolves: tdf#163614 empty compares greater-than for LOOKUP() Change-Id: I529a83f18a0660c97bd1c9368418f1751b1db2aa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185932 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins (cherry picked from commit b16dd0fb306944a02e5d73d4a2bbc68cf80b0b8f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185933 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 12db67ea1db9..dcf767a69c5e 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -4856,14 +4856,17 @@ private: /** returns -1 when the matrix value is smaller than the query value, 0 when they are equal, and 1 when the matrix value is larger than the query value. */ -sal_Int32 lcl_CompareMatrix2Query( - SCSIZE i, const VectorMatrixAccessor& rMat, const ScQueryParam& rParam, const ScQueryEntry& rEntry, bool bMatchWholeCell ) +sal_Int32 lcl_CompareMatrix2Query( SCSIZE i, const VectorMatrixAccessor& rMat, const ScQueryParam& rParam, + const ScQueryEntry& rEntry, bool bMatchWholeCell, bool bEmptyIsLess = true ) { if (rMat.IsEmpty(i)) { /* TODO: in case we introduced query for real empty this would have to * be changed! */ - return -1; // empty always less than anything else + if (bEmptyIsLess) + return -1; // empty always less than anything else + else + return 1; // empty always greater than anything else } /* FIXME: what is an empty path (result of IF(false;true_path) in @@ -7249,7 +7252,8 @@ void ScInterpreter::ScLookup() for (SCSIZE nLen = nLast-nFirst; nLen > 0; nLen = nLast-nFirst) { SCSIZE nMid = nFirst + nLen/2; - sal_Int32 nCmp = lcl_CompareMatrix2Query( nMid, aMatAcc2, aParam, rEntry, bMatchWholeCell ); + sal_Int32 nCmp = lcl_CompareMatrix2Query( nMid, aMatAcc2, aParam, rEntry, bMatchWholeCell, + false /* bEmptyIsLess, instead empty are sorted to end */); if (nCmp == 0) { // exact match. find the last item with the same value. @@ -7275,7 +7279,8 @@ void ScInterpreter::ScLookup() if (nDelta == static_cast<SCCOLROW>(nLenMajor-2)) // last item { - sal_Int32 nCmp = lcl_CompareMatrix2Query(nDelta+1, aMatAcc2, aParam, rEntry, bMatchWholeCell ); + sal_Int32 nCmp = lcl_CompareMatrix2Query(nDelta+1, aMatAcc2, aParam, rEntry, bMatchWholeCell, + false /* bEmptyIsLess, instead empty are sorted to end */); if (nCmp <= 0) { // either the last item is an exact match or the real