From 2a20616d09709427e8cf2474d4721836bce66b8e Mon Sep 17 00:00:00 2001 From: varshneydevansh Date: Wed, 26 Mar 2025 14:33:08 +0530 Subject: Move Windows error helpers to comphelper namespace Previously, WindowsErrorString and WindowsErrorStringFromHRESULT were defined in an anonymous namespace in windowserrorstring.hxx, which: 1. Made them unavailable to other translation units 2. Violate ODR by creating separate copies in each TU 3. Require workarounds to access them Changes: - Move functions to proper comphelper namespace - Keep implementations inline as they're simple utilities - Preserve all existing functionality - Update all call sites to use comphelper:: prefix This change enables proper use of these utilities across LibreOffice while maintaining current behavior and performance characteristics. Introduced in this commit: commit 94cdcaa4d8db8f03ac9a84dac54357efff3eb123 Author: Tor Lillqvist Date: Thu Aug 13 13:22:28 2015 +0300 Add a globally usable WindowsErrorString function Change-Id: I34df1c2b1f30c6204f107ca4792131d692203880 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183332 Reviewed-by: Mike Kaganski Tested-by: Jenkins --- xmlsecurity/source/xmlsec/errorcallback.cxx | 2 +- .../source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx | 2 +- xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'xmlsecurity/source/xmlsec') diff --git a/xmlsecurity/source/xmlsec/errorcallback.cxx b/xmlsecurity/source/xmlsec/errorcallback.cxx index a2c429462e81..7f45413657e4 100644 --- a/xmlsecurity/source/xmlsec/errorcallback.cxx +++ b/xmlsecurity/source/xmlsec/errorcallback.cxx @@ -48,7 +48,7 @@ static void errorCallback(const char* file, OUString systemErrorString; #ifdef _WIN32 - systemErrorString = " " + WindowsErrorString(GetLastError()); + systemErrorString = " " + comphelper::WindowsErrorString(GetLastError()); #endif SAL_WARN("xmlsecurity.xmlsec", file << ":" << line << ": " << func << "() '" << pErrorObject << "' '" << pErrorSubject << "' " << reason << " '" << pMsg << "'" << systemErrorString); diff --git a/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx index a6258f92ad76..8f5b46ad09ce 100644 --- a/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx +++ b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx @@ -283,7 +283,7 @@ static BOOL WINAPI cert_enum_system_store_callback(const void *pvSystemStore, if (!(ERROR_FILE_NOT_FOUND == dwErr || ERROR_NOT_SUPPORTED == dwErr)) { - SAL_WARN("xmlsecurity.xmlsec", "CertEnumPhysicalStore failed:" << WindowsErrorString(GetLastError())); + SAL_WARN("xmlsecurity.xmlsec", "CertEnumPhysicalStore failed:" << comphelper::WindowsErrorString(GetLastError())); } } return TRUE; diff --git a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx index bd4ef701e6ed..05881195312e 100644 --- a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx +++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx @@ -612,7 +612,7 @@ sal_Int32 SAL_CALL X509Certificate_MSCryptImpl::getCertificateUsage( ) &length); if (!rc) - SAL_WARN("xmlsecurity.xmlsec", "CryptDecodeObject failed: " << WindowsErrorString(GetLastError())); + SAL_WARN("xmlsecurity.xmlsec", "CryptDecodeObject failed: " << comphelper::WindowsErrorString(GetLastError())); else { std::vectorbuffer(length); @@ -628,7 +628,7 @@ sal_Int32 SAL_CALL X509Certificate_MSCryptImpl::getCertificateUsage( ) CRYPT_BIT_BLOB *blob = reinterpret_cast(buffer.data()); if (!rc) - SAL_WARN("xmlsecurity.xmlsec", "CryptDecodeObject failed: " << WindowsErrorString(GetLastError())); + SAL_WARN("xmlsecurity.xmlsec", "CryptDecodeObject failed: " << comphelper::WindowsErrorString(GetLastError())); else if (blob->cbData == 1) usage = blob->pbData[0]; else @@ -727,7 +727,7 @@ static bool EncodeDistinguishedName(std::u16string_view const rName, CERT_NAME_B reinterpret_cast(rName.data()), CERT_X500_NAME_STR, nullptr, nullptr, &rBlob.cbData, &pszError)) { - SAL_INFO("xmlsecurity.xmlsec", "CertStrToNameW failed: " << WindowsErrorString(GetLastError()) << "; " << OUString(o3tl::toU(pszError))); + SAL_INFO("xmlsecurity.xmlsec", "CertStrToNameW failed: " << comphelper::WindowsErrorString(GetLastError()) << "; " << OUString(o3tl::toU(pszError))); return false; } rBlob.pbData = new BYTE[rBlob.cbData]; @@ -735,7 +735,7 @@ static bool EncodeDistinguishedName(std::u16string_view const rName, CERT_NAME_B reinterpret_cast(rName.data()), CERT_X500_NAME_STR, nullptr, rBlob.pbData, &rBlob.cbData, &pszError)) { - SAL_INFO("xmlsecurity.xmlsec", "CertStrToNameW failed: " << WindowsErrorString(GetLastError()) << "; " << OUString(o3tl::toU(pszError))); + SAL_INFO("xmlsecurity.xmlsec", "CertStrToNameW failed: " << comphelper::WindowsErrorString(GetLastError()) << "; " << OUString(o3tl::toU(pszError))); return false; } return true; -- cgit