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());