From 76900b83252c35d4a55acd87def9b8d280b15f50 Mon Sep 17 00:00:00 2001 From: Adrian Diaz Date: Fri, 31 May 2019 11:53:58 -0600 Subject: [PATCH] avoids the possibility of undefined behavior with memcpy having the same source and destination arrays; this is not every instance of this issue in the source code --- src/math_extra.cpp | 4 ++-- src/rcb.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/math_extra.cpp b/src/math_extra.cpp index 0bba2ad401..f7e5bb646b 100644 --- a/src/math_extra.cpp +++ b/src/math_extra.cpp @@ -56,7 +56,7 @@ int mldivide3(const double m[3][3], const double *v, double *ans) if (fabs(aug[j][i]) > fabs(aug[i][i])) { double tempv[4]; memcpy(tempv,aug[i],4*sizeof(double)); - memcpy(aug[i],aug[j],4*sizeof(double)); + memmove(aug[i],aug[j],4*sizeof(double)); memcpy(aug[j],tempv,4*sizeof(double)); } } @@ -68,7 +68,7 @@ int mldivide3(const double m[3][3], const double *v, double *ans) if (p != i) { double tempv[4]; memcpy(tempv,aug[i],4*sizeof(double)); - memcpy(aug[i],aug[p],4*sizeof(double)); + memmove(aug[i],aug[p],4*sizeof(double)); memcpy(aug[p],tempv,4*sizeof(double)); } diff --git a/src/rcb.cpp b/src/rcb.cpp index 630cef309a..83cdccdf80 100644 --- a/src/rcb.cpp +++ b/src/rcb.cpp @@ -537,7 +537,7 @@ void RCB::compute(int dimension, int n, double **x, double *wt, if (dotmark[i] == markactive) memcpy(&buf[outgoing++],&dots[i],sizeof(Dot)); else - memcpy(&dots[keep++],&dots[i],sizeof(Dot)); + memmove(&dots[keep++],&dots[i],sizeof(Dot)); } // post receives for dots @@ -1029,7 +1029,7 @@ void RCB::compute_old(int dimension, int n, double **x, double *wt, if (dotmark[i] == markactive) memcpy(&buf[outgoing++],&dots[i],sizeof(Dot)); else - memcpy(&dots[keep++],&dots[i],sizeof(Dot)); + memmove(&dots[keep++],&dots[i],sizeof(Dot)); } // post receives for dots