]> git.tdb.fi Git - libs/datafile.git/commitdiff
Fix logic problems when ignoring a statement in the middle of direct load
authorMikko Rasa <tdb@tdb.fi>
Thu, 19 Dec 2013 21:58:53 +0000 (23:58 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 19 Dec 2013 21:58:53 +0000 (23:58 +0200)
Each recursive call to parse() was subtracting one from sub_remaining,
causing it to get out of sync with the actual statement hierarchy.

source/binaryparser.cpp

index 051133f79a32cecb540c021f87b6930f5e168566..e2ced82098e7b1472944dd4a2b626bef32211459 100644 (file)
@@ -48,7 +48,10 @@ Statement BinaryParser::parse()
 {
        const StatementKey *key;
        if(cur_info)
+       {
                key = &cur_info->key;
+               cur_info = 0;
+       }
        else
        {
                int id = parse_int();
@@ -84,15 +87,16 @@ Statement BinaryParser::parse()
                }
        }
 
-       if(!sub_remaining.empty())
-               --sub_remaining.back();
+       unsigned upper_nsub = (sub_remaining.empty() ? 0 : sub_remaining.back());
 
        unsigned nsub = parse_int();
        for(unsigned j = 0; j<nsub; ++j)
                result.sub.push_back(parse());
 
+       if(upper_nsub>0)
+               sub_remaining.back() = upper_nsub-1;
+
        result.valid = true;
-       cur_info = 0;
 
        return result;
 }