mirror of
https://github.com/esphome/esphome.git
synced 2026-10-01 00:40:21 +00:00
Guard against nullptr+0 UB in call() and fix assert bound
- Add early return when size_==0 to avoid nullptr+0 pointer arithmetic (UB per C++ standard, even though all ESPHome targets treat it as no-op) - Fix debug assert: size < UINT16_MAX allows capacity up to 65535
This commit is contained in:
@@ -24,7 +24,7 @@ static const char *const TAG = "helpers";
|
||||
|
||||
__attribute__((noinline, cold)) void *callback_manager_grow(void *data, uint16_t size, uint16_t &capacity,
|
||||
size_t elem_size) {
|
||||
ESPHOME_DEBUG_ASSERT(size < UINT16_MAX - 1);
|
||||
ESPHOME_DEBUG_ASSERT(size < UINT16_MAX);
|
||||
uint16_t new_cap = size + 1;
|
||||
auto *new_data = ::operator new(new_cap *elem_size);
|
||||
if (data) {
|
||||
|
||||
Reference in New Issue
Block a user