Skip to content

Commit

Permalink
Fixed reflection resizing code not checking strings in vectors.
Browse files Browse the repository at this point in the history
Change-Id: I4081160a8281939ab282d7914ae396276c767882
Tested: on Linux.
  • Loading branch information
Wouter van Oortmerssen committed Jul 22, 2015
1 parent f66e93c commit b6380ac
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions include/flatbuffers/reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,18 +354,22 @@ class ResizeContext {
break;
}
case reflection::Vector: {
if (fielddef.type()->element() != reflection::Obj) break;
auto elem_type = fielddef.type()->element();
if (elem_type != reflection::Obj && elem_type != reflection::String)
break;
auto vec = reinterpret_cast<Vector<uoffset_t> *>(ref);
auto elemobjectdef =
schema_.objects()->Get(fielddef.type()->index());
if (elemobjectdef->is_struct()) break;
auto elemobjectdef = elem_type == reflection::Obj
? schema_.objects()->Get(fielddef.type()->index())
: nullptr;
if (elemobjectdef && elemobjectdef->is_struct()) break;
for (uoffset_t i = 0; i < vec->size(); i++) {
auto loc = vec->Data() + i * sizeof(uoffset_t);
if (DagCheck(loc))
continue; // This offset already visited.
auto dest = loc + vec->Get(i);
Straddle<uoffset_t, 1>(loc, dest ,loc);
ResizeTable(*elemobjectdef, reinterpret_cast<Table *>(dest));
if (elemobjectdef)
ResizeTable(*elemobjectdef, reinterpret_cast<Table *>(dest));
}
break;
}
Expand Down

0 comments on commit b6380ac

Please sign in to comment.