diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index ae3f7e1e36..5eab5b475d 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -1752,15 +1752,10 @@ template struct Callback { // creates objects of implicit-lifetime types (trivially copyable qualifies). Callback cb; cb.ctx = nullptr; - char *dst = reinterpret_cast(&cb.ctx); // NOLINT(clang-analyzer-core.uninitialized.Assign) - const char *src = reinterpret_cast(&callable); // NOLINT(clang-analyzer-core.uninitialized.Assign) - for (size_t i = 0; i < sizeof(DecayF); ++i) - dst[i] = src[i]; // NOLINT(clang-analyzer-core.uninitialized.Assign) + __builtin_memcpy(&cb.ctx, &callable, sizeof(DecayF)); cb.fn = [](void *c, Ts... args) { alignas(DecayF) char buf[sizeof(DecayF)]; - const char *csrc = reinterpret_cast(&c); // NOLINT(clang-analyzer-core.uninitialized.Assign) - for (size_t i = 0; i < sizeof(DecayF); ++i) - buf[i] = csrc[i]; // NOLINT(clang-analyzer-core.uninitialized.Assign) + __builtin_memcpy(buf, &c, sizeof(DecayF)); reinterpret_cast(buf)->operator()(args...); }; return cb;