From bea9ffa3d0049b851ee85c85cffe110f9d679a06 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 10 May 2017 14:20:45 +0100 Subject: [PATCH] slight fixes for "templatized" arraycopy static methods. - source pointers were tested twice. - source and destination can still possibly overlap dest = src + 1 for example, thus might be safer to just use memmove regardless of the situation. --- activemq-cpp/src/main/decaf/lang/System.cpp | 70 +++++++-------------- 1 file changed, 21 insertions(+), 49 deletions(-) diff --git a/activemq-cpp/src/main/decaf/lang/System.cpp b/activemq-cpp/src/main/decaf/lang/System.cpp index 199dd660c..9e4c49b68 100644 --- a/activemq-cpp/src/main/decaf/lang/System.cpp +++ b/activemq-cpp/src/main/decaf/lang/System.cpp @@ -122,17 +122,13 @@ void System::arraycopy(const char* src, std::size_t srcPos, char* dest, __FILE__, __LINE__, "Given Source Pointer was null."); } - if (src == NULL) { + if (dest == NULL) { throw NullPointerException( - __FILE__, __LINE__, "Given Source Pointer was null."); + __FILE__, __LINE__, "Given Destination Pointer was null."); } // Now we try and copy, could still segfault. - if (src != dest) { - ::memcpy(dest + destPos, src + srcPos, length); - } else { - ::memmove(dest + destPos, src + srcPos, length); - } + ::memmove(dest + destPos, src + srcPos, length); } //////////////////////////////////////////////////////////////////////////////// @@ -144,17 +140,13 @@ void System::arraycopy(const unsigned char* src, std::size_t srcPos, __FILE__, __LINE__, "Given Source Pointer was null."); } - if (src == NULL) { + if (dest == NULL) { throw NullPointerException( - __FILE__, __LINE__, "Given Source Pointer was null."); + __FILE__, __LINE__, "Given Destination Pointer was null."); } // Now we try and copy, could still segfault. - if (src != dest) { - ::memcpy(dest + destPos, src + srcPos, length); - } else { - ::memmove(dest + destPos, src + srcPos, length); - } + ::memmove(dest + destPos, src + srcPos, length); } //////////////////////////////////////////////////////////////////////////////// @@ -166,17 +158,13 @@ void System::arraycopy(const short* src, std::size_t srcPos, __FILE__, __LINE__, "Given Source Pointer was null."); } - if (src == NULL) { + if (dest == NULL) { throw NullPointerException( - __FILE__, __LINE__, "Given Source Pointer was null."); + __FILE__, __LINE__, "Given Destination Pointer was null."); } // Now we try and copy, could still segfault. - if (src != dest) { - ::memcpy(dest + destPos, src + srcPos, length * sizeof(short)); - } else { - ::memmove(dest + destPos, src + srcPos, length * sizeof(short)); - } + ::memmove(dest + destPos, src + srcPos, length * sizeof(short)); } //////////////////////////////////////////////////////////////////////////////// @@ -188,17 +176,13 @@ void System::arraycopy(const int* src, std::size_t srcPos, __FILE__, __LINE__, "Given Source Pointer was null."); } - if (src == NULL) { + if (dest == NULL) { throw NullPointerException( - __FILE__, __LINE__, "Given Source Pointer was null."); + __FILE__, __LINE__, "Given Destination Pointer was null."); } // Now we try and copy, could still segfault. - if (src != dest) { - ::memcpy(dest + destPos, src + srcPos, length * sizeof(int)); - } else { - ::memmove(dest + destPos, src + srcPos, length * sizeof(int)); - } + ::memmove(dest + destPos, src + srcPos, length * sizeof(int)); } //////////////////////////////////////////////////////////////////////////////// @@ -210,17 +194,13 @@ void System::arraycopy(const long long* src, std::size_t srcPos, __FILE__, __LINE__, "Given Source Pointer was null."); } - if (src == NULL) { + if (dest == NULL) { throw NullPointerException( - __FILE__, __LINE__, "Given Source Pointer was null."); + __FILE__, __LINE__, "Given Destination Pointer was null."); } // Now we try and copy, could still segfault. - if (src != dest) { - ::memcpy(dest + destPos, src + srcPos, length * sizeof(long long)); - } else { - ::memmove(dest + destPos, src + srcPos, length * sizeof(long long)); - } + ::memmove(dest + destPos, src + srcPos, length * sizeof(long long)); } //////////////////////////////////////////////////////////////////////////////// @@ -232,17 +212,13 @@ void System::arraycopy(const float* src, std::size_t srcPos, __FILE__, __LINE__, "Given Source Pointer was null."); } - if (src == NULL) { + if (dest == NULL) { throw NullPointerException( - __FILE__, __LINE__, "Given Source Pointer was null."); + __FILE__, __LINE__, "Given Destination Pointer was null."); } // Now we try and copy, could still segfault. - if (src != dest) { - ::memcpy(dest + destPos, src + srcPos, length * sizeof(float)); - } else { - ::memmove(dest + destPos, src + srcPos, length * sizeof(float)); - } + ::memmove(dest + destPos, src + srcPos, length * sizeof(float)); } //////////////////////////////////////////////////////////////////////////////// @@ -254,17 +230,13 @@ void System::arraycopy(const double* src, std::size_t srcPos, __FILE__, __LINE__, "Given Source Pointer was null." ); } - if( src == NULL ) { + if( dest == NULL ) { throw NullPointerException( - __FILE__, __LINE__, "Given Source Pointer was null." ); + __FILE__, __LINE__, "Given Destination Pointer was null." ); } // Now we try and copy, could still segfault. - if( src != dest ) { - ::memcpy( dest + destPos, src + srcPos, length * sizeof( double ) ); - } else { - ::memmove( dest + destPos, src + srcPos, length * sizeof( double ) ); - } + ::memmove( dest + destPos, src + srcPos, length * sizeof( double ) ); } ////////////////////////////////////////////////////////////////////////////////