From c6ff6d268baba89bc24268d0b7e8172d62cee23f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 14 Jan 2026 17:35:36 -1000 Subject: [PATCH] safer --- esphome/core/helpers.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index 7f70a0126e..85fe7e3d89 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -410,6 +410,10 @@ char *format_bin_to(char *buffer, size_t buffer_size, const uint8_t *data, size_ } // Calculate max bytes we can format: each byte needs 8 chars size_t max_bytes = (buffer_size - 1) / 8; + if (max_bytes == 0 || length == 0) { + buffer[0] = '\0'; + return buffer; + } size_t bytes_to_format = std::min(length, max_bytes); for (size_t byte_idx = 0; byte_idx < bytes_to_format; byte_idx++) {