summaryrefslogtreecommitdiff
path: root/sot
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-04-26 15:08:36 +0200
committerStephan Bergmann <sbergman@redhat.com>2022-04-26 17:04:01 +0200
commitbdff0bb77b57def835fcaed3bded7519e69dc896 (patch)
treec330add464f566a32ebd82dd9ad29f91ba0d87f8 /sot
parent651527b4efe9700c8c8dff58ce5aa86ad5681f16 (diff)
Use o3tl::make_unsigned in some places
...where a signed and an unsigned value are compared, and the signed value has just been proven to be non-negative here Change-Id: I9665e6c2c4c5557f2d4cf1bb646f9fffc7bd7d30 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133442 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sot')
-rw-r--r--sot/source/sdstor/stgcache.cxx3
-rw-r--r--sot/source/sdstor/stgcache.hxx3
2 files changed, 4 insertions, 2 deletions
diff --git a/sot/source/sdstor/stgcache.cxx b/sot/source/sdstor/stgcache.cxx
index 9881d6e0e7a7..2a7e9493f5bf 100644
--- a/sot/source/sdstor/stgcache.cxx
+++ b/sot/source/sdstor/stgcache.cxx
@@ -18,6 +18,7 @@
*/
#include <string.h>
+#include <o3tl/safeint.hxx>
#include <osl/endian.h>
#include <osl/diagnose.h>
@@ -53,7 +54,7 @@ rtl::Reference< StgPage > StgPage::Create( short nData, sal_Int32 nPage )
void StgCache::SetToPage ( const rtl::Reference< StgPage >& rPage, short nOff, sal_Int32 nVal )
{
- if( ( nOff < static_cast<short>( rPage->GetSize() / sizeof( sal_Int32 ) ) ) && nOff >= 0 )
+ if( nOff >= 0 && ( o3tl::make_unsigned(nOff) < rPage->GetSize() / sizeof( sal_Int32 ) ) )
{
#ifdef OSL_BIGENDIAN
nVal = OSL_SWAPDWORD(nVal);
diff --git a/sot/source/sdstor/stgcache.hxx b/sot/source/sdstor/stgcache.hxx
index c9b123c17f9d..7efbffae5b4f 100644
--- a/sot/source/sdstor/stgcache.hxx
+++ b/sot/source/sdstor/stgcache.hxx
@@ -20,6 +20,7 @@
#ifndef INCLUDED_SOT_SOURCE_SDSTOR_STGCACHE_HXX
#define INCLUDED_SOT_SOURCE_SDSTOR_STGCACHE_HXX
+#include <o3tl/safeint.hxx>
#include <osl/endian.h>
#include <rtl/ref.hxx>
#include <tools/stream.hxx>
@@ -115,7 +116,7 @@ public:
inline sal_Int32 StgCache::GetFromPage ( const rtl::Reference< StgPage >& rPage, short nOff )
{
- if( ( nOff >= static_cast<short>( rPage->GetSize() / sizeof( sal_Int32 ) ) ) || nOff < 0 )
+ if( nOff < 0 || ( o3tl::make_unsigned(nOff) >= rPage->GetSize() / sizeof( sal_Int32 ) ) )
return -1;
sal_Int32 n = static_cast<sal_Int32*>(rPage->GetData())[ nOff ];
#ifdef OSL_BIGENDIAN