From 884db13b711ea0765493e0c68ea92e090b848521 Mon Sep 17 00:00:00 2001 From: Muhammad Naeem Date: Tue, 5 May 2026 01:09:28 +0500 Subject: [PATCH] tdf#147021: Use std::size() instead of SAL_N_ELEMENTS in several modules Verified: make Library_tk Library_lng CppunitTest_sax_xmlimport Library_PresentationMinimizer Executable_xpdfimport Change-Id: I1b7c30fda2b72cdc3fe1cf6bf802f15624aee148 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204771 Tested-by: Jenkins Reviewed-by: Jonathan Clark --- linguistic/source/lngopt.cxx | 3 ++- linguistic/workben/sprophelp.cxx | 3 ++- sax/qa/cppunit/xmlimport.cxx | 3 ++- sdext/source/minimizer/configurationaccess.cxx | 4 ++-- sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx | 4 ++-- toolkit/source/controls/spinningprogress.cxx | 4 +++- ure/source/uretest/cppmain.cc | 5 +++-- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/linguistic/source/lngopt.cxx b/linguistic/source/lngopt.cxx index 3c845b2b9d3d..3873a985b481 100644 --- a/linguistic/source/lngopt.cxx +++ b/linguistic/source/lngopt.cxx @@ -18,6 +18,7 @@ */ +#include #include #include "lngopt.hxx" #include @@ -125,7 +126,7 @@ OUString LinguOptions::GetName( sal_Int32 nWID ) OUString aRes; - if (0 <= nWID && o3tl::make_unsigned(nWID) < SAL_N_ELEMENTS(aWID_Name) + if (0 <= nWID && o3tl::make_unsigned(nWID) < std::size(aWID_Name) && aWID_Name[ nWID ].nWID == nWID) aRes = aWID_Name[nWID].aPropertyName; else diff --git a/linguistic/workben/sprophelp.cxx b/linguistic/workben/sprophelp.cxx index f6326ba55fee..b9f77fe51159 100644 --- a/linguistic/workben/sprophelp.cxx +++ b/linguistic/workben/sprophelp.cxx @@ -18,6 +18,7 @@ */ +#include #include #include "linguistic/misc.hxx" @@ -175,7 +176,7 @@ static const char *aSP[] = PropertyHelper_Spell::PropertyHelper_Spell( const Reference< XInterface > & rxSource, Reference< XPropertySet > &rxPropSet ) : - PropertyChgHelper ( rxSource, rxPropSet, aSP, SAL_N_ELEMENTS(aSP) ) + PropertyChgHelper ( rxSource, rxPropSet, aSP, static_cast(std::size(aSP)) ) { SetDefault(); sal_Int32 nLen = GetPropNames().getLength(); diff --git a/sax/qa/cppunit/xmlimport.cxx b/sax/qa/cppunit/xmlimport.cxx index d71cbb480984..8245f546f3c8 100644 --- a/sax/qa/cppunit/xmlimport.cxx +++ b/sax/qa/cppunit/xmlimport.cxx @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -360,7 +361,7 @@ void XMLImportTest::setUp() uno::UNO_QUERY_THROW); xInit->initialize({ uno::Any(xTokenHandler) }); - sal_Int32 nNamespaceCount = SAL_N_ELEMENTS(DummyTokenHandler::namespaceURIs); + sal_Int32 nNamespaceCount = static_cast(std::size(DummyTokenHandler::namespaceURIs)); uno::Sequence namespaceArgs( nNamespaceCount + 1 ); auto p_namespaceArgs = namespaceArgs.getArray(); p_namespaceArgs[0] <<= u"registerNamespaces"_ustr; diff --git a/sdext/source/minimizer/configurationaccess.cxx b/sdext/source/minimizer/configurationaccess.cxx index 2acab6df88e3..7819a3fe465b 100644 --- a/sdext/source/minimizer/configurationaccess.cxx +++ b/sdext/source/minimizer/configurationaccess.cxx @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -116,7 +116,7 @@ void OptimizerSettings::SaveSettingsToConfiguration( const Reference< XNameRepla // Any( maFilterName ), Any( mbOpenNewDocument ) }; - for ( int i = 0; i < int(SAL_N_ELEMENTS( pNames )); i++ ) + for ( int i = 0; i < static_cast(std::size( pNames )); i++ ) { try { diff --git a/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx b/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx index 6e9784d4aa6b..065b8d78772c 100644 --- a/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx +++ b/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx @@ -18,7 +18,7 @@ */ #include "pnghelper.hxx" -#include +#include #include @@ -119,7 +119,7 @@ void PngHelper::appendFileHeader( OutputBuffer& o_rOutputBuf ) { static const unsigned char aHeader[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; - o_rOutputBuf.insert( o_rOutputBuf.end(), aHeader, aHeader + SAL_N_ELEMENTS(aHeader) ); + o_rOutputBuf.insert( o_rOutputBuf.end(), aHeader, aHeader + std::size(aHeader) ); } size_t PngHelper::startChunk( const char* pChunkName, OutputBuffer& o_rOutputBuf ) diff --git a/toolkit/source/controls/spinningprogress.cxx b/toolkit/source/controls/spinningprogress.cxx index 7d6d37c4ab82..dfe0231bb124 100644 --- a/toolkit/source/controls/spinningprogress.cxx +++ b/toolkit/source/controls/spinningprogress.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include + #include #include #include @@ -62,7 +64,7 @@ protected: { Throbber::ImageSet::N16px, Throbber::ImageSet::N32px, Throbber::ImageSet::N64px }; - for ( size_t i=0; i < SAL_N_ELEMENTS(aImageSets); ++i ) + for ( size_t i=0; i < std::size(aImageSets); ++i ) { const ::std::vector< OUString > aDefaultURLs( Throbber::getDefaultImageURLs( aImageSets[i] ) ); const Sequence< OUString > aImageURLs( aDefaultURLs.data(), aDefaultURLs.size() ); diff --git a/ure/source/uretest/cppmain.cc b/ure/source/uretest/cppmain.cc index fb957d9f221a..15a3187c3d62 100644 --- a/ure/source/uretest/cppmain.cc +++ b/ure/source/uretest/cppmain.cc @@ -20,6 +20,7 @@ #include "sal/macros.h" #include +#include #include #include "com/sun/star/beans/Introspection.hpp" @@ -120,7 +121,7 @@ private: "com.sun.star.script.InvocationAdapterFactory", "com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTscript" }; - for (::std::size_t i = 0; i < SAL_N_ELEMENTS(services); ++i) { + for (::std::size_t i = 0; i < std::size(services); ++i) { ::rtl::OUString name(::rtl::OUString::createFromAscii(services[i])); css::uno::Reference< css::uno::XInterface > instance; try { @@ -165,7 +166,7 @@ private: static char const * const singletons[] = { "com.sun.star.reflection.theTypeDescriptionManager" }; - for (std::size_t i = 0; i != SAL_N_ELEMENTS(singletons); ++i) { + for (std::size_t i = 0; i != std::size(singletons); ++i) { css::uno::Reference< css::uno::XInterface > instance( context_->getValueByName( "/singletons/" + rtl::OUString::createFromAscii(singletons[i])),