diff options
Diffstat (limited to 'cppu/source/uno')
-rw-r--r-- | cppu/source/uno/EnvStack.cxx | 27 | ||||
-rw-r--r-- | cppu/source/uno/IdentityMapping.cxx | 7 | ||||
-rw-r--r-- | cppu/source/uno/cascade_mapping.cxx | 17 | ||||
-rw-r--r-- | cppu/source/uno/check.cxx | 84 | ||||
-rw-r--r-- | cppu/source/uno/eq.hxx | 156 | ||||
-rw-r--r-- | cppu/source/uno/lbenv.cxx | 59 | ||||
-rw-r--r-- | cppu/source/uno/lbmap.cxx | 74 | ||||
-rw-r--r-- | cppu/source/uno/sequence.cxx | 16 |
8 files changed, 258 insertions, 182 deletions
diff --git a/cppu/source/uno/EnvStack.cxx b/cppu/source/uno/EnvStack.cxx index 2356948c51c5..7b7df2cefc5a 100644 --- a/cppu/source/uno/EnvStack.cxx +++ b/cppu/source/uno/EnvStack.cxx @@ -25,6 +25,7 @@ #include <osl/thread.h> #include <osl/thread.hxx> +#include <o3tl/string_view.hxx> #include <mutex> #include <unordered_map> @@ -134,35 +135,35 @@ extern "C" void SAL_CALL uno_getCurrentEnvironment(uno_Environment ** ppEnv, rtl } else { - OUString uno_envDcp(UNO_LB_UNO); + OUString uno_envDcp(u"" UNO_LB_UNO ""_ustr); uno_getEnvironment(ppEnv, uno_envDcp.pData, nullptr); } } } -static OUString s_getPrefix(OUString const & str1, OUString const & str2) +static OUString s_getPrefix(std::u16string_view str1, std::u16string_view str2) { sal_Int32 nIndex1 = 0; sal_Int32 nIndex2 = 0; sal_Int32 sim = 0; - OUString token1; - OUString token2; + std::u16string_view token1; + std::u16string_view token2; do { - token1 = str1.getToken(0, ':', nIndex1); - token2 = str2.getToken(0, ':', nIndex2); + token1 = o3tl::getToken(str1, 0, ':', nIndex1); + token2 = o3tl::getToken(str2, 0, ':', nIndex2); if (token1 == token2) - sim += token1.getLength() + 1; + sim += token1.size() + 1; } while(nIndex1 == nIndex2 && nIndex1 >= 0 && token1 == token2); OUString result; if (sim) - result = str1.copy(0, sim - 1); + result = str1.substr(0, sim - 1); return result; } @@ -171,7 +172,7 @@ static int s_getNextEnv(uno_Environment ** ppEnv, uno_Environment * pCurrEnv, un { int res = 0; - OUString nextPurpose; + std::u16string_view nextPurpose; OUString currPurpose; if (pCurrEnv) @@ -185,7 +186,7 @@ static int s_getNextEnv(uno_Environment ** ppEnv, uno_Environment * pCurrEnv, un if (currPurpose.getLength() > intermPurpose.getLength()) { sal_Int32 idx = currPurpose.lastIndexOf(':'); - nextPurpose = currPurpose.copy(0, idx); + nextPurpose = currPurpose.subView(0, idx); res = -1; } @@ -196,14 +197,14 @@ static int s_getNextEnv(uno_Environment ** ppEnv, uno_Environment * pCurrEnv, un nextPurpose = targetPurpose; else - nextPurpose = targetPurpose.copy(0, idx); + nextPurpose = targetPurpose.subView(0, idx); res = 1; } - if (!nextPurpose.isEmpty()) + if (!nextPurpose.empty()) { - OUString next_envDcp = UNO_LB_UNO + nextPurpose; + OUString next_envDcp = OUString::Concat(UNO_LB_UNO) + nextPurpose; uno_getEnvironment(ppEnv, next_envDcp.pData, nullptr); } else diff --git a/cppu/source/uno/IdentityMapping.cxx b/cppu/source/uno/IdentityMapping.cxx index c6dab40cefe8..32ec32c073d3 100644 --- a/cppu/source/uno/IdentityMapping.cxx +++ b/cppu/source/uno/IdentityMapping.cxx @@ -22,6 +22,7 @@ #include <typelib/typedescription.h> #include <uno/mapping.h> #include <uno/environment.hxx> +#include <utility> #include <osl/interlck.h> @@ -35,7 +36,7 @@ struct IdentityMapping : public uno_Mapping sal_Int32 m_nRef; uno::Environment m_env; - explicit IdentityMapping(uno::Environment const & rEnv); + explicit IdentityMapping(uno::Environment aEnv); }; } @@ -86,9 +87,9 @@ static void s_mapInterface(uno_Mapping * pMapping, } -IdentityMapping::IdentityMapping(uno::Environment const & rEnv) +IdentityMapping::IdentityMapping(uno::Environment aEnv) : m_nRef(0), - m_env(rEnv) + m_env(std::move(aEnv)) { uno_Mapping::acquire = s_acquire; uno_Mapping::release = s_release; diff --git a/cppu/source/uno/cascade_mapping.cxx b/cppu/source/uno/cascade_mapping.cxx index e19173bcff4c..17b190032e52 100644 --- a/cppu/source/uno/cascade_mapping.cxx +++ b/cppu/source/uno/cascade_mapping.cxx @@ -23,6 +23,7 @@ #include <uno/lbnames.h> #include <uno/mapping.hxx> #include <uno/dispatcher.h> +#include <o3tl/string_view.hxx> #include <cppu/EnvDcp.hxx> @@ -155,29 +156,29 @@ extern "C" { static void s_MediatorMapping_free(uno_Mapping * pMapping) }} -static OUString getPrefix(OUString const & str1, OUString const & str2) +static OUString getPrefix(std::u16string_view str1, std::u16string_view str2) { sal_Int32 nIndex1 = 0; sal_Int32 nIndex2 = 0; sal_Int32 sim = 0; - OUString token1; - OUString token2; + std::u16string_view token1; + std::u16string_view token2; do { - token1 = str1.getToken(0, ':', nIndex1); - token2 = str2.getToken(0, ':', nIndex2); + token1 = o3tl::getToken(str1, 0, ':', nIndex1); + token2 = o3tl::getToken(str2, 0, ':', nIndex2); if (token1 == token2) - sim += token1.getLength() + 1; + sim += token1.size() + 1; } while(nIndex1 == nIndex2 && nIndex1 >= 0 && token1 == token2); OUString result; if (sim) - result = str1.copy(0, sim - 1); + result = str1.substr(0, sim - 1); return result; } @@ -207,7 +208,7 @@ void getCascadeMapping(uno_Mapping ** ppMapping, if (pAddPurpose && pAddPurpose->length) return; - OUString uno_envType(UNO_LB_UNO); + OUString uno_envType(u"" UNO_LB_UNO ""_ustr); OUString from_envType = cppu::EnvDcp::getTypeName(pFrom->pTypeName); OUString to_envType = cppu::EnvDcp::getTypeName(pTo->pTypeName); diff --git a/cppu/source/uno/check.cxx b/cppu/source/uno/check.cxx index 8e99ff0a35c3..561434aa55f3 100644 --- a/cppu/source/uno/check.cxx +++ b/cppu/source/uno/check.cxx @@ -69,8 +69,11 @@ struct D }; struct E { + // [-loplugin:fakebool] false positive: sal_Bool a; + // [-loplugin:fakebool] false positive: sal_Bool b; + // [-loplugin:fakebool] false positive: sal_Bool c; sal_Int16 d; sal_Int32 e; @@ -142,8 +145,10 @@ enum Enum # pragma pack(pop) #endif +// [-loplugin:fakebool] false positive: static_assert( static_cast<sal_Bool>(true) == sal_True, "must be binary compatible" ); +// [-loplugin:fakebool] false positive: static_assert( static_cast<sal_Bool>(false) == sal_False, "must be binary compatible" ); #if SAL_TYPES_ALIGNMENT8 == 2 @@ -255,11 +260,20 @@ static_assert(sizeof(second) == sizeof(int), "sizeof(second) != sizeof(int)"); struct Char4 { - Char3 chars; +#if defined __GNUC__ && (__GNUC__ < 12 || (__GNUC__ == 12 && __GNUC_MINOR__ < 1)) && !defined __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wattributes" +#endif + [[maybe_unused]] Char3 chars; +#if defined __GNUC__ && (__GNUC__ < 12 || (__GNUC__ == 12 && __GNUC_MINOR__ < 1)) && !defined __clang__ +#pragma GCC diagnostic pop +#endif char c; }; -#define OFFSET_OF( s, m ) reinterpret_cast< size_t >(reinterpret_cast<char *>(&reinterpret_cast<s *>(16)->m) -16) +template<typename T1, typename T2> std::size_t OFFSET_OF(T2 T1::* p) { + return reinterpret_cast< size_t >(reinterpret_cast<char *>(&(reinterpret_cast<T1 *>(16)->*p)) -16); +} class BinaryCompatible_Impl { @@ -268,48 +282,48 @@ public: }; BinaryCompatible_Impl::BinaryCompatible_Impl() { - assert(OFFSET_OF(N, p) == 8); + assert(OFFSET_OF(&N::p) == 8); - assert(OFFSET_OF(C2, n2) == 4); + assert(OFFSET_OF(&C2::n2) == 4); #if SAL_TYPES_ALIGNMENT8 == 2 - assert(OFFSET_OF(C3, d3) == 6); - assert(OFFSET_OF(C3, n3) == 14); - assert(OFFSET_OF(C4, n4) == 18); - assert(OFFSET_OF(C4, d4) == 22); - assert(OFFSET_OF(C5, n5) == 30); - assert(OFFSET_OF(C5, b5) == 38); - assert(OFFSET_OF(C6, c6) == 2); - assert(OFFSET_OF(C6, b6) == 42); - - assert(OFFSET_OF(O2, p2) == 16); + assert(OFFSET_OF(&C3::d3) == 6); + assert(OFFSET_OF(&C3::n3) == 14); + assert(OFFSET_OF(&C4::n4) == 18); + assert(OFFSET_OF(&C4::d4) == 22); + assert(OFFSET_OF(&C5::n5) == 30); + assert(OFFSET_OF(&C5::b5) == 38); + assert(OFFSET_OF(&C6::c6) == 2); + assert(OFFSET_OF(&C6::b6) == 42); + + assert(OFFSET_OF(&O2::p2) == 16); #elif SAL_TYPES_ALIGNMENT8 == 4 - assert(OFFSET_OF(C3, d3) == 8); - assert(OFFSET_OF(C3, n3) == 16); - assert(OFFSET_OF(C4, n4) == 20); - assert(OFFSET_OF(C4, d4) == 24); - assert(OFFSET_OF(C5, n5) == 32); - assert(OFFSET_OF(C5, b5) == 40); - assert(OFFSET_OF(C6, c6) == 4); - assert(OFFSET_OF(C6, b6) == 48); - - assert(OFFSET_OF(O2, p2) == 20); + assert(OFFSET_OF(&C3::d3) == 8); + assert(OFFSET_OF(&C3::n3) == 16); + assert(OFFSET_OF(&C4::n4) == 20); + assert(OFFSET_OF(&C4::d4) == 24); + assert(OFFSET_OF(&C5::n5) == 32); + assert(OFFSET_OF(&C5::b5) == 40); + assert(OFFSET_OF(&C6::c6) == 4); + assert(OFFSET_OF(&C6::b6) == 48); + + assert(OFFSET_OF(&O2::p2) == 20); #elif SAL_TYPES_ALIGNMENT8 == 8 - assert(OFFSET_OF(C3, d3) == 8); - assert(OFFSET_OF(C3, n3) == 16); - assert(OFFSET_OF(C4, n4) == 24); - assert(OFFSET_OF(C4, d4) == 32); - assert(OFFSET_OF(C5, n5) == 40); - assert(OFFSET_OF(C5, b5) == 48); - assert(OFFSET_OF(C6, c6) == 8); - assert(OFFSET_OF(C6, b6) == 64); - - assert(OFFSET_OF(O2, p2) == 24); + assert(OFFSET_OF(&C3::d3) == 8); + assert(OFFSET_OF(&C3::n3) == 16); + assert(OFFSET_OF(&C4::n4) == 24); + assert(OFFSET_OF(&C4::d4) == 32); + assert(OFFSET_OF(&C5::n5) == 40); + assert(OFFSET_OF(&C5::b5) == 48); + assert(OFFSET_OF(&C6::c6) == 8); + assert(OFFSET_OF(&C6::b6) == 64); + + assert(OFFSET_OF(&O2::p2) == 24); #else # error unexpected alignment of 8 byte types #endif - assert(OFFSET_OF(Char4, c) == 3); + assert(OFFSET_OF(&Char4::c) == 3); } BinaryCompatible_Impl aTest; diff --git a/cppu/source/uno/eq.hxx b/cppu/source/uno/eq.hxx index 6287cdcc3506..60a372886776 100644 --- a/cppu/source/uno/eq.hxx +++ b/cppu/source/uno/eq.hxx @@ -21,6 +21,7 @@ #include <cmath> #include <string.h> +#include <o3tl/intcmp.hxx> #include <osl/diagnose.h> #include <rtl/ustring.hxx> @@ -294,20 +295,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return (*static_cast<sal_Int8 *>(pDest) == *static_cast<sal_Int8 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_Int8 *>(pDest), *static_cast<sal_Int8 *>(pSource)); case typelib_TypeClass_SHORT: - return (static_cast<sal_Int16>(*static_cast<sal_Int8 *>(pDest)) == *static_cast<sal_Int16 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_Int8 *>(pDest), *static_cast<sal_Int16 *>(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return (static_cast<sal_Int32>(*static_cast<sal_Int8 *>(pDest)) == static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int8 *>(pDest), *static_cast<sal_uInt16 *>(pSource)); case typelib_TypeClass_LONG: - return (static_cast<sal_Int32>(*static_cast<sal_Int8 *>(pDest)) == *static_cast<sal_Int32 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_Int8 *>(pDest), *static_cast<sal_Int32 *>(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return (static_cast<sal_Int64>(*static_cast<sal_Int8 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int8 *>(pDest), *static_cast<sal_uInt32 *>(pSource)); case typelib_TypeClass_HYPER: - return (static_cast<sal_Int64>(*static_cast<sal_Int8 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_Int8 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return (*static_cast<sal_Int8 *>(pDest) >= 0 && - static_cast<sal_Int64>(*static_cast<sal_Int8 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); // same size + return o3tl::cmp_equal( + *static_cast<sal_Int8 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_FLOAT: return (static_cast<float>(*static_cast<sal_Int8 *>(pDest)) == *static_cast<float *>(pSource)); case typelib_TypeClass_DOUBLE: @@ -319,20 +326,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return (*static_cast<sal_Int16 *>(pDest) == static_cast<sal_Int16>(*static_cast<sal_Int8 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int16 *>(pDest), *static_cast<sal_Int8 *>(pSource)); case typelib_TypeClass_SHORT: - return (*static_cast<sal_Int16 *>(pDest) == *static_cast<sal_Int16 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_Int16 *>(pDest), *static_cast<sal_Int16 *>(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return (static_cast<sal_Int32>(*static_cast<sal_Int16 *>(pDest)) == static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int16 *>(pDest), *static_cast<sal_uInt16 *>(pSource)); case typelib_TypeClass_LONG: - return (static_cast<sal_Int32>(*static_cast<sal_Int16 *>(pDest)) == *static_cast<sal_Int32 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_Int16 *>(pDest), *static_cast<sal_Int32 *>(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return (static_cast<sal_Int64>(*static_cast<sal_Int16 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int16 *>(pDest), *static_cast<sal_uInt32 *>(pSource)); case typelib_TypeClass_HYPER: - return (static_cast<sal_Int64>(*static_cast<sal_Int16 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_Int16 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return (*static_cast<sal_Int16 *>(pDest) >= 0 && - static_cast<sal_Int64>(*static_cast<sal_Int16 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); // same size + return o3tl::cmp_equal( + *static_cast<sal_Int16 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_FLOAT: return (static_cast<float>(*static_cast<sal_Int16 *>(pDest)) == *static_cast<float *>(pSource)); case typelib_TypeClass_DOUBLE: @@ -344,19 +357,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return (static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pDest)) == static_cast<sal_Int32>(*static_cast<sal_Int8 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt16 *>(pDest), *static_cast<sal_Int8 *>(pSource)); case typelib_TypeClass_SHORT: - return (static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pDest)) == static_cast<sal_Int32>(*static_cast<sal_Int16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt16 *>(pDest), *static_cast<sal_Int16 *>(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return (*static_cast<sal_uInt16 *>(pDest) == *static_cast<sal_uInt16 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_uInt16 *>(pDest), *static_cast<sal_uInt16 *>(pSource)); case typelib_TypeClass_LONG: - return (static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pDest)) == *static_cast<sal_Int32 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_uInt16 *>(pDest), *static_cast<sal_Int32 *>(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return (static_cast<sal_uInt32>(*static_cast<sal_uInt16 *>(pDest)) == *static_cast<sal_uInt32 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_uInt16 *>(pDest), *static_cast<sal_uInt32 *>(pSource)); case typelib_TypeClass_HYPER: - return (static_cast<sal_Int64>(*static_cast<sal_uInt16 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_uInt16 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return (static_cast<sal_uInt64>(*static_cast<sal_uInt16 *>(pDest)) == *static_cast<sal_uInt64 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_uInt16 *>(pDest), *static_cast<sal_uInt64 *>(pSource)); case typelib_TypeClass_FLOAT: return (static_cast<float>(*static_cast<sal_uInt16 *>(pDest)) == *static_cast<float *>(pSource)); case typelib_TypeClass_DOUBLE: @@ -368,20 +388,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return (*static_cast<sal_Int32 *>(pDest) == static_cast<sal_Int32>(*static_cast<sal_Int8 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int32 *>(pDest), *static_cast<sal_Int8 *>(pSource)); case typelib_TypeClass_SHORT: - return (*static_cast<sal_Int32 *>(pDest) == static_cast<sal_Int32>(*static_cast<sal_Int16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int32 *>(pDest), *static_cast<sal_Int16 *>(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return (*static_cast<sal_Int32 *>(pDest) == static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int32 *>(pDest), *static_cast<sal_uInt16 *>(pSource)); case typelib_TypeClass_LONG: - return (*static_cast<sal_Int32 *>(pDest) == *static_cast<sal_Int32 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_Int32 *>(pDest), *static_cast<sal_Int32 *>(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return (static_cast<sal_Int64>(*static_cast<sal_Int32 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int32 *>(pDest), *static_cast<sal_uInt32 *>(pSource)); case typelib_TypeClass_HYPER: - return (static_cast<sal_Int64>(*static_cast<sal_Int32 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_Int32 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return (*static_cast<sal_Int32 *>(pDest) >= 0 && - static_cast<sal_Int64>(*static_cast<sal_Int32 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); // same size + return o3tl::cmp_equal( + *static_cast<sal_Int32 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_FLOAT: return (static_cast<float>(*static_cast<sal_Int32 *>(pDest)) == *static_cast<float *>(pSource)); case typelib_TypeClass_DOUBLE: @@ -393,19 +419,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return (static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_Int8 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt32 *>(pDest), *static_cast<sal_Int8 *>(pSource)); case typelib_TypeClass_SHORT: - return (static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_Int16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt32 *>(pDest), *static_cast<sal_Int16 *>(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return (*static_cast<sal_uInt32 *>(pDest) == static_cast<sal_uInt32>(*static_cast<sal_uInt16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt32 *>(pDest), *static_cast<sal_uInt16 *>(pSource)); case typelib_TypeClass_LONG: - return (static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_Int32 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt32 *>(pDest), *static_cast<sal_Int32 *>(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return (*static_cast<sal_uInt32 *>(pDest) == *static_cast<sal_uInt32 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_uInt32 *>(pDest), *static_cast<sal_uInt32 *>(pSource)); case typelib_TypeClass_HYPER: - return (static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_uInt32 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return (static_cast<sal_uInt64>(*static_cast<sal_uInt32 *>(pDest)) == *static_cast<sal_uInt64 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_uInt32 *>(pDest), *static_cast<sal_uInt64 *>(pSource)); case typelib_TypeClass_FLOAT: return (static_cast<float>(*static_cast<sal_uInt32 *>(pDest)) == *static_cast<float *>(pSource)); case typelib_TypeClass_DOUBLE: @@ -417,20 +450,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return (*static_cast<sal_Int64 *>(pDest) == static_cast<sal_Int64>(*static_cast<sal_Int8 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int64 *>(pDest), *static_cast<sal_Int8 *>(pSource)); case typelib_TypeClass_SHORT: - return (*static_cast<sal_Int64 *>(pDest) == static_cast<sal_Int64>(*static_cast<sal_Int16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int64 *>(pDest), *static_cast<sal_Int16 *>(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return (*static_cast<sal_Int64 *>(pDest) == static_cast<sal_Int64>(*static_cast<sal_uInt16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int64 *>(pDest), *static_cast<sal_uInt16 *>(pSource)); case typelib_TypeClass_LONG: - return (*static_cast<sal_Int64 *>(pDest) == static_cast<sal_Int64>(*static_cast<sal_Int32 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int64 *>(pDest), *static_cast<sal_Int32 *>(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return (*static_cast<sal_Int64 *>(pDest) == static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_Int64 *>(pDest), *static_cast<sal_uInt32 *>(pSource)); case typelib_TypeClass_HYPER: - return (*static_cast<sal_Int64 *>(pDest) == *static_cast<sal_Int64 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_Int64 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return (*static_cast<sal_Int64 *>(pDest) >= 0 && - *static_cast<sal_Int64 *>(pDest) == *static_cast<sal_Int64 *>(pSource)); // same size + return o3tl::cmp_equal( + *static_cast<sal_Int64 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_FLOAT: return (static_cast<float>(*static_cast<sal_Int64 *>(pDest)) == *static_cast<float *>(pSource)); case typelib_TypeClass_DOUBLE: @@ -442,23 +481,26 @@ inline bool _equalData( switch (eSourceTypeClass) { case typelib_TypeClass_BYTE: - return (*static_cast<sal_Int8 *>(pSource) >= 0 && - *static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_Int8 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt64 *>(pDest), *static_cast<sal_Int8 *>(pSource)); case typelib_TypeClass_SHORT: - return (*static_cast<sal_Int16 *>(pSource) >= 0 && - *static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_Int16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt64 *>(pDest), *static_cast<sal_Int16 *>(pSource)); case typelib_TypeClass_UNSIGNED_SHORT: - return (*static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_uInt16 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt64 *>(pDest), *static_cast<sal_uInt16 *>(pSource)); case typelib_TypeClass_LONG: - return (*static_cast<sal_Int32 *>(pSource) >= 0 && - *static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_Int32 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt64 *>(pDest), *static_cast<sal_Int32 *>(pSource)); case typelib_TypeClass_UNSIGNED_LONG: - return (*static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_uInt32 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt64 *>(pDest), *static_cast<sal_uInt32 *>(pSource)); case typelib_TypeClass_HYPER: - return (*static_cast<sal_Int64 *>(pSource) >= 0 && - *static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_Int64 *>(pSource))); + return o3tl::cmp_equal( + *static_cast<sal_uInt64 *>(pDest), *static_cast<sal_Int64 *>(pSource)); case typelib_TypeClass_UNSIGNED_HYPER: - return (*static_cast<sal_uInt64 *>(pDest) == *static_cast<sal_uInt64 *>(pSource)); + return o3tl::cmp_equal( + *static_cast<sal_uInt64 *>(pDest), *static_cast<sal_uInt64 *>(pSource)); case typelib_TypeClass_FLOAT: if (::floor( *static_cast<float *>(pSource) ) != *static_cast<float *>(pSource) || *static_cast<float *>(pSource) < 0) return false; diff --git a/cppu/source/uno/lbenv.cxx b/cppu/source/uno/lbenv.cxx index f19d8e725e4f..d9b37b083e02 100644 --- a/cppu/source/uno/lbenv.cxx +++ b/cppu/source/uno/lbenv.cxx @@ -42,6 +42,7 @@ #include <string_view> #include <unordered_map> +#include <utility> #include <vector> #include <stdio.h> @@ -78,7 +79,7 @@ struct ObjectEntry sal_Int32 nRef; bool mixedObject; - explicit ObjectEntry( const OUString & rOId_ ); + explicit ObjectEntry( OUString aOId_ ); void append( uno_DefaultEnvironment * pEnv, @@ -147,8 +148,8 @@ struct uno_DefaultEnvironment : public uno_ExtEnvironment }; -ObjectEntry::ObjectEntry( OUString const & rOId_ ) - : oid( rOId_ ), +ObjectEntry::ObjectEntry( OUString aOId_ ) + : oid(std::move( aOId_ )), nRef( 0 ), mixedObject( false ) { @@ -345,7 +346,7 @@ static void s_stub_defenv_revokeInterface(va_list * pParam) Ptr2ObjectMap::const_iterator const iFind( that->aPtr2ObjectMap.find( pInterface ) ); - OSL_ASSERT( iFind != that->aPtr2ObjectMap.end() ); + assert(iFind != that->aPtr2ObjectMap.end()); ObjectEntry * pOEntry = iFind->second; if (! --pOEntry->nRef) { @@ -696,18 +697,18 @@ extern "C" void SAL_CALL uno_dumpEnvironment( { writeLine( stream, "###################################" "###########################################", pFilter ); - buf.append( "environment: " ); - buf.append( pEnv->pTypeName ); - writeLine( stream, buf.makeStringAndClear(), pFilter ); + buf.append( OUString::Concat("environment: ") + OUString::unacquired(&pEnv->pTypeName) ); + writeLine( stream, buf, pFilter ); + buf.setLength(0); writeLine( stream, "NO INTERFACE INFORMATION AVAILABLE!", pFilter ); return; } writeLine( stream, "########################################" "######################################", pFilter ); - buf.append( "environment dump: " ); - buf.append( pEnv->pTypeName ); - writeLine( stream, buf.makeStringAndClear(), pFilter ); + buf.append( OUString::Concat("environment dump: ") + OUString::unacquired(&pEnv->pTypeName) ); + writeLine( stream, buf, pFilter ); + buf.setLength(0); uno_DefaultEnvironment * that = reinterpret_cast< uno_DefaultEnvironment * >(pEnv); @@ -721,33 +722,32 @@ extern "C" void SAL_CALL uno_dumpEnvironment( buf.append( "+ " ); if (pOEntry->mixedObject) buf.append( "mixed " ); - buf.append( "object entry: nRef=" ); - buf.append( pOEntry->nRef ); - buf.append( "; oid=\"" ); - buf.append( pOEntry->oid ); - buf.append( '\"' ); - writeLine( stream, buf.makeStringAndClear(), pFilter ); + buf.append( "object entry: nRef=" + + OUString::number(pOEntry->nRef) + + "; oid=\"" + + pOEntry->oid + + "\"" ); + writeLine( stream, buf, pFilter ); + buf.setLength(0); for ( std::size_t nPos = 0; nPos < pOEntry->aInterfaces.size(); ++nPos ) { const InterfaceEntry & rIEntry = pOEntry->aInterfaces[nPos]; - buf.append( " - " ); - buf.append( rIEntry.pTypeDescr->aBase.pTypeName ); + buf.append( OUString::Concat(" - ") + + OUString::unacquired(&rIEntry.pTypeDescr->aBase.pTypeName) ); if (rIEntry.fpFreeProxy) { - buf.append( "; proxy free=0x" ); - buf.append( - reinterpret_cast< sal_IntPtr >(rIEntry.fpFreeProxy), 16 ); + buf.append( "; proxy free=0x" + + OUString::number( reinterpret_cast< sal_IntPtr >(rIEntry.fpFreeProxy), 16 ) ); } else { buf.append( "; original" ); } - buf.append( "; ptr=0x" ); - buf.append( - reinterpret_cast< sal_IntPtr >(rIEntry.pInterface), 16 ); + buf.append( "; ptr=0x" + + OUString::number(reinterpret_cast< sal_IntPtr >(rIEntry.pInterface), 16 ) ); if (pOEntry->find( rIEntry.pInterface, nPos + 1 ) < 0) { @@ -757,7 +757,8 @@ extern "C" void SAL_CALL uno_dumpEnvironment( buf.append( " (ptr not found in map!)" ); } } - writeLine( stream, buf.makeStringAndClear(), pFilter ); + writeLine( stream, buf, pFilter ); + buf.setLength(0); } } if (! ptr2obj.empty()) @@ -782,7 +783,7 @@ extern "C" void SAL_CALL uno_dumpEnvironmentByName( { writeLine( stream, - OUStringConcatenation("environment \"" + OUString::unacquired(&pEnvDcp) + "\" does not exist!"), + Concat2View("environment \"" + OUString::unacquired(&pEnvDcp) + "\" does not exist!"), pFilter ); } } @@ -845,10 +846,10 @@ static void unoenv_computeObjectIdentifier( (*pUnoI->release)( pUnoI ); OUString aStr( // interface - OUString::number( reinterpret_cast< sal_Int64 >(pUnoI), 16 ) + ";" + OUString::number( reinterpret_cast< sal_IntPtr >(pUnoI), 16 ) + ";" // environment[context] + OUString::unacquired(&pEnv->aBase.pTypeName) + "[" - + OUString::number( reinterpret_cast< sal_Int64 >( + + OUString::number( reinterpret_cast< sal_IntPtr >( reinterpret_cast< uno_Environment * >(pEnv)->pContext ), 16 ) // process;good guid @@ -1031,7 +1032,7 @@ bool loadEnv(OUString const & cLibStem, } - uno_initEnvironmentFunc fpInit = reinterpret_cast<uno_initEnvironmentFunc>(aMod.getSymbol(UNO_INIT_ENVIRONMENT)); + uno_initEnvironmentFunc fpInit = reinterpret_cast<uno_initEnvironmentFunc>(aMod.getSymbol(u"" UNO_INIT_ENVIRONMENT ""_ustr)); if (!fpInit) return false; diff --git a/cppu/source/uno/lbmap.cxx b/cppu/source/uno/lbmap.cxx index 43818eb85025..aea90a7eb760 100644 --- a/cppu/source/uno/lbmap.cxx +++ b/cppu/source/uno/lbmap.cxx @@ -27,6 +27,7 @@ #include <mutex> #include <set> #include <unordered_map> +#include <utility> #include <rtl/ustring.hxx> #include <rtl/ustrbuf.hxx> @@ -125,11 +126,11 @@ struct MappingEntry MappingEntry( uno_Mapping * pMapping_, uno_freeMappingFunc freeMapping_, - const OUString & rMappingName_ ) + OUString aMappingName_ ) : nRef( 1 ) , pMapping( pMapping_ ) , freeMapping( freeMapping_ ) - , aMappingName( rMappingName_ ) + , aMappingName(std::move( aMappingName_ )) {} }; @@ -154,7 +155,7 @@ struct MappingsData t_OUString2Entry aName2Entry; t_Mapping2Entry aMapping2Entry; - Mutex aCallbacksMutex; + std::mutex aCallbacksMutex; std::set< uno_getMappingFunc > aCallbacks; @@ -192,9 +193,9 @@ struct uno_Mediate_Mapping : public uno_Mapping OUString aAddPurpose; uno_Mediate_Mapping( - const Environment & rFrom_, const Environment & rTo_, - const Mapping & rFrom2Uno_, const Mapping & rUno2To_, - const OUString & rAddPurpose ); + Environment aFrom_, Environment aTo_, + Mapping aFrom2Uno_, Mapping aUno2To_, + OUString aAddPurpose ); }; } @@ -265,15 +266,15 @@ static void mediate_mapInterface( } uno_Mediate_Mapping::uno_Mediate_Mapping( - const Environment & rFrom_, const Environment & rTo_, - const Mapping & rFrom2Uno_, const Mapping & rUno2To_, - const OUString & rAddPurpose_ ) + Environment aFrom_, Environment aTo_, + Mapping aFrom2Uno_, Mapping aUno2To_, + OUString aAddPurpose_ ) : nRef( 1 ) - , aFrom( rFrom_ ) - , aTo( rTo_ ) - , aFrom2Uno( rFrom2Uno_ ) - , aUno2To( rUno2To_ ) - , aAddPurpose( rAddPurpose_ ) + , aFrom(std::move( aFrom_ )) + , aTo(std::move( aTo_ )) + , aFrom2Uno(std::move( aFrom2Uno_ )) + , aUno2To(std::move( aUno2To_ )) + , aAddPurpose(std::move( aAddPurpose_ )) { uno_Mapping::acquire = mediate_acquire; uno_Mapping::release = mediate_release; @@ -284,18 +285,17 @@ uno_Mediate_Mapping::uno_Mediate_Mapping( static OUString getMappingName( const Environment & rFrom, const Environment & rTo, std::u16string_view rAddPurpose ) { - OUStringBuffer aKey( 64 ); - aKey.append( rAddPurpose ); - aKey.append( ';' ); - aKey.append( rFrom.getTypeName() ); - aKey.append( '[' ); - aKey.append( reinterpret_cast< sal_IntPtr >(rFrom.get()), 16 ); - aKey.append( "];" ); - aKey.append( rTo.getTypeName() ); - aKey.append( '[' ); - aKey.append( reinterpret_cast< sal_IntPtr >(rTo.get()), 16 ); - aKey.append( ']' ); - return aKey.makeStringAndClear(); + return + OUString::Concat(rAddPurpose) + + ";" + + rFrom.getTypeName() + + "[" + + OUString::number( reinterpret_cast< sal_IntPtr >(rFrom.get()), 16 ) + + "];" + + rTo.getTypeName() + + "[" + + OUString::number( reinterpret_cast< sal_IntPtr >(rTo.get()), 16 ) + + "]"; } static OUString getBridgeName( @@ -304,12 +304,12 @@ static OUString getBridgeName( OUStringBuffer aBridgeName( 16 ); if (!rAddPurpose.empty()) { - aBridgeName.append( rAddPurpose ); - aBridgeName.append( '_' ); + aBridgeName.append( OUString::Concat(rAddPurpose) + "_" ); } - aBridgeName.append( EnvDcp::getTypeName(rFrom.getTypeName()) ); - aBridgeName.append( '_' ); - aBridgeName.append( EnvDcp::getTypeName(rTo.getTypeName()) ); + aBridgeName.append( + EnvDcp::getTypeName(rFrom.getTypeName()) + + "_" + + EnvDcp::getTypeName(rTo.getTypeName()) ); return aBridgeName.makeStringAndClear(); } @@ -448,7 +448,7 @@ static Mapping loadExternalMapping( if (bModule) { uno_ext_getMappingFunc fpGetMapFunc = - reinterpret_cast<uno_ext_getMappingFunc>(aModule.getSymbol( UNO_EXT_GETMAPPING )); + reinterpret_cast<uno_ext_getMappingFunc>(aModule.getSymbol( u"" UNO_EXT_GETMAPPING ""_ustr )); if (fpGetMapFunc) { @@ -518,7 +518,7 @@ static Mapping getMediateMapping( // backwards: from dest to source of mapping chain // connect to uno - OUString aUnoEnvTypeName( UNO_LB_UNO ); + OUString aUnoEnvTypeName( u"" UNO_LB_UNO ""_ustr ); if (rTo.getTypeName() == aUnoEnvTypeName) // to is uno { aUno = rTo; @@ -621,7 +621,7 @@ void SAL_CALL uno_getMapping( // try callback chain { - MutexGuard aGuard(rData.aCallbacksMutex); + std::unique_lock aGuard(rData.aCallbacksMutex); for (const auto& rCallback : rData.aCallbacks) { (*rCallback)(ppMapping, pFrom, pTo, aAddPurpose.pData); @@ -715,7 +715,7 @@ void SAL_CALL uno_revokeMapping( ClearableMutexGuard aGuard( rData.aMappingsMutex ); const t_Mapping2Entry::const_iterator iFind( rData.aMapping2Entry.find( pMapping ) ); - OSL_ASSERT( iFind != rData.aMapping2Entry.end() ); + assert(iFind != rData.aMapping2Entry.end() && "pMapping must be registered to be removed"); MappingEntry * pEntry = (*iFind).second; if (! --pEntry->nRef) { @@ -735,7 +735,7 @@ void SAL_CALL uno_registerMappingCallback( { OSL_ENSURE( pCallback, "### null ptr!" ); MappingsData & rData = getMappingsData(); - MutexGuard aGuard( rData.aCallbacksMutex ); + std::unique_lock aGuard( rData.aCallbacksMutex ); rData.aCallbacks.insert( pCallback ); } @@ -745,7 +745,7 @@ void SAL_CALL uno_revokeMappingCallback( { OSL_ENSURE( pCallback, "### null ptr!" ); MappingsData & rData = getMappingsData(); - MutexGuard aGuard( rData.aCallbacksMutex ); + std::unique_lock aGuard( rData.aCallbacksMutex ); rData.aCallbacks.erase( pCallback ); } } // extern "C" diff --git a/cppu/source/uno/sequence.cxx b/cppu/source/uno/sequence.cxx index c467f2c38704..2d8b1da19f84 100644 --- a/cppu/source/uno/sequence.cxx +++ b/cppu/source/uno/sequence.cxx @@ -20,6 +20,7 @@ #include <sal/config.h> #include <cassert> +#include <cstdlib> #include <string.h> #include <osl/diagnose.h> @@ -227,6 +228,9 @@ static bool idefaultConstructElements( { typelib_TypeDescription * pElementTypeDescr = nullptr; TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + if (pElementTypeDescr == nullptr) { + std::abort(); + } sal_Int32 eEnum = reinterpret_cast<typelib_EnumTypeDescription *>( pElementTypeDescr)->nDefaultEnumValue; @@ -245,6 +249,9 @@ static bool idefaultConstructElements( { typelib_TypeDescription * pElementTypeDescr = nullptr; TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + if (pElementTypeDescr == nullptr) { + std::abort(); + } sal_Int32 nElementSize = pElementTypeDescr->nSize; if (nAlloc >= 0) @@ -471,6 +478,9 @@ static bool icopyConstructFromElements( { typelib_TypeDescription * pElementTypeDescr = nullptr; TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + if (pElementTypeDescr == nullptr) { + std::abort(); + } sal_Int32 nElementSize = pElementTypeDescr->nSize; pSeq = reallocSeq( pSeq, nElementSize, nAlloc ); @@ -522,6 +532,9 @@ static bool icopyConstructFromElements( { typelib_TypeDescription * pElementTypeDescr = nullptr; TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType ); + if (pElementTypeDescr == nullptr) { + std::abort(); + } typelib_TypeDescriptionReference * pSeqElementType = reinterpret_cast<typelib_IndirectTypeDescription *>(pElementTypeDescr)->pType; uno_Sequence ** pDestElements = reinterpret_cast<uno_Sequence **>(pSeq->elements); @@ -664,6 +677,9 @@ sal_Bool SAL_CALL uno_type_sequence_construct( { typelib_TypeDescription * pTypeDescr = nullptr; TYPELIB_DANGER_GET( &pTypeDescr, pType ); + if (pTypeDescr == nullptr) { + std::abort(); + } typelib_TypeDescriptionReference * pElementType = reinterpret_cast<typelib_IndirectTypeDescription *>(pTypeDescr)->pType; |