mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 21:18:24 +08:00
Improve safety of makeCopy() function
The mentioned function allocates and copies elements of size 1. Therefore, the implementation was simplified and additional check was added to avoid possible UBs. Signed-off-by: Wrobel, Patryk <patryk.wrobel@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
ccb855de32
commit
a6c7f341dd
@@ -115,8 +115,11 @@ inline std::unique_ptr<T[]> makeCopy(const void *src, size_t size) {
|
|||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
using ElT = typename std::remove_all_extents<T>::type;
|
|
||||||
std::unique_ptr<T[]> copiedData(new ElT[size]);
|
static_assert(sizeof(T) == 1u && std::is_trivially_copyable_v<T>);
|
||||||
|
|
||||||
|
auto copiedData = std::make_unique<T[]>(size);
|
||||||
memcpy_s(copiedData.get(), size, src, size);
|
memcpy_s(copiedData.get(), size, src, size);
|
||||||
|
|
||||||
return copiedData;
|
return copiedData;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user