]> git.tdb.fi Git - libs/datafile.git/commitdiff
More senseful validity checks for keyword and string definitions
authorMikko Rasa <tdb@tdb.fi>
Thu, 2 Aug 2012 14:45:00 +0000 (17:45 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 2 Aug 2012 14:45:00 +0000 (17:45 +0300)
I don't see how the original conditions could ever have been triggered,
given that arguments are parsed based on the signature, and those of the
built-in statements are fixed.

source/binaryparser.cpp
source/type.h

index fa99a7e47708ba3c1d4991c16d605d9ae77c7b28..fd918758294fd6c1d66ac497af5d5674d629c691 100644 (file)
@@ -39,20 +39,25 @@ Statement BinaryParser::parse()
                Statement st = parse_statement();
                if(st.keyword=="__kwd")
                {
-                       if(st.args.size()!=3)
+                       int id = st.args[0].get<int>();
+                       if(id<=0)
                                throw bad_definition("__kwd");
 
-                       const int id = st.args[0].get<unsigned>();
                        const string &kw = st.args[1].get<const string &>();
                        const string &args = st.args[2].get<const string &>();
+                       for(string::const_iterator i=args.begin(); i!=args.end(); ++i)
+                               for(unsigned j=0; valid_signatures[j]!=*i; ++j)
+                                       if(!valid_signatures[j])
+                                               throw bad_definition("__kwd");
+
                        dict[id] = DictEntry(kw, args);
                }
                else if(st.keyword=="__str")
                {
-                       if(st.args.size()!=2)
+                       int id = st.args[0].get<int>();
+                       if(id<=0)
                                throw bad_definition("__str");
 
-                       const unsigned id = st.args[0].get<unsigned>();
                        strings[id] = st.args[1].get<const string &>();
                }
                else if(st.keyword=="__flt")
index 701a5dc9786533f930e6c49778988f6816f83189..58766289bc172a0e214917c961452976fac5645e 100644 (file)
@@ -52,6 +52,16 @@ struct SymbolType
        typedef Symbol Store;
 };
 
+const char valid_signatures[] =
+{
+       IntType::signature,
+       FloatType::signature,
+       BoolType::signature,
+       StringType::signature,
+       SymbolType::signature,
+       0
+};
+
 template<typename T>
 struct HasLoadType
 {