editeng/inc/TextPortion.hxx                |    3 ++-
 editeng/source/editeng/impedit.hxx         |    3 ++-
 extensions/source/scanner/grid.cxx         |    4 ++--
 sc/source/filter/inc/XclExpChangeTrack.hxx |    4 +++-
 vcl/source/edit/textdata.cxx               |    3 ++-
 vcl/source/window/commandevent.cxx         |    5 +++--
 vcl/source/window/winproc.cxx              |    4 +++-
 7 files changed, 17 insertions(+), 9 deletions(-)

New commits:
commit 629dab07c8b9a5d3717211db5b0126333f2b9873
Author:     Sergey Anisimov <[email protected]>
AuthorDate: Fri Oct 10 17:34:20 2025 +0300
Commit:     Hossein <[email protected]>
CommitDate: Tue Oct 28 14:34:44 2025 +0100

    tdf#163691 - Use std::copy_n() instead of memcpy()
    
    Change-Id: I5ffd3ea19eda9038620c7a0e07d074ceb928af1b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192172
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/editeng/inc/TextPortion.hxx b/editeng/inc/TextPortion.hxx
index 805d3cbdd6f7..bd4d8dffd68a 100644
--- a/editeng/inc/TextPortion.hxx
+++ b/editeng/inc/TextPortion.hxx
@@ -24,6 +24,7 @@
 #include <tools/long.hxx>
 #include <o3tl/typed_flags_set.hxx>
 
+#include <algorithm>
 #include <string.h>
 #include <memory>
 #include <utility>
@@ -74,7 +75,7 @@ struct ExtraPortionInfo
         if (pDXArray)
         {
             pOrgDXArray.reset(new double[nLen]);
-            memcpy(pOrgDXArray.get(), pDXArray, nLen * sizeof(double));
+            std::copy_n(pDXArray, nLen, pOrgDXArray.get());
         }
         else
             pOrgDXArray.reset();
diff --git a/editeng/source/editeng/impedit.hxx 
b/editeng/source/editeng/impedit.hxx
index 606f02e6b641..338145db8973 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -58,6 +58,7 @@
 #include <o3tl/deleter.hxx>
 #include <o3tl/typed_flags_set.hxx>
 
+#include <algorithm>
 #include <functional>
 #include <optional>
 #include <memory>
@@ -139,7 +140,7 @@ struct ImplIMEInfos
     {
         nLen = nInputLength;
         pAttribs.reset(new ExtTextInputAttr[nInputLength]);
-        memcpy(pAttribs.get(), pInputAttributes, nInputLength * 
sizeof(ExtTextInputAttr));
+        std::copy_n(pInputAttributes, nInputLength, pAttribs.get());
     }
 
     void DestroyAttribs()
diff --git a/extensions/source/scanner/grid.cxx 
b/extensions/source/scanner/grid.cxx
index d5d47c167378..4bf20dd57da4 100644
--- a/extensions/source/scanner/grid.cxx
+++ b/extensions/source/scanner/grid.cxx
@@ -171,7 +171,7 @@ void GridWindow::Init(double* pXValues, double* pYValues, 
int nValues, bool bCut
     if (m_pOrigYValues && m_nValues)
     {
         m_pNewYValues.reset(new double[ m_nValues ]);
-        memcpy( m_pNewYValues.get(), m_pOrigYValues, sizeof( double ) * 
m_nValues );
+        std::copy_n(m_pOrigYValues, m_nValues, m_pNewYValues.get());
     }
 
     setBoundings( 0, 0, 1023, 1023 );
@@ -640,7 +640,7 @@ void GridWindow::ChangeMode(ResetType nType)
         case ResetType::RESET:
         {
             if( m_pOrigYValues && m_pNewYValues && m_nValues )
-                memcpy( m_pNewYValues.get(), m_pOrigYValues, 
m_nValues*sizeof(double) );
+                std::copy_n(m_pOrigYValues, m_nValues, m_pNewYValues.get());
         }
         break;
         case ResetType::EXPONENTIAL:
diff --git a/sc/source/filter/inc/XclExpChangeTrack.hxx 
b/sc/source/filter/inc/XclExpChangeTrack.hxx
index 746125e50ab1..b9ffcd6b2376 100644
--- a/sc/source/filter/inc/XclExpChangeTrack.hxx
+++ b/sc/source/filter/inc/XclExpChangeTrack.hxx
@@ -19,8 +19,10 @@
 
 #pragma once
 
+#include <algorithm>
 #include <memory>
 #include <stack>
+
 #include <tools/datetime.hxx>
 #include <unotools/securityoptions.hxx>
 #include <chgtrack.hxx>
@@ -316,7 +318,7 @@ public:
     sal_uInt16           GetBufferCount() const
                                     { return static_cast< sal_uInt16 >( (pLast 
- pBuffer.get()) + 1 ); }
     void                 GetBufferCopy( sal_uInt16* pDest ) const
-                                    { memcpy( pDest, pBuffer.get(), 
sizeof(sal_uInt16) * GetBufferCount() ); }
+                                    { std::copy_n( pBuffer.get(), 
GetBufferCount(), pDest ); }
 };
 
 // XclExpChTrTabId - tab id record
