From 94a78e385319b0c5971a03af9d077bd090948b12 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Mon, 8 Jun 2020 09:49:49 -0700 Subject: [PATCH] Fixed: Access violation and ASAN/UNSAN failures with sorted tables https://github.com/google/flatbuffers/issues/5945 --- src/idl_parser.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index d56a20920..1bafd9b1f 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -1355,8 +1355,8 @@ CheckedError Parser::ParseVector(const Type &type, uoffset_t *ovalue, // globals, making parsing thread-unsafe. // So for now, we use SimpleQsort above. // TODO: replace with something better, preferably not recursive. - static voffset_t offset = key->value.offset; - static BaseType ftype = key->value.type.base_type; + voffset_t offset = key->value.offset; + BaseType ftype = key->value.type.base_type; if (type.struct_def->fixed) { auto v = @@ -1364,7 +1364,7 @@ CheckedError Parser::ParseVector(const Type &type, uoffset_t *ovalue, SimpleQsort( v->Data(), v->Data() + v->size() * type.struct_def->bytesize, type.struct_def->bytesize, - [](const uint8_t *a, const uint8_t *b) -> bool { + [&](const uint8_t *a, const uint8_t *b) -> bool { return CompareType(a + offset, b + offset, ftype); }, [&](uint8_t *a, uint8_t *b) { @@ -1381,7 +1381,7 @@ CheckedError Parser::ParseVector(const Type &type, uoffset_t *ovalue, // can't be used to swap elements. SimpleQsort>( v->data(), v->data() + v->size(), 1, - [](const Offset *_a, const Offset
*_b) -> bool { + [&](const Offset
*_a, const Offset
*_b) -> bool { // Indirect offset pointer to table pointer. auto a = reinterpret_cast(_a) + ReadScalar(_a);