From 64e4edd70fc170889e96f56de45ab4fb5b0f461a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 29 Jan 2026 23:30:33 -0600 Subject: [PATCH] bad feedback from copilot --- esphome/components/time/real_time_clock.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/esphome/components/time/real_time_clock.h b/esphome/components/time/real_time_clock.h index 5b760d23c6..b9830ee4cb 100644 --- a/esphome/components/time/real_time_clock.h +++ b/esphome/components/time/real_time_clock.h @@ -27,10 +27,15 @@ class RealTimeClock : public PollingComponent { void set_timezone(const char *tz) { this->apply_timezone_(tz); } /// Set the time zone from a character buffer with known length. - /// The buffer does not need to be null-terminated; it will be copied. + /// The buffer does not need to be null-terminated. void set_timezone(const char *tz, size_t len) { - std::string tz_str(tz, len); - this->apply_timezone_(tz_str.c_str()); + // Stack buffer - TZ strings are typically <64 chars + char buf[64]; + if (len >= sizeof(buf)) + len = sizeof(buf) - 1; + memcpy(buf, tz, len); + buf[len] = '\0'; + this->apply_timezone_(buf); } /// Set the time zone from a std::string.