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 fa99a7e..fd91875 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 701a5dc..5876628 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
 {