[core] get_log_str: fix false-positive error on null-terminated strings with stricter compilers (#15136)

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: J. Nick Koston <nick+github@koston.org>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
Diorcet Yann
2026-03-24 20:26:21 +00:00
committed by GitHub
co-authored by J. Nick Koston J. Nick Koston pre-commit-ci-lite[bot] J. Nick Koston
parent 8751f348c8
commit 13baf26050
+4 -1
View File
@@ -3,6 +3,7 @@
#include <array>
#include <cstddef>
#include <cstdint>
#include <new>
#include "esphome/core/hal.h" // For PROGMEM definition
@@ -104,7 +105,9 @@ struct LogString;
static const char *get_(uint8_t idx, uint8_t fallback) { \
if (idx >= COUNT) \
idx = fallback; \
return &BLOB[::esphome::progmem_read_byte(&OFFSETS[idx])]; \
/* std::launder is used here to prevent the inter-procedural analysis that */ \
/* causes the false positive that the string is not null terminated */ \
return std::launder(&BLOB[::esphome::progmem_read_byte(&OFFSETS[idx])]); \
} \
static ::ProgmemStr get_progmem_str(uint8_t idx, uint8_t fallback) { \
return reinterpret_cast<::ProgmemStr>(get_(idx, fallback)); \