]> git.tdb.fi Git - libs/datafile.git/commitdiff
More resiliece against certain corner cases when direct loading
authorMikko Rasa <tdb@tdb.fi>
Sun, 19 Oct 2014 08:58:00 +0000 (11:58 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 19 Oct 2014 08:58:00 +0000 (11:58 +0300)
An empty binary file terminated with __end was causing problems as the
very first peek call would return null, causing Loader to fall back to
indirect loading.  However, the __end was already processed by peek, so
the parse call would fail.

source/loader.cpp
source/parser.cpp

index e1a0d4abd7bcd80adfa4040c2a9bdf43ffb43ee7..d987a9e92fd646ce8812f9b827028d508d0601f5 100644 (file)
@@ -87,7 +87,7 @@ void Loader::load(Parser &p)
        {
                if(p.peek(0))
                        load_direct(p, 0);
-               else
+               else if(p)  // Peek may have processed an __end, so recheck goodness
                {
                        // Parse in raw mode so we can peek immediately after a mode change
                        Statement st = p.parse(true);
index 9ad70d8742884bfdfa40d5bebbc467b9e289afe7..a9bbbf22fe8ccb52cf8a60ede5d914f581fdcf04 100644 (file)
@@ -88,7 +88,7 @@ void Parser::process_control_statement(const Statement &st)
 
 const StatementKey *Parser::peek(unsigned level)
 {
-       while(1)
+       while(good)
        {
                const StatementKey *key = mode->peek(level);
                if(key && !key->keyword.compare(0, 2, "__"))
@@ -96,6 +96,8 @@ const StatementKey *Parser::peek(unsigned level)
                else
                        return key;
        }
+
+       return 0;
 }
 
 bool Parser::parse_and_load(unsigned level, Loader &ldr, const LoaderAction &act)