summaryrefslogtreecommitdiff
path: root/src/reflection.cpp
diff options
context:
space:
mode:
authorWouter van Oortmerssen <wvo@google.com>2015-12-21 16:17:50 -0800
committerWouter van Oortmerssen <wvo@google.com>2015-12-21 16:20:03 -0800
commit189153723649d3b6ad56f7b83662e30c480e124f (patch)
treecb20fe260e4733b1093028f80b48e3ba8cf3aeff /src/reflection.cpp
parentd7d527d1545a3247863a3d95b6b3e4adf18eb127 (diff)
downloadflatbuffers-189153723649d3b6ad56f7b83662e30c480e124f.tar.gz
flatbuffers-189153723649d3b6ad56f7b83662e30c480e124f.tar.bz2
flatbuffers-189153723649d3b6ad56f7b83662e30c480e124f.zip
Fixed reflection setting string not changing size field.
Change-Id: I3c3e88a79667d1733b6c47e43b55d8b2604ca8e2 Tested: on Linux.
Diffstat (limited to 'src/reflection.cpp')
-rw-r--r--src/reflection.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/reflection.cpp b/src/reflection.cpp
index 35ae16fe..ab39e1e2 100644
--- a/src/reflection.cpp
+++ b/src/reflection.cpp
@@ -287,14 +287,17 @@ void SetString(const reflection::Schema &schema, const std::string &val,
const String *str, std::vector<uint8_t> *flatbuf,
const reflection::Object *root_table) {
auto delta = static_cast<int>(val.size()) - static_cast<int>(str->Length());
- auto start = static_cast<uoffset_t>(reinterpret_cast<const uint8_t *>(str) -
- flatbuf->data() +
- sizeof(uoffset_t));
+ auto str_start = static_cast<uoffset_t>(
+ reinterpret_cast<const uint8_t *>(str) - flatbuf->data());
+ auto start = str_start + sizeof(uoffset_t);
if (delta) {
// Clear the old string, since we don't want parts of it remaining.
memset(flatbuf->data() + start, 0, str->Length());
// Different size, we must expand (or contract).
ResizeContext(schema, start, delta, flatbuf, root_table);
+ // Set the new length.
+ WriteScalar(flatbuf->data() + str_start,
+ static_cast<uoffset_t>(val.size()));
}
// Copy new data. Safe because we created the right amount of space.
memcpy(flatbuf->data() + start, val.c_str(), val.size() + 1);