try to avoid overflows in some compare functions
Change-Id: I6144d7d6527dc401b7f1b577d1a227361e39e7bb
This commit is contained in:
@@ -197,7 +197,7 @@ short Compare( const OUString &sInput1, const OUString &sInput2,
|
|||||||
if ( nNum1 != nNum2 )
|
if ( nNum1 != nNum2 )
|
||||||
{
|
{
|
||||||
if ( nNum1 < nNum2 ) return -1;
|
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
|
// The prefix and the first numerical elements are equal, but the suffix
|
||||||
|
@@ -350,13 +350,12 @@ void StgEntry::GetName( OUString& rName ) const
|
|||||||
|
|
||||||
// Compare two entries. Do this case-insensitive.
|
// 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 (r.nNameLen != nNameLen)
|
||||||
if( !nRes )
|
return r.nNameLen > nNameLen ? 1 : -1;
|
||||||
nRes = r.aName.compareTo( aName );
|
else
|
||||||
|
return r.aName.compareTo(aName);
|
||||||
return (short)nRes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// These load/store operations are a bit more complicated,
|
// These load/store operations are a bit more complicated,
|
||||||
|
@@ -128,7 +128,7 @@ public:
|
|||||||
bool SetName( const OUString& ); // store a name (ASCII, up to 32 chars)
|
bool SetName( const OUString& ); // store a name (ASCII, up to 32 chars)
|
||||||
void GetName( OUString& rName ) const;
|
void GetName( OUString& rName ) const;
|
||||||
// fill in the name
|
// 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 );
|
bool Load( const void* pBuffer, sal_uInt32 nBufSize );
|
||||||
void Store( void* );
|
void Store( void* );
|
||||||
StgEntryType GetType() const { return (StgEntryType) cType; }
|
StgEntryType GetType() const { return (StgEntryType) cType; }
|
||||||
|
@@ -1286,7 +1286,7 @@ sal_IntPtr SortedResultSet::FindPos( SortListData *pEntry,
|
|||||||
nCompare = Compare( pEntry, pMid );
|
nCompare = Compare( pEntry, pMid );
|
||||||
|
|
||||||
if ( !nCompare )
|
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
|
if ( nCompare < 0 ) // pEntry < pMid
|
||||||
nEnd = nMid - 1;
|
nEnd = nMid - 1;
|
||||||
|
Reference in New Issue
Block a user