From 17882988042e3b8adeffbc2072a5a457cb6efb52 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 19 Jan 2022 11:59:51 +0100 Subject: Cleanup: Strict compiler warning in Cycles The ustring is not a trivially copyable object from the C++ standard point of view, so using memcpy on it is strictly wrong. In practice, however, this is OK since it is just a thin wrapper around char*. For now use explicit cast to void* same as it was done in other places of ccl::array implementation. But also localize the place where memory copy happens to make it easier to support proper non-trivial C++ objects in the future. --- intern/cycles/util/array.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'intern/cycles/util') diff --git a/intern/cycles/util/array.h b/intern/cycles/util/array.h index 4c905b09138..1c5e3e8d4ec 100644 --- a/intern/cycles/util/array.h +++ b/intern/cycles/util/array.h @@ -64,7 +64,7 @@ template class arra else { data_ = mem_allocate(from.datasize_); if (from.datasize_ > 0) { - memcpy(data_, from.data_, from.datasize_ * sizeof(T)); + mem_copy(data_, from.data_, from.datasize_); } datasize_ = from.datasize_; capacity_ = datasize_; @@ -76,7 +76,7 @@ template class arra if (this != &from) { resize(from.size()); if (datasize_ > 0) { - memcpy((void *)data_, from.data_, datasize_ * sizeof(T)); + mem_copy(data_, from.data_, datasize_); } } @@ -88,7 +88,7 @@ template class arra resize(from.size()); if (from.size() > 0 && datasize_ > 0) { - memcpy(data_, &from[0], datasize_ * sizeof(T)); + mem_copy(data_, from.data(), datasize_); } return *this; @@ -161,8 +161,7 @@ template class arra return NULL; } else if (data_ != NULL) { - memcpy( - (void *)newdata, data_, ((datasize_ < newsize) ? datasize_ : newsize) * sizeof(T)); + mem_copy(newdata, data_, ((datasize_ < newsize) ? datasize_ : newsize)); mem_free(data_, capacity_); } data_ = newdata; @@ -246,7 +245,7 @@ template class arra if (newcapacity > capacity_) { T *newdata = mem_allocate(newcapacity); if (data_ != NULL) { - memcpy(newdata, data_, ((datasize_ < newcapacity) ? datasize_ : newcapacity) * sizeof(T)); + mem_copy(newdata, data_, ((datasize_ < newcapacity) ? datasize_ : newcapacity)); mem_free(data_, capacity_); } data_ = newdata; @@ -280,7 +279,7 @@ template class arra if (from.size()) { size_t old_size = size(); resize(old_size + from.size()); - memcpy(data_ + old_size, from.data(), sizeof(T) * from.size()); + mem_copy(data_ + old_size, from.data(), from.size()); } } @@ -308,6 +307,11 @@ template class arra } } + inline void mem_copy(T *mem_to, const T *mem_from, const size_t N) + { + memcpy((void *)mem_to, mem_from, sizeof(T) * N); + } + T *data_; size_t datasize_; size_t capacity_; -- cgit v1.2.3