diff --git a/vcl/source/edit/textdata.cxx b/vcl/source/edit/textdata.cxx
index 7cee5a566612..af2724860479 100644
--- a/vcl/source/edit/textdata.cxx
+++ b/vcl/source/edit/textdata.cxx
@@ -21,6 +21,7 @@
 #include <sal/log.hxx>
 #include <osl/diagnose.h>
 
+#include <algorithm>
 #include <cstddef>
 
 #include <utility>
@@ -293,7 +294,7 @@ void TEIMEInfos::CopyAttribs(const ExtTextInputAttr* pA, 
sal_Int32 nL)
 {
     nLen = nL;
     pAttribs.reset( new ExtTextInputAttr[ nL ] );
-    memcpy( pAttribs.get(), pA, nL*sizeof(ExtTextInputAttr) );
+    std::copy_n(pA, nL, pAttribs.get());
 }
 
 void TEIMEInfos::DestroyAttribs()
diff --git a/vcl/source/window/commandevent.cxx 
b/vcl/source/window/commandevent.cxx
index 83c21826e7c3..7a32d56991ea 100644
--- a/vcl/source/window/commandevent.cxx
+++ b/vcl/source/window/commandevent.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <algorithm>
 #include <string.h>
 
 #include <utility>
@@ -30,7 +31,7 @@ CommandExtTextInputData::CommandExtTextInputData( OUString 
aText,
     if ( pTextAttr && !maText.isEmpty() )
     {
         mpTextAttr.reset( new ExtTextInputAttr[maText.getLength()] );
-        memcpy( mpTextAttr.get(), pTextAttr, 
maText.getLength()*sizeof(ExtTextInputAttr) );
+        std::copy_n(pTextAttr, maText.getLength(), mpTextAttr.get());
     }
 
     mnCursorPos     = nCursorPos;
@@ -44,7 +45,7 @@ CommandExtTextInputData::CommandExtTextInputData( const 
CommandExtTextInputData&
     if ( rData.mpTextAttr && !maText.isEmpty() )
     {
         mpTextAttr.reset( new ExtTextInputAttr[maText.getLength()] );
-        memcpy( mpTextAttr.get(), rData.mpTextAttr.get(), 
maText.getLength()*sizeof(ExtTextInputAttr) );
+        std::copy_n(rData.mpTextAttr.get(), maText.getLength(), 
mpTextAttr.get());
     }
 
     mnCursorPos     = rData.mnCursorPos;
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index a75eb6ada250..53b3540cd21d 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -62,6 +62,8 @@
 #include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
 #include <com/sun/star/awt/MouseEvent.hpp>
 
+#include <algorithm>
+
 #define IMPL_MIN_NEEDSYSWIN         49
 
 namespace
@@ -1444,7 +1446,7 @@ static bool ImplHandleExtTextInput( vcl::Window* pWindow,
     if ( pTextAttr )
     {
         pWinData->mpExtOldAttrAry.reset( new 
ExtTextInputAttr[rText.getLength()] );
-        memcpy( pWinData->mpExtOldAttrAry.get(), pTextAttr, 
rText.getLength()*sizeof( ExtTextInputAttr ) );
+        std::copy_n(pTextAttr, rText.getLength(), 
pWinData->mpExtOldAttrAry.get());
     }
     return !ImplCallCommand( pChild, CommandEventId::ExtTextInput, &aData );
 }

Reply via email to