From: Mikko Rasa Date: Thu, 2 Aug 2012 14:45:00 +0000 (+0300) Subject: More senseful validity checks for keyword and string definitions X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9867e5fdf99d7d6c9d83846c11a1cee6a9919be1;p=libs%2Fdatafile.git More senseful validity checks for keyword and string definitions 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. --- diff --git a/source/binaryparser.cpp b/source/binaryparser.cpp index fa99a7e..fd91875 100644 --- a/source/binaryparser.cpp +++ b/source/binaryparser.cpp @@ -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(); + if(id<=0) throw bad_definition("__kwd"); - const int id = st.args[0].get(); const string &kw = st.args[1].get(); const string &args = st.args[2].get(); + 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(); + if(id<=0) throw bad_definition("__str"); - const unsigned id = st.args[0].get(); strings[id] = st.args[1].get(); } else if(st.keyword=="__flt") diff --git a/source/type.h b/source/type.h index 701a5dc..5876628 100644 --- a/source/type.h +++ b/source/type.h @@ -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 struct HasLoadType {