diff --git a/src/lib/core/CHIPTLV.h b/src/lib/core/CHIPTLV.h index d61232e9e27e1c..876e8157dd98bb 100644 --- a/src/lib/core/CHIPTLV.h +++ b/src/lib/core/CHIPTLV.h @@ -845,8 +845,10 @@ class DLL_EXPORT TLVReader }; /** - * A TLVReader that is backed by a single contiguous buffer. This exposes some - * additional methods that point directly into that buffer. + * A TLVReader that is guaranteed to be backed by a single contiguous buffer. + * This allows it to expose some additional methods that allow consumers to + * directly access the data in that buffer in a safe way that is guaranteed to + * work as long as the reader object stays in scope. */ class ContiguousBufferTLVReader : public TLVReader { @@ -873,7 +875,7 @@ class ContiguousBufferTLVReader : public TLVReader } /** - * Allow opening a container, wit ha new ContiguousBufferTLVReader reading + * Allow opening a container, with a new ContiguousBufferTLVReader reading * that container. See TLVReader::OpenContainer for details. */ CHIP_ERROR OpenContainer(ContiguousBufferTLVReader & containerReader); diff --git a/src/lib/core/CHIPTLVReader.cpp b/src/lib/core/CHIPTLVReader.cpp index a8ac654d0b2725..6b1a0ec1d086db 100644 --- a/src/lib/core/CHIPTLVReader.cpp +++ b/src/lib/core/CHIPTLVReader.cpp @@ -899,6 +899,11 @@ CHIP_ERROR TLVReader::FindElementWithTag(const uint64_t tag, TLVReader & destRea CHIP_ERROR ContiguousBufferTLVReader::OpenContainer(ContiguousBufferTLVReader & containerReader) { + // We are going to initialize containerReader by calling our superclass + // OpenContainer method. The superclass only knows how to initialize + // members the superclass knows about, so we assert that we don't have any + // extra members that need initializing. If such members ever get added, + // they would need to be initialized in this method. static_assert(sizeof(ContiguousBufferTLVReader) == sizeof(TLVReader), "We have state the superclass is not initializing?"); return TLVReader::OpenContainer(containerReader); }