Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey@blender.org>2022-01-19 13:59:51 +0300
committerSergey Sharybin <sergey@blender.org>2022-01-19 14:01:49 +0300
commit17882988042e3b8adeffbc2072a5a457cb6efb52 (patch)
tree796a44265febdeea1530f4dead5ada63398faccd /intern/cycles/util
parent8a23d91a50923c62be5ed4ce38955dfc60de6e70 (diff)
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.
Diffstat (limited to 'intern/cycles/util')
-rw-r--r--intern/cycles/util/array.h18
1 files changed, 11 insertions, 7 deletions
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<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> 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<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> 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<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> 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<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> 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<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> 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<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> 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<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES> 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_;