sc/source/core/tool/interpr1.cxx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
New commits: commit b16dd0fb306944a02e5d73d4a2bbc68cf80b0b8f Author: Eike Rathke <[email protected]> AuthorDate: Tue May 27 22:14:41 2025 +0200 Commit: Eike Rathke <[email protected]> CommitDate: Wed May 28 00:03:24 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 <[email protected]> Tested-by: Jenkins diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 0cb678dfdfcb..314054b8cb02 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -4803,14 +4803,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 @@ -7196,7 +7199,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. @@ -7222,7 +7226,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
