From 2107a7d5142f0b47bd22fc7581dea1abe9c1e61f Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Wed, 28 Oct 2015 17:40:33 -0700 Subject: [PATCH] Fixed assert in flatc converting to text. Change-Id: Idac375b22aa9beaba162084cc3396f5536a4e721 Tested: on Linux. --- include/flatbuffers/flatbuffers.h | 5 +++++ src/flatc.cpp | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index e7100e31c..41b3b266c 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -582,6 +582,11 @@ class FlatBufferBuilder FLATBUFFERS_FINAL_CLASS { buf_.fill(PaddingBytes(buf_.size(), elem_size)); } + void PushFlatBuffer(const uint8_t *bytes, size_t size) { + PushBytes(bytes, size); + finished = true; + } + void PushBytes(const uint8_t *bytes, size_t size) { buf_.push(bytes, size); } diff --git a/src/flatc.cpp b/src/flatc.cpp index e3c74d2e2..b7bc7d9ac 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -98,7 +98,7 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) { " also implies --no-prefix.\n" " --gen-includes (deprecated), this is the default behavior.\n" " If the original behavior is required (no include\n" - " statements) use --no-includes.\n" + " statements) use --no-includes.\n" " --no-includes Don\'t generate include statements for included\n" " schemas the generated file depends on (C++).\n" " --gen-mutable Generate accessors that can mutate buffers in-place.\n" @@ -201,13 +201,13 @@ int main(int argc, const char *argv[]) { ++file_it) { std::string contents; if (!flatbuffers::LoadFile(file_it->c_str(), true, &contents)) - Error("unable to load file" + *file_it); + Error("unable to load file: " + *file_it); bool is_binary = static_cast(file_it - filenames.begin()) >= binary_files_from; if (is_binary) { parser.builder_.Clear(); - parser.builder_.PushBytes( + parser.builder_.PushFlatBuffer( reinterpret_cast(contents.c_str()), contents.length()); if (!raw_binary) {