[Libreoffice-commits] core.git: dtrans/source extensions/source sal/osl shell/source tools/source vcl/win winaccessibility/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Mon Feb 3 19:28:01 UTC 2020


 dtrans/source/win32/dtobj/FmtFilter.cxx       |    4 +++-
 dtrans/source/win32/dtobj/XTDataObject.cxx    |    5 +++--
 extensions/source/ole/unoobjw.cxx             |    5 +++--
 sal/osl/w32/socket.cxx                        |    3 ++-
 shell/source/win32/zipfile/zipfile.cxx        |    8 +++++---
 tools/source/misc/pathutils.cxx               |    6 +++---
 vcl/win/window/salmenu.cxx                    |    3 ++-
 winaccessibility/source/service/AccObject.cxx |    3 ++-
 8 files changed, 23 insertions(+), 14 deletions(-)

New commits:
commit b66c5f77d150056b2de262dae66301fcd7dc38c1
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Mon Feb 3 16:21:55 2020 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Mon Feb 3 20:27:29 2020 +0100

    loplugin:unsignedcompare (clang-cl)
    
    Change-Id: I69cc1b352221ca053ccd0c5b78e926480a8c9ccd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87884
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/dtrans/source/win32/dtobj/FmtFilter.cxx b/dtrans/source/win32/dtobj/FmtFilter.cxx
index 74df67541140..e9c4b42f8b68 100644
--- a/dtrans/source/win32/dtobj/FmtFilter.cxx
+++ b/dtrans/source/win32/dtobj/FmtFilter.cxx
@@ -20,6 +20,8 @@
 #include <string.h>
 
 #include "FmtFilter.hxx"
+
+#include <o3tl/safeint.hxx>
 #include <osl/diagnose.h>
 
 #include <shobjidl.h>
@@ -176,7 +178,7 @@ HENHMETAFILE OOMFPictToWinENHMFPict( Sequence< sal_Int8 > const & aOOMetaFilePic
 
 Sequence< sal_Int8 > WinDIBToOOBMP( const Sequence< sal_Int8 >& aWinDIB )
 {
-    OSL_ENSURE(sal_uInt32(aWinDIB.getLength()) > sizeof(BITMAPINFOHEADER), "CF_DIBV5/CF_DIB too small (!)");
+    OSL_ENSURE(o3tl::make_unsigned(aWinDIB.getLength()) > sizeof(BITMAPINFOHEADER), "CF_DIBV5/CF_DIB too small (!)");
     Sequence< sal_Int8 > ooBmpStream;
 
     ooBmpStream.realloc(aWinDIB.getLength( ) + sizeof(BITMAPFILEHEADER));
diff --git a/dtrans/source/win32/dtobj/XTDataObject.cxx b/dtrans/source/win32/dtobj/XTDataObject.cxx
index 6df5c9d384c1..01b1ce39fce4 100644
--- a/dtrans/source/win32/dtobj/XTDataObject.cxx
+++ b/dtrans/source/win32/dtobj/XTDataObject.cxx
@@ -19,6 +19,7 @@
 
 #include <osl/diagnose.h>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/safeint.hxx>
 
 #include "XTDataObject.hxx"
 #include <com/sun/star/datatransfer/DataFlavor.hpp>
@@ -368,11 +369,11 @@ void CXTDataObject::renderAnyDataAndSetupStgMedium(
 #ifdef DBG_UTIL
         if(CF_DIBV5 == fetc.cfFormat)
         {
-            OSL_ENSURE(sal_uInt32(clipDataStream.getLength()) > (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPV5HEADER)), "Wrong size on CF_DIBV5 data (!)");
+            OSL_ENSURE(o3tl::make_unsigned(clipDataStream.getLength()) > (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPV5HEADER)), "Wrong size on CF_DIBV5 data (!)");
         }
         else // CF_DIB == fetc.cfFormat
         {
-            OSL_ENSURE(sal_uInt32(clipDataStream.getLength()) > (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)), "Wrong size on CF_DIB data (!)");
+            OSL_ENSURE(o3tl::make_unsigned(clipDataStream.getLength()) > (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)), "Wrong size on CF_DIB data (!)");
         }
 #endif
 
