Skip to content

Commit d5f8676

Browse files
committed
constexpr simd vec: mixed element type constructor: fix nullptr being passed to memcpy
1 parent 3e20cc6 commit d5f8676

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

glm/detail/simd_constexpr/vec.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ namespace glm
295295
return 1;
296296
}
297297
}
298-
static inline auto ctor_mixed_constexpr_single = [](auto vs0) -> auto
298+
static inline decltype(auto) ctor_mixed_constexpr_single = [](auto vs0) -> auto
299299
{
300300
using VTX = decltype(vs0);
301301
if constexpr ( std::is_integral_v<VTX> || std::is_floating_point_v<VTX> ) {
@@ -353,16 +353,19 @@ namespace glm
353353
const auto params = std::tuple{vecOrScalar...};
354354

355355
const auto arr = ctor_mixed_constexpr_single(std::get<0>(params));
356-
std::memcpy(aa.a.p.begin()+i, arr, sizeof(T)*lengths[0]);
356+
if (arr) [[likely]]
357+
std::memcpy(aa.a.p.begin()+i, arr, sizeof(T)*lengths[0]);
357358
constexpr auto i2 = i + lengths[0];
358359

359360
if constexpr (sizeof...(VecOrScalar) > 1) {
360361
const auto arr2 = ctor_mixed_constexpr_single(std::get<1>(params));
361-
std::memcpy(aa.a.p.begin()+i2, arr2, sizeof(T)*lengths[1]);
362+
if (arr2) [[likely]]
363+
std::memcpy(aa.a.p.begin()+i2, arr2, sizeof(T)*lengths[1]);
362364
constexpr auto i3 = i2 + lengths[1];
363365
if constexpr (sizeof...(VecOrScalar) > 2) {
364366
const auto arr3 = ctor_mixed_constexpr_single(std::get<2>(params));
365-
std::memcpy(aa.a.p.begin()+i3, arr3, sizeof(T)*lengths[2]);
367+
if (arr3) [[likely]]
368+
std::memcpy(aa.a.p.begin()+i3, arr3, sizeof(T)*lengths[2]);
366369
}
367370
}
368371

0 commit comments

Comments
 (0)