From 5dbf35051a969cec0d9d1e23a39d23b8942038b6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 20:58:13 -1000 Subject: [PATCH] [api] Add explicit static_cast for tag/field_length narrowing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consistency with frame helper code — makes the uint64→uint32 narrowing explicit on BLE builds where proto_varint_value_t is uint64_t. Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/proto.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index e35565dd6d..8959ac7a2a 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -69,7 +69,7 @@ uint32_t ProtoDecodableMessage::count_repeated_field(const uint8_t *buffer, size break; // Invalid data, stop counting } - uint32_t tag = res.value; + uint32_t tag = static_cast(res.value); uint32_t field_type = tag & WIRE_TYPE_MASK; uint32_t field_id = tag >> 3; ptr += res.consumed; @@ -94,7 +94,7 @@ uint32_t ProtoDecodableMessage::count_repeated_field(const uint8_t *buffer, size if (!res.has_value()) { return count; } - uint32_t field_length = res.value; + uint32_t field_length = static_cast(res.value); ptr += res.consumed; if (field_length > static_cast(end - ptr)) { return count; // Out of bounds @@ -215,7 +215,7 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { return; } - uint32_t tag = res.value; + uint32_t tag = static_cast(res.value); uint32_t field_type = tag & WIRE_TYPE_MASK; uint32_t field_id = tag >> 3; ptr += res.consumed; @@ -240,7 +240,7 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { ESP_LOGV(TAG, "Invalid Length Delimited at offset %ld", (long) (ptr - buffer)); return; } - uint32_t field_length = res.value; + uint32_t field_length = static_cast(res.value); ptr += res.consumed; if (field_length > static_cast(end - ptr)) { ESP_LOGV(TAG, "Out-of-bounds Length Delimited at offset %ld", (long) (ptr - buffer));