- fbx: fix infinite recursion when parsing nested Scope's.

pull/14/head
Alexander Gessler 2012-06-26 03:31:34 +02:00
parent c9d9fcdfd1
commit ecd79b3cc3
2 changed files with 11 additions and 12 deletions

View File

@ -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<Token>());
}
#include <Windows.h>
// ------------------------------------------------------------------------------------------------
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);
}
// ------------------------------------------------------------------------------------------------

View File

@ -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<Scope> compound;
};