diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-09-28 11:01:22 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-09-28 13:08:15 +0200 |
commit | 913ed3e5673c2d70e2c4e519eb65368b0606d7f0 (patch) | |
tree | 5ff32fdd6b94d7b2f1b2a64f9d8ecf04d8e15d02 | |
parent | 6cec8ba33a28de7248861b2eecfc5034cbde9d37 (diff) |
sal_uLong->sal_uInt32 in SwHashTable
Also
(*) increase the number of items this table supports from SAL_MAX_UINT16
to SAL_MAX_UINT32
(*) add some asserts to document and verify the above limit
Change-Id: I53f83303af04a9ac4f3786b221e338a7684fa1ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140700
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sw/inc/calc.hxx | 12 | ||||
-rw-r--r-- | sw/source/core/bastyp/calc.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/doc/DocumentFieldsManager.cxx | 10 | ||||
-rw-r--r-- | sw/source/core/doc/docfld.cxx | 4 |
4 files changed, 17 insertions, 13 deletions
diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx index 2a770dc447cd..f88fe8582f6c 100644 --- a/sw/inc/calc.hxx +++ b/sw/inc/calc.hxx @@ -154,15 +154,19 @@ class SwHashTable { std::vector<std::unique_ptr<T>> m_aData; public: - SwHashTable(size_t nSize) : m_aData(nSize) {} + SwHashTable(size_t nSize) : m_aData(nSize) + { + assert(nSize < SAL_MAX_UINT32); + } std::unique_ptr<T> & operator[](size_t idx) { return m_aData[idx]; } std::unique_ptr<T> const & operator[](size_t idx) const { return m_aData[idx]; } void resize(size_t nSize) { m_aData.resize(nSize); } - T* Find( const OUString& rStr, sal_uInt16* pPos = nullptr ) const + T* Find( const OUString& rStr, sal_uInt32* pPos = nullptr ) const { size_t nTableSize = m_aData.size(); - sal_uLong ii = 0; + assert(nTableSize < SAL_MAX_UINT32); + sal_uInt32 ii = 0; for( sal_Int32 n = 0; n < rStr.getLength(); ++n ) { ii = ii << 1 ^ rStr[n]; @@ -170,7 +174,7 @@ public: ii %= nTableSize; if( pPos ) - *pPos = o3tl::narrowing<sal_uInt16>(ii); + *pPos = ii; for( T* pEntry = m_aData[ii].get(); pEntry; pEntry = static_cast<T*>(pEntry->pNext.get()) ) { diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx index d63ab0231914..592f969bde0b 100644 --- a/sw/source/core/bastyp/calc.cxx +++ b/sw/source/core/bastyp/calc.cxx @@ -429,7 +429,7 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, bool bIns ) { m_aErrExpr.nValue.SetVoidValue(false); - sal_uInt16 ii = 0; + sal_uInt32 ii = 0; OUString aStr = m_pCharClass->lowercase( rStr ); SwCalcExp* pFnd = m_aVarTable.Find(aStr, &ii); @@ -597,7 +597,7 @@ void SwCalc::VarChange( const OUString& rStr, const SwSbxValue& rValue ) { OUString aStr = m_pCharClass->lowercase( rStr ); - sal_uInt16 nPos = 0; + sal_uInt32 nPos = 0; SwCalcExp* pFnd = m_aVarTable.Find( aStr, &nPos ); if( !pFnd ) diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index 334b7edd1580..fc604900a139 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -928,7 +928,7 @@ void DocumentFieldsManager::UpdateExpFieldsImpl( case SwFieldIds::User: { // Entry present? - sal_uInt16 nPos; + sal_uInt32 nPos; const OUString& rNm = pFieldType->GetName(); OUString sExpand(const_cast<SwUserFieldType*>(static_cast<const SwUserFieldType*>(pFieldType))->Expand(nsSwGetSetExpType::GSE_STRING, 0, LANGUAGE_SYSTEM)); SwHash* pFnd = aHashStrTable.Find( rNm, &nPos ); @@ -1110,7 +1110,7 @@ void DocumentFieldsManager::UpdateExpFieldsImpl( // Add entry to hash table // Entry present? - sal_uInt16 nPos; + sal_uInt32 nPos; HashStr* pFnd = aHashStrTable.Find( rName, &nPos ); OUString const value(pField->ExpandField(m_rDoc.IsClipBoard(), nullptr)); if( pFnd ) @@ -1159,7 +1159,7 @@ void DocumentFieldsManager::UpdateExpFieldsImpl( // lookup the field's name aNew = static_cast<SwSetExpFieldType*>(pSField->GetTyp())->GetSetRefName(); // Entry present? - sal_uInt16 nPos; + sal_uInt32 nPos; HashStr* pFnd = aHashStrTable.Find( aNew, &nPos ); if( pFnd ) // Modify entry in the hash table @@ -1659,7 +1659,7 @@ void DocumentFieldsManager::FieldsToExpand( SwHashTable<HashStr> & rHashTable, // look up the field's name aNew = static_cast<SwSetExpFieldType*>(pSField->GetTyp())->GetSetRefName(); // Entry present? - sal_uInt16 nPos; + sal_uInt32 nPos; SwHash* pFnd = rHashTable.Find( aNew, &nPos ); if( pFnd ) // modify entry in the hash table @@ -1676,7 +1676,7 @@ void DocumentFieldsManager::FieldsToExpand( SwHashTable<HashStr> & rHashTable, // Insert entry in the hash table // Entry present? - sal_uInt16 nPos; + sal_uInt32 nPos; HashStr* pFnd = rHashTable.Find( rName, &nPos ); OUString const value(pField->ExpandField(m_rDoc.IsClipBoard(), nullptr)); if( pFnd ) diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx index 03afc4668401..5cae8a66f8ee 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -1187,7 +1187,7 @@ void SwDocUpdateField::InsertFieldType( const SwFieldType& rType ) SetFieldsDirty( true ); // look up and remove from the hash table sFieldName = GetAppCharClass().lowercase( sFieldName ); - sal_uInt16 n; + sal_uInt32 n; SwCalcFieldType* pFnd = GetFieldTypeTable().Find( sFieldName, &n ); @@ -1219,7 +1219,7 @@ void SwDocUpdateField::RemoveFieldType( const SwFieldType& rType ) SetFieldsDirty( true ); // look up and remove from the hash table sFieldName = GetAppCharClass().lowercase( sFieldName ); - sal_uInt16 n; + sal_uInt32 n; SwCalcFieldType* pFnd = GetFieldTypeTable().Find( sFieldName, &n ); if( !pFnd ) |