diff --git a/extensions/source/ole/unoobjw.cxx b/extensions/source/ole/unoobjw.cxx
index 5a10e03dcbea..b09f0cb19ce6 100644
--- a/extensions/source/ole/unoobjw.cxx
+++ b/extensions/source/ole/unoobjw.cxx
@@ -92,6 +92,7 @@
 #include <comphelper/windowsdebugoutput.hxx>
 #include <comphelper/windowserrorstring.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/safeint.hxx>
 
 #include "comifaces.hxx"
 #include "jscriptclasses.hxx"
@@ -807,7 +808,7 @@ HRESULT STDMETHODCALLTYPE CXTypeInfo::GetFuncDesc(UINT index,
     assert(xClass->getTypeClass() == TypeClass_INTERFACE &&
            aMethods.getLength() > 0);
 
-    if (index > static_cast<UINT>(aMethods.getLength() - 3 + 3 + 4))
+    if (index > o3tl::make_unsigned(aMethods.getLength() - 3 + 3 + 4))
         return E_INVALIDARG;
 
     *ppFuncDesc = new FUNCDESC;
@@ -1904,7 +1905,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP InterfaceOleWrapper::Invoke(DISPID dispidMembe
         if( bHandled)
             return ret;
 
-        if ((dispidMember > 0) && (static_cast<size_t>(dispidMember) <= m_MemberInfos.size()) && m_xInvocation.is())
+        if ((dispidMember > 0) && (o3tl::make_unsigned(dispidMember) <= m_MemberInfos.size()) && m_xInvocation.is())
         {
             MemberInfo d = m_MemberInfos[dispidMember - 1];
             DWORD flags = wFlags & d.flags;
diff --git a/sal/osl/w32/socket.cxx b/sal/osl/w32/socket.cxx
index b0173357c187..52f6738e8205 100644
--- a/sal/osl/w32/socket.cxx
+++ b/sal/osl/w32/socket.cxx
@@ -30,6 +30,7 @@
 #include <rtl/byteseq.h>
 #include <sal/log.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/safeint.hxx>
 #include <comphelper/windowserrorstring.hxx>
 
 #include "sockimpl.hxx"
@@ -641,7 +642,7 @@ oslSocketResult SAL_CALL osl_getLocalHostname (rtl_uString **strLocalHostname)
                             (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
                              | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
                              | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))
-                        && sal_uInt32(u.getLength()) < SAL_N_ELEMENTS(LocalHostname))
+                        && o3tl::make_unsigned(u.getLength()) < SAL_N_ELEMENTS(LocalHostname))
                     {
                         memcpy(LocalHostname, u.getStr(), (u.getLength() + 1) * sizeof (sal_Unicode));
                     }
diff --git a/shell/source/win32/zipfile/zipfile.cxx b/shell/source/win32/zipfile/zipfile.cxx
index 1462c161a900..a1b2b40e628c 100644
--- a/shell/source/win32/zipfile/zipfile.cxx
+++ b/shell/source/win32/zipfile/zipfile.cxx
@@ -29,6 +29,8 @@
 
 #include <string.h>
 
+#include <o3tl/safeint.hxx>
+
 namespace
 {
 
@@ -450,7 +452,7 @@ void ZipFile::GetUncompressedContent(
         return;
     m_pStream->sseek(end.cdir_offset, SEEK_SET);
     CentralDirectoryEntry entry;
-    while (m_pStream->stell() != -1 && static_cast<unsigned long>(m_pStream->stell()) < end.cdir_offset + end.cdir_size)
+    while (m_pStream->stell() != -1 && o3tl::make_unsigned(m_pStream->stell()) < end.cdir_offset + end.cdir_size)
     {
         if (!readCentralDirectoryEntry(m_pStream, entry))
             return;
@@ -522,7 +524,7 @@ ZipFile::DirectoryPtr_t ZipFile::GetDirectory() const
         return dir;
     m_pStream->sseek(end.cdir_offset, SEEK_SET);
     CentralDirectoryEntry entry;
-    while (m_pStream->stell() != -1 && static_cast<unsigned long>(m_pStream->stell()) < end.cdir_offset + end.cdir_size)
+    while (m_pStream->stell() != -1 && o3tl::make_unsigned(m_pStream->stell()) < end.cdir_offset + end.cdir_size)
     {
         if (!readCentralDirectoryEntry(m_pStream, entry))
             return dir;
@@ -559,7 +561,7 @@ long ZipFile::GetFileLongestFileNameLength() const
         return lmax;
     m_pStream->sseek(end.cdir_offset, SEEK_SET);
     CentralDirectoryEntry entry;
-    while (m_pStream->stell() != -1 && static_cast<unsigned long>(m_pStream->stell()) < end.cdir_offset + end.cdir_size)
+    while (m_pStream->stell() != -1 && o3tl::make_unsigned(m_pStream->stell()) < end.cdir_offset + end.cdir_size)
     {
         if (!readCentralDirectoryEntry(m_pStream, entry))
             return lmax;
diff --git a/tools/source/misc/pathutils.cxx b/tools/source/misc/pathutils.cxx
index 28e63ac674a8..706740a320f9 100644
--- a/tools/source/misc/pathutils.cxx
+++ b/tools/source/misc/pathutils.cxx
@@ -21,9 +21,10 @@
 
 #if defined(_WIN32)
 
-#include <cstddef>
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
+
+#include <o3tl/safeint.hxx>
 #include <sal/types.h>
 #include <tools/pathutils.hxx>
 
@@ -79,8 +80,7 @@ WCHAR * buildPath(
         }
     }
     if (backLength <
-        static_cast< std::size_t >(MAX_PATH - (frontEnd - frontBegin)))
-        // hopefully std::size_t is large enough
+        o3tl::make_unsigned(MAX_PATH - (frontEnd - frontBegin)))
     {
         WCHAR * p;
         if (frontBegin == path) {
diff --git a/vcl/win/window/salmenu.cxx b/vcl/win/window/salmenu.cxx
index 3e90600c6670..6f8dc8bff283 100644
--- a/vcl/win/window/salmenu.cxx
+++ b/vcl/win/window/salmenu.cxx
@@ -22,6 +22,7 @@
 #include <vcl/menu.hxx>
 #include <vcl/sysdata.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/safeint.hxx>
 
 #include <win/wincomp.hxx>
 #include <win/saldata.hxx>
@@ -175,7 +176,7 @@ void WinSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos )
 void WinSalMenu::RemoveItem( unsigned nPos )
 {
     int num = ::GetMenuItemCount( mhMenu );
-    if( num != -1 && nPos < static_cast<unsigned>(num) )
+    if( num != -1 && nPos < o3tl::make_unsigned(num) )
     {
         WinSalMenuItem *pSalMenuItem = nullptr;
 
diff --git a/winaccessibility/source/service/AccObject.cxx b/winaccessibility/source/service/AccObject.cxx
index bf71d8617596..f6460522838d 100644
--- a/winaccessibility/source/service/AccObject.cxx
+++ b/winaccessibility/source/service/AccObject.cxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/accessibility/XAccessibleText.hpp>
 
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/safeint.hxx>
 
 #include <stdlib.h>
 #include <memory.h>
@@ -797,7 +798,7 @@ void AccObject::UpdateRole()
     XAccessibleContext* pContext  = m_xAccContextRef.get();
     m_pIMAcc->Put_XAccRole( ROLE_SYSTEM_WINDOW  );
     sal_Int16 iRoleIndex = pContext->getAccessibleRole();
-    if ((0 <= iRoleIndex) && (sal_uInt16(iRoleIndex) < SAL_N_ELEMENTS(ROLE_TABLE)))
+    if ((0 <= iRoleIndex) && (o3tl::make_unsigned(iRoleIndex) < SAL_N_ELEMENTS(ROLE_TABLE)))
     {
         short iIA2Role = ROLE_TABLE[iRoleIndex][1] ;
         m_pIMAcc->Put_XAccRole( iIA2Role  );


More information about the Libreoffice-commits mailing list