From 9867e5fdf99d7d6c9d83846c11a1cee6a9919be1 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 2 Aug 2012 17:45:00 +0300 Subject: [PATCH] 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. --- source/binaryparser.cpp | 13 +++++++++---- source/type.h | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) 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 { -- 2.43.0