From 27a16ca97cedfc80b96fd1a8f76b66b9ffddae98 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 5 Apr 2026 18:54:39 -1000 Subject: [PATCH] [api] Use local pointer in encode_small_varint to avoid aliased pos_ stores --- esphome/components/api/proto.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index c4f965ed13..e3cecfcde6 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -280,8 +280,10 @@ class ProtoWriteBuffer { * The tag is precomputed by the code generator. value must be < 128. */ void encode_small_varint(uint8_t precomputed_tag, uint8_t value) { this->debug_check_bounds_(2); - *this->pos_++ = precomputed_tag; - *this->pos_++ = value; + auto *p = this->pos_; + p[0] = precomputed_tag; + p[1] = value; + this->pos_ = p + 2; } void encode_uint32(uint32_t field_id, uint32_t value, bool force = false) { if (value == 0 && !force)