pw_kvs: Check that AlignedWrite buffer is at least write alignment
Check that the internal buffer for AlignedWrite<> is at least the size
of the write alignment that was given as an argument.
Change-Id: Ia438bfcac2540ca6c2b06ea9383a7682d158e7d9
diff --git a/pw_kvs/public/pw_kvs/alignment.h b/pw_kvs/public/pw_kvs/alignment.h
index b2dcbc3..2663846 100644
--- a/pw_kvs/public/pw_kvs/alignment.h
+++ b/pw_kvs/public/pw_kvs/alignment.h
@@ -97,6 +97,12 @@
StatusWithSize AlignedWrite(Output& output,
size_t alignment_bytes,
span<const span<const std::byte>> data) {
+ // TODO: This should convert to PW_CHECK once that is available for use in
+ // host tests.
+ if (alignment_bytes > kBufferSize) {
+ return StatusWithSize(Status::INTERNAL);
+ }
+
AlignedWriterBuffer<kBufferSize> buffer(alignment_bytes, output);
for (const span<const std::byte>& chunk : data) {