From 620667f9d8768e33e96c98ac499365cabc5dd67a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 17 Jan 2026 08:44:43 -1000 Subject: [PATCH] bot review --- esphome/core/string_ref.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/esphome/core/string_ref.h b/esphome/core/string_ref.h index 7501d06ce4..3b209a7c7f 100644 --- a/esphome/core/string_ref.h +++ b/esphome/core/string_ref.h @@ -81,7 +81,8 @@ class StringRef { operator std::string() const { return str(); } - /// Find first occurrence of substring, returns std::string::npos if not found + /// Find first occurrence of substring, returns std::string::npos if not found. + /// Note: Requires the underlying string to be null-terminated. size_type find(const char *s, size_type pos = 0) const { if (pos >= len_) return std::string::npos; @@ -91,8 +92,8 @@ class StringRef { size_type find(char c, size_type pos = 0) const { if (pos >= len_) return std::string::npos; - const char *result = std::strchr(base_ + pos, c); - return (result && result < base_ + len_) ? static_cast(result - base_) : std::string::npos; + const void *result = std::memchr(base_ + pos, static_cast(c), len_ - pos); + return result ? static_cast(static_cast(result) - base_) : std::string::npos; } /// Return substring as std::string