Fixed crash related to flatc parsing duplicate input files.

Thanks @Chaosvex for reporting.

Change-Id: I73f60ab0bf875a3e0849eaec5f42f6d036881094
Tested: on Linux.
parent 947a5b4e
...@@ -419,7 +419,7 @@ class Parser { ...@@ -419,7 +419,7 @@ class Parser {
const char *source_, *cursor_; const char *source_, *cursor_;
int line_; // the current line being parsed int line_; // the current line being parsed
int token_; int token_;
std::stack<std::string> files_being_parsed_; std::string files_being_parsed_;
bool proto_mode_; bool proto_mode_;
bool strict_json_; bool strict_json_;
std::string attribute_; std::string attribute_;
......
...@@ -892,7 +892,7 @@ EnumDef &Parser::ParseEnum(bool is_union) { ...@@ -892,7 +892,7 @@ EnumDef &Parser::ParseEnum(bool is_union) {
Expect(kTokenIdentifier); Expect(kTokenIdentifier);
auto &enum_def = *new EnumDef(); auto &enum_def = *new EnumDef();
enum_def.name = enum_name; enum_def.name = enum_name;
if (!files_being_parsed_.empty()) enum_def.file = files_being_parsed_.top(); enum_def.file = files_being_parsed_;
enum_def.doc_comment = enum_comment; enum_def.doc_comment = enum_comment;
enum_def.is_union = is_union; enum_def.is_union = is_union;
enum_def.defined_namespace = namespaces_.back(); enum_def.defined_namespace = namespaces_.back();
...@@ -973,7 +973,7 @@ StructDef &Parser::StartStruct(const std::string &name) { ...@@ -973,7 +973,7 @@ StructDef &Parser::StartStruct(const std::string &name) {
if (!struct_def.predecl) Error("datatype already exists: " + name); if (!struct_def.predecl) Error("datatype already exists: " + name);
struct_def.predecl = false; struct_def.predecl = false;
struct_def.name = name; struct_def.name = name;
if (!files_being_parsed_.empty()) struct_def.file = files_being_parsed_.top(); struct_def.file = files_being_parsed_;
// Move this struct to the back of the vector just in case it was predeclared, // Move this struct to the back of the vector just in case it was predeclared,
// to preserve declaration order. // to preserve declaration order.
*remove(structs_.vec.begin(), structs_.vec.end(), &struct_def) = &struct_def; *remove(structs_.vec.begin(), structs_.vec.end(), &struct_def) = &struct_def;
...@@ -1352,11 +1352,11 @@ Type Parser::ParseTypeFromProtoType() { ...@@ -1352,11 +1352,11 @@ Type Parser::ParseTypeFromProtoType() {
bool Parser::Parse(const char *source, const char **include_paths, bool Parser::Parse(const char *source, const char **include_paths,
const char *source_filename) { const char *source_filename) {
files_being_parsed_ = source_filename ? source_filename : "";
if (source_filename && if (source_filename &&
included_files_.find(source_filename) == included_files_.end()) { included_files_.find(source_filename) == included_files_.end()) {
included_files_[source_filename] = true; included_files_[source_filename] = true;
files_included_per_file_[source_filename] = std::set<std::string>(); files_included_per_file_[source_filename] = std::set<std::string>();
files_being_parsed_.push(source_filename);
} }
if (!include_paths) { if (!include_paths) {
static const char *current_directory[] = { "", nullptr }; static const char *current_directory[] = { "", nullptr };
...@@ -1499,10 +1499,8 @@ bool Parser::Parse(const char *source, const char **include_paths, ...@@ -1499,10 +1499,8 @@ bool Parser::Parse(const char *source, const char **include_paths,
error_ += NumToString(line_) + ":0"; // gcc alike error_ += NumToString(line_) + ":0"; // gcc alike
#endif #endif
error_ += ": error: " + msg; error_ += ": error: " + msg;
if (source_filename) files_being_parsed_.pop();
return false; return false;
} }
if (source_filename) files_being_parsed_.pop();
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment