From 36e9febba1fd77b115ee1742ae2a34bfc560e20c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 17 Jan 2026 11:01:45 -1000 Subject: [PATCH] bot comments, tidy --- esphome/core/string_ref.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/esphome/core/string_ref.h b/esphome/core/string_ref.h index d5d2897e82..e13b752e00 100644 --- a/esphome/core/string_ref.h +++ b/esphome/core/string_ref.h @@ -87,8 +87,10 @@ class StringRef { if (pos >= len_) return std::string::npos; const char *result = std::strstr(base_ + pos, s); - // Verify match is within bounds (strstr searches to null terminator) - return (result && result < base_ + len_) ? static_cast(result - base_) : std::string::npos; + // Verify entire match is within bounds (strstr searches to null terminator) + if (result && result + std::strlen(s) <= base_ + len_) + return static_cast(result - base_); + return std::string::npos; } size_type find(char c, size_type pos = 0) const { if (pos >= len_) @@ -188,6 +190,7 @@ inline std::string operator+(const std::string &lhs, const StringRef &rhs) { // String conversion functions for ADL compatibility (allows stoi(x) where x is StringRef) // Must be in esphome namespace for ADL to find them. Uses strtol/strtod directly to avoid heap allocation. namespace internal { +// NOLINTBEGIN(google-runtime-int) template inline R parse_number(const StringRef &str, size_t *pos, F conv) { char *end; R result = conv(str.c_str(), &end); @@ -202,8 +205,9 @@ template inline R parse_number(const StringRef &str, siz *pos = static_cast(end - str.c_str()); return result; } +// NOLINTEND(google-runtime-int) } // namespace internal -// NOLINTBEGIN(readability-identifier-naming) +// NOLINTBEGIN(readability-identifier-naming,google-runtime-int) inline int stoi(const StringRef &str, size_t *pos = nullptr, int base = 10) { return static_cast(internal::parse_number(str, pos, base, std::strtol)); }