From ecd79b3cc37ac578dd537e45bfe413b3e31ea1ab Mon Sep 17 00:00:00 2001 From: Alexander Gessler Date: Tue, 26 Jun 2012 03:31:34 +0200 Subject: [PATCH] - fbx: fix infinite recursion when parsing nested Scope's. --- code/FBXParser.cpp | 18 +++++++++++------- code/FBXParser.h | 5 ----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/code/FBXParser.cpp b/code/FBXParser.cpp index 338fbba70..fb9628f3e 100644 --- a/code/FBXParser.cpp +++ b/code/FBXParser.cpp @@ -90,16 +90,19 @@ Element::Element(Parser& parser) if (n->Type() == TokenType_OPEN_BRACKET) { compound.reset(new Scope(parser)); - // compound scopes must appear at the end of an element, so TOK_CLOSE_BRACKET should be next + // current token should be a TOK_CLOSE_BRACKET n = parser.CurrentToken(); ai_assert(n); if (n->Type() != TokenType_CLOSE_BRACKET) { ParseError("expected closing bracket",n); } + + parser.AdvanceToNextToken(); + return; } } - while(n->Type() != TokenType_KEY); + while(n->Type() != TokenType_KEY && n->Type() != TokenType_CLOSE_BRACKET); } // ------------------------------------------------------------------------------------------------ @@ -107,7 +110,7 @@ Element::~Element() { std::for_each(tokens.begin(),tokens.end(),Util::delete_fun()); } - +#include // ------------------------------------------------------------------------------------------------ Scope::Scope(Parser& parser,bool topLevel) { @@ -123,14 +126,16 @@ Scope::Scope(Parser& parser,bool topLevel) ParseError("unexpected end of file",NULL); } - do { + // note: empty scopes are allowed + while(n->Type() != TokenType_CLOSE_BRACKET) { if (n->Type() != TokenType_KEY) { ParseError("unexpected token, expected TOK_KEY",n); } - elements.insert(ElementMap::value_type(n->StringContents(),new_Element(parser))); + const std::string& str = n->StringContents(); + elements.insert(ElementMap::value_type(str,new_Element(parser))); - // Element() should stop at the next Key (or Close) token + // Element() should stop at the next Key token (or right after a Close token) n = parser.CurrentToken(); if(n == NULL) { if (topLevel) { @@ -139,7 +144,6 @@ Scope::Scope(Parser& parser,bool topLevel) ParseError("unexpected end of file",parser.LastToken()); } } - while(n->Type() != TokenType_CLOSE_BRACKET); } // ------------------------------------------------------------------------------------------------ diff --git a/code/FBXParser.h b/code/FBXParser.h index 4b3852055..086608b28 100644 --- a/code/FBXParser.h +++ b/code/FBXParser.h @@ -90,17 +90,12 @@ public: public: - const std::string& Key() const { - return key; - } - const TokenList& Tokens() const { return tokens; } private: - std::string key; TokenList tokens; boost::scoped_ptr compound; };