From e7ce2703e859d306911fc717f25e915932a43306 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 21:04:55 -1000 Subject: [PATCH 1/2] [api] Add explicit static_cast in decode_zigzag32 calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On BLE builds where proto_varint_value_t is uint64_t, decode_zigzag32() takes uint32_t — make the narrowing explicit to match the static_cast pattern used for other type conversions in generated code. Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/api_pb2.cpp | 10 +++++----- script/api_protobuf/api_protobuf.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index 20ee65fd048..01993cc5e5f 100644 --- a/esphome/components/api/api_pb2.cpp +++ b/esphome/components/api/api_pb2.cpp @@ -1039,7 +1039,7 @@ bool HomeAssistantStateResponse::decode_length(uint32_t field_id, ProtoLengthDel bool DSTRule::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: - this->time_seconds = decode_zigzag32(value); + this->time_seconds = decode_zigzag32(static_cast(value)); break; case 2: this->day = value; @@ -1064,10 +1064,10 @@ bool DSTRule::decode_varint(uint32_t field_id, proto_varint_value_t value) { bool ParsedTimezone::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: - this->std_offset_seconds = decode_zigzag32(value); + this->std_offset_seconds = decode_zigzag32(static_cast(value)); break; case 2: - this->dst_offset_seconds = decode_zigzag32(value); + this->dst_offset_seconds = decode_zigzag32(static_cast(value)); break; default: return false; @@ -1151,13 +1151,13 @@ bool ExecuteServiceArgument::decode_varint(uint32_t field_id, proto_varint_value this->legacy_int = static_cast(value); break; case 5: - this->int_ = decode_zigzag32(value); + this->int_ = decode_zigzag32(static_cast(value)); break; case 6: this->bool_array.push_back(value != 0); break; case 7: - this->int_array.push_back(decode_zigzag32(value)); + this->int_array.push_back(decode_zigzag32(static_cast(value))); break; default: return false; diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 1c2a3e5cc2f..b4044c362c6 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -1262,7 +1262,7 @@ class SFixed64Type(TypeInfo): class SInt32Type(TypeInfo): cpp_type = "int32_t" default_value = "0" - decode_varint = "decode_zigzag32(value)" + decode_varint = "decode_zigzag32(static_cast(value))" encode_func = "encode_sint32" wire_type = WireType.VARINT # Uses wire type 0 From 765bb3298ea99d318b3db9ef7ca47b33f0824e91 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 21:06:22 -1000 Subject: [PATCH 2/2] [api] Use PROTO_VARINT_PARSE_FAILED constant in parse failure returns Replace magic {0, 0} with {0, PROTO_VARINT_PARSE_FAILED} in parse_slow() and parse_wide() for consistency with the named sentinel. Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/proto.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index 8959ac7a2a3..4f5b3f0918f 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -38,7 +38,7 @@ ProtoVarIntResult ProtoVarInt::parse_slow(const uint8_t *buffer, uint32_t len) { #ifdef USE_API_VARINT64 return parse_wide(buffer, len, result32); #else - return {0, 0}; + return {0, PROTO_VARINT_PARSE_FAILED}; #endif } @@ -53,7 +53,7 @@ ProtoVarIntResult ProtoVarInt::parse_wide(const uint8_t *buffer, uint32_t len, u return {result64, i + 1}; } } - return {0, 0}; + return {0, PROTO_VARINT_PARSE_FAILED}; } #endif