diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index da6d447ff4d11e0151b3203407a30da893650a5b..ffccdd7214009dda1df6bad2675b1049c5e92c2d 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -6440,10 +6440,8 @@ PUGI__NS_BEGIN
 	#endif
 	}
 
-	PUGI__FN bool convert_string_to_number(const char_t* begin, const char_t* end, double* out_result)
+	PUGI__FN bool convert_string_to_number(char_t (&buffer)[32], const char_t* begin, const char_t* end, double* out_result)
 	{
-		char_t buffer[32];
-
 		size_t length = static_cast<size_t>(end - begin);
 		char_t* scratch = buffer;
 
@@ -6736,10 +6734,8 @@ PUGI__NS_BEGIN
 		}
 	}
 
-	PUGI__FN xpath_variable* get_variable(xpath_variable_set* set, const char_t* begin, const char_t* end)
+	PUGI__FN xpath_variable* get_variable(char_t (&buffer)[32], xpath_variable_set* set, const char_t* begin, const char_t* end)
 	{
-		char_t buffer[32];
-
 		size_t length = static_cast<size_t>(end - begin);
 		char_t* scratch = buffer;
 
@@ -8730,6 +8726,8 @@ PUGI__NS_BEGIN
 
 		xpath_parse_result* _result;
 
+		char_t _scratch[32];
+
 	#ifdef PUGIXML_NO_EXCEPTIONS
 		jmp_buf _error_handler;
 	#endif
@@ -9018,7 +9016,7 @@ PUGI__NS_BEGIN
 				if (!_variables)
 					throw_error("Unknown variable: variable set is not provided");
 
-				xpath_variable* var = get_variable(_variables, name.begin, name.end);
+				xpath_variable* var = get_variable(_scratch, _variables, name.begin, name.end);
 
 				if (!var)
 					throw_error("Unknown variable: variable set does not contain the given name");
@@ -9056,7 +9054,7 @@ PUGI__NS_BEGIN
 			{
 				double value = 0;
 
-				if (!convert_string_to_number(_lexer.contents().begin, _lexer.contents().end, &value))
+				if (!convert_string_to_number(_scratch, _lexer.contents().begin, _lexer.contents().end, &value))
 					throw_error_oom();
 
 				xpath_ast_node* n = new (alloc_node()) xpath_ast_node(ast_number_constant, xpath_type_number, value);