Add crashes and fixes found during fuzzy testing

* Let unhandled exceptions propogate to user
 * Report eval_error when break statement is not in loop
 * Fix handling of 0 length scripts closes #193
 * Don't crash on arity mismatch - Specifically affects the case where no overloads exist for a given function
 * Fix error printing for `bind` calls
 * Handle unexpected continue statement
 * Check arity during bind
 * Don't allow arith conversion on variadic function
 * Correct `bind` parameter match count
 * Add in expected Boxed_Value exception cases
 * Check access to AST, don't allow `;` in func def
 * Don't attempt arithmetic unary & call
 * Don't crash on 0 param call to `bind`
 * Catch errors during member function dispatch
 * Properly handle type of const bool &
This commit is contained in:
Jason Turner
2015-07-13 14:44:26 -06:00
parent 2fbc377119
commit 1f72afc8f5
12 changed files with 203 additions and 97 deletions

View File

@@ -1117,11 +1117,22 @@ namespace chaiscript
AST_Node(std::move(t_ast_node_text), AST_Node_Type::File, std::move(t_loc), std::move(t_children)) { }
virtual ~File_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) const CHAISCRIPT_OVERRIDE {
const auto num_children = children.size();
for (size_t i = 0; i < num_children-1; ++i) {
children[i]->eval(t_ss);
try {
const auto num_children = children.size();
if (num_children > 0) {
for (size_t i = 0; i < num_children-1; ++i) {
children[i]->eval(t_ss);
}
return children.back()->eval(t_ss);
} else {
return Boxed_Value();
}
} catch (const detail::Continue_Loop &) {
throw exception::eval_error("Unexpected `continue` statement outside of a loop");
} catch (const detail::Break_Loop &) {
throw exception::eval_error("Unexpected `break` statement outside of a loop");
}
return children.back()->eval(t_ss);
}
};
@@ -1158,7 +1169,7 @@ namespace chaiscript
try {
// short circuit arithmetic operations
if (m_oper != Operators::invalid && bv.get_type_info().is_arithmetic())
if (m_oper != Operators::invalid && m_oper != Operators::bitwise_and && bv.get_type_info().is_arithmetic())
{
return Boxed_Number::do_oper(m_oper, bv);
} else {