From b8cb6fedb335dd9105395c58685ab6a90150b5cb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 25 Dec 2025 20:38:38 -1000 Subject: [PATCH 1/2] address copilot review comments --- esphome/components/network/ip_address.h | 3 +-- esphome/components/wifi_info/wifi_info_text_sensor.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/esphome/components/network/ip_address.h b/esphome/components/network/ip_address.h index c4bf2abc719..27cc212a474 100644 --- a/esphome/components/network/ip_address.h +++ b/esphome/components/network/ip_address.h @@ -55,8 +55,7 @@ struct IPAddress { std::string str() const { return str_lower_case(inet_ntoa(ip_addr_)); } /// Write IP address to buffer. Buffer must be at least IP_ADDRESS_BUFFER_SIZE bytes. char *str_to(char *buf) const { - inet_ntop(AF_INET, &ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE); - return buf; + return const_cast(inet_ntop(AF_INET, &ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE)); } #else IPAddress() { ip_addr_set_zero(&ip_addr_); } diff --git a/esphome/components/wifi_info/wifi_info_text_sensor.cpp b/esphome/components/wifi_info/wifi_info_text_sensor.cpp index ce3c4b76613..1860ace9495 100644 --- a/esphome/components/wifi_info/wifi_info_text_sensor.cpp +++ b/esphome/components/wifi_info/wifi_info_text_sensor.cpp @@ -63,7 +63,7 @@ void ScanResultsWiFiInfo::setup() { wifi::global_wifi_component->add_scan_result void ScanResultsWiFiInfo::dump_config() { LOG_TEXT_SENSOR("", "Scan Results", this); } -// Format: "SSID: -XXdB\n" - caller must ensure 9 bytes available after ssid +// Format: "SSID: -XXdB\n" - caller must ensure ssid_len + 9 bytes available in buffer static char *format_scan_entry(char *buf, const char *ssid, size_t ssid_len, int8_t rssi) { memcpy(buf, ssid, ssid_len); buf += ssid_len; From 9e13f6ac4c2922156f5b351db52e8ccdf5db441d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 25 Dec 2025 20:46:20 -1000 Subject: [PATCH 2/2] copilot is wrong, add comment --- esphome/components/wifi_info/wifi_info_text_sensor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/wifi_info/wifi_info_text_sensor.cpp b/esphome/components/wifi_info/wifi_info_text_sensor.cpp index 1860ace9495..eae0f87b403 100644 --- a/esphome/components/wifi_info/wifi_info_text_sensor.cpp +++ b/esphome/components/wifi_info/wifi_info_text_sensor.cpp @@ -46,8 +46,8 @@ void DNSAddressWifiInfo::dump_config() { LOG_TEXT_SENSOR("", "DNS Address", this void DNSAddressWifiInfo::on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1, const network::IPAddress &dns2) { - // Single buffer: IP1 + space + IP2 + null - char buf[network::IP_ADDRESS_BUFFER_SIZE * 2 + 1]; + // IP_ADDRESS_BUFFER_SIZE (40) = max IP (39) + null; space reuses first null's slot + char buf[network::IP_ADDRESS_BUFFER_SIZE * 2]; dns1.str_to(buf); size_t len1 = strlen(buf); buf[len1] = ' ';