Allow populating a flatbuffers string field up to its static length
An assert in the code prevented us from doing so. The implementation
already accounts for an extra byte for the null character, so the value
of the 'static_length' attribute indicates the maximum number of
characters allowed in the string excluding the null character.
Modify an existing test to attempt setting a string field to a value
that is as long as its static length, to verify that this does work.
Change-Id: I1fc7229762ec8625ba881ca57552c646a19c3d66
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/flatbuffers/static_vector.h b/aos/flatbuffers/static_vector.h
index 05d6459..bf706e0 100644
--- a/aos/flatbuffers/static_vector.h
+++ b/aos/flatbuffers/static_vector.h
@@ -735,7 +735,7 @@
: VectorType(buffer, parent) {}
virtual ~String() {}
void SetString(std::string_view string) {
- CHECK_LT(string.size(), VectorType::capacity());
+ CHECK_LE(string.size(), VectorType::capacity());
VectorType::resize_inline(string.size(), SetZero::kNo);
memcpy(VectorType::data(), string.data(), string.size());
}