From db2381de7afffc932d051ec9fc853bfe06645060 Mon Sep 17 00:00:00 2001 From: Bil Bas (Spooner) Date: Thu, 19 Feb 2015 15:45:49 +0000 Subject: Correctly halt on error in sprintf parsing (fixes #1393) --- core/variant_op.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'core/variant_op.cpp') diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 21bbc8c7e..10b9a67da 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -738,18 +738,22 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant& _RETURN( p_a._data._int % p_b._data._int ); } else if (p_a.type==STRING) { - const String *str=reinterpret_cast(p_a._data._mem); + const String* format=reinterpret_cast(p_a._data._mem); + String result; + bool error; if (p_b.type==ARRAY) { // e.g. "frog %s %d" % ["fish", 12] - const Array *arr=reinterpret_cast(p_b._data._mem); - _RETURN(str->sprintf(*arr)); + const Array* args=reinterpret_cast(p_b._data._mem); + result=format->sprintf(*args, &error); } else { // e.g. "frog %d" % 12 - Array arr; - arr.push_back(p_b); - _RETURN(str->sprintf(arr)); + Array args; + args.push_back(p_b); + result=format->sprintf(args, &error); } + r_valid = !error; + _RETURN(result); } r_valid=false; -- cgit v1.2.3-70-g09d2