sc/source/core/tool/refupdat.cxx |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

New commits:
commit 60e8be7f9dde44e1c8c0935826396c8bb907517a
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Oct 18 15:47:43 2024 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Oct 18 18:17:34 2024 +0200

    tdf#163486: PVS: It's odd that this function always returns one and the 
same value.
    
    The old implementation used a UB (signed integer overflow).
    
    Change-Id: I1d8222b261f0db49c48b38defa2b58bc4770aae4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175143
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sc/source/core/tool/refupdat.cxx b/sc/source/core/tool/refupdat.cxx
index 95f738c4ed84..62a661aa1a97 100644
--- a/sc/source/core/tool/refupdat.cxx
+++ b/sc/source/core/tool/refupdat.cxx
@@ -156,11 +156,10 @@ static void Expand( R& n1, R& n2, U nStart, S nD )
 
 static bool lcl_IsWrapBig( sal_Int64 nRef, sal_Int32 nDelta )
 {
-    if ( nRef > 0 && nDelta > 0 )
-        return nRef + nDelta <= 0;
-    else if ( nRef < 0 && nDelta < 0 )
-        return nRef + nDelta >= 0;
-    return false;
+    if (nDelta > 0)
+        return nRef > std::numeric_limits<sal_Int64>::max() - nDelta;
+    else
+        return nRef < std::numeric_limits<sal_Int64>::min() - nDelta;
 }
 
 static bool lcl_MoveBig( sal_Int64& rRef, sal_Int64 nStart, sal_Int32 nDelta )

Reply via email to