diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-08-24 11:37:40 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-08-24 12:51:08 +0200 |
commit | 2476104c9168969b4970bd613a11078fec699435 (patch) | |
tree | cade8499a7e1a1df8d507c038703624ccd8039d3 | |
parent | 47d51286103dc6fa2c4ddfa871bde4878aef17ef (diff) |
fix ubsan signed integer overflow
after
commit 6b544507b01d479b991d3ba7c949cb70696a3f2e
Author: Noel Grandin <noel.grandin@collabora.co.uk>
Date: Tue Aug 23 11:42:38 2022 +0200
Use more SwPosition::Adjust
ubsan started to complain because the SAL_WARN_IF here assumes that nVal
is >= 0. Make it work if nVal is < 0.
/sw/source/core/bastyp/index.cxx:332:5: runtime error: signed integer
overflow: 2147483647 - -1 cannot be represented in type 'int'
/sw/source/core/bastyp/index.cxx:332:5
/sw/source/core/crsr/pam.cxx:257:14
SwPaM*) /sw/source/uibase/wrtsh/wrtsh2.cxx:129:52
/sw/source/uibase/fldui/fldmgr.cxx:1490:39
SfxRequest const&) /sw/source/uibase/wrtsh/wrtsh1.cxx:2284:19
Change-Id: Ic9e98b5350a55713f6b3fc2b39c9cbce97ee7223
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138756
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sw/source/core/bastyp/index.cxx | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/sw/source/core/bastyp/index.cxx b/sw/source/core/bastyp/index.cxx index f7868e8901e0..c7ded156ea26 100644 --- a/sw/source/core/bastyp/index.cxx +++ b/sw/source/core/bastyp/index.cxx @@ -329,7 +329,7 @@ sal_Int32 SwContentIndex::operator--() sal_Int32 SwContentIndex::operator+=( sal_Int32 const nVal ) { - SAL_WARN_IF( !(m_nIndex <= SAL_MAX_INT32 - nVal), "sw.core", + SAL_WARN_IF( !(nVal > 0 ? m_nIndex <= SAL_MAX_INT32 - nVal : m_nIndex >= nVal), "sw.core", "SwContentIndex SwContentIndex::operator+=(sal_Int32) wraps around" ); return ChgValue( *this, m_nIndex + nVal ).m_nIndex; } |