From 2eb3e252780a3cb549f65a34feeea8a50e90b0e3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 6 Apr 2026 13:58:10 -1000 Subject: [PATCH] Add debug assert to encode_short_string_force for size < 128 --- esphome/components/api/proto.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 8cb05f630f..26868e3fd5 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -350,6 +350,9 @@ class ProtoEncode { /// Tag must be a single-byte varint (< 128). Always encodes (no zero check). static inline void encode_short_string_force(uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint8_t tag, const StringRef &ref) { +#ifdef ESPHOME_DEBUG_API + assert(ref.size() < 128 && "encode_short_string_force: string exceeds max_data_length < 128"); +#endif PROTO_ENCODE_CHECK_BOUNDS(pos, 2 + ref.size()); pos[0] = tag; pos[1] = static_cast(ref.size());