diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-02-05 23:30:22 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-02-05 23:33:35 +0100 |
commit | 004304eb2fd1703d22dec0abf0170bb2ce493d0c (patch) | |
tree | 2cc68735fa3eb215f043fa6f175f3fcb0e03f88f | |
parent | b0ef5cf258f3a84054c052f0a09a208dbc17fdf3 (diff) |
try to avoid overflows in some compare functions
Change-Id: I6144d7d6527dc401b7f1b577d1a227361e39e7bb
-rw-r--r-- | sc/source/core/data/table3.cxx | 2 | ||||
-rw-r--r-- | sot/source/sdstor/stgelem.cxx | 11 | ||||
-rw-r--r-- | sot/source/sdstor/stgelem.hxx | 2 | ||||
-rw-r--r-- | ucb/source/sorter/sortresult.cxx | 2 |
4 files changed, 8 insertions, 9 deletions
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 61b8059a6e9c..d673583e5554 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -197,7 +197,7 @@ short Compare( const OUString &sInput1, const OUString &sInput2, if ( nNum1 != nNum2 ) { if ( nNum1 < nNum2 ) return -1; - return static_cast<short>( nNum1 > nNum2 ); + return (nNum1 > nNum2) ? 1 : 0; } // The prefix and the first numerical elements are equal, but the suffix diff --git a/sot/source/sdstor/stgelem.cxx b/sot/source/sdstor/stgelem.cxx index 4b29e10c7075..3e1dc9543d4a 100644 --- a/sot/source/sdstor/stgelem.cxx +++ b/sot/source/sdstor/stgelem.cxx @@ -350,13 +350,12 @@ void StgEntry::GetName( OUString& rName ) const // Compare two entries. Do this case-insensitive. -short StgEntry::Compare( const StgEntry& r ) const +sal_Int32 StgEntry::Compare( const StgEntry& r ) const { - sal_Int32 nRes = r.nNameLen - nNameLen; - if( !nRes ) - nRes = r.aName.compareTo( aName ); - - return (short)nRes; + if (r.nNameLen != nNameLen) + return r.nNameLen > nNameLen ? 1 : -1; + else + return r.aName.compareTo(aName); } // These load/store operations are a bit more complicated, diff --git a/sot/source/sdstor/stgelem.hxx b/sot/source/sdstor/stgelem.hxx index b4b386cdebda..c36b5b48b4e7 100644 --- a/sot/source/sdstor/stgelem.hxx +++ b/sot/source/sdstor/stgelem.hxx @@ -128,7 +128,7 @@ public: bool SetName( const OUString& ); // store a name (ASCII, up to 32 chars) void GetName( OUString& rName ) const; // fill in the name - short Compare( const StgEntry& ) const; // compare two entries + sal_Int32 Compare( const StgEntry& ) const; // compare two entries bool Load( const void* pBuffer, sal_uInt32 nBufSize ); void Store( void* ); StgEntryType GetType() const { return (StgEntryType) cType; } diff --git a/ucb/source/sorter/sortresult.cxx b/ucb/source/sorter/sortresult.cxx index d5fcabf5069e..c4cec6ea031f 100644 --- a/ucb/source/sorter/sortresult.cxx +++ b/ucb/source/sorter/sortresult.cxx @@ -1286,7 +1286,7 @@ sal_IntPtr SortedResultSet::FindPos( SortListData *pEntry, nCompare = Compare( pEntry, pMid ); if ( !nCompare ) - nCompare = reinterpret_cast<sal_IntPtr>(pEntry) - reinterpret_cast<sal_IntPtr>(pMid); + nCompare = (pEntry != pMid) ? ((pEntry < pMid) ? -1 : 1) : 0; if ( nCompare < 0 ) // pEntry < pMid nEnd = nMid - 1; |