From ea8053303d8acef00824152f483aef2ee5954770 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 19 Feb 2020 20:58:12 -0800 Subject: [PATCH] Initialize x to 0 in ss_toi() This fixes a source of undefined behavior, where the int returned by ss_toi() would be random garbage memory if the string passed into it would be empty. That's because if the string is empty, there are no characters to parse, so nothing simply gets put into x. The easiest way to pass an empty string in to ss_toi() would be to use script commands with empty arguments. --- desktop_version/src/UtilityClass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop_version/src/UtilityClass.cpp b/desktop_version/src/UtilityClass.cpp index 638a4444..f5ac0d20 100644 --- a/desktop_version/src/UtilityClass.cpp +++ b/desktop_version/src/UtilityClass.cpp @@ -58,7 +58,7 @@ const char *GCChar(SDL_GameControllerButton button) int ss_toi( std::string _s ) { std::istringstream i(_s); - int x; + int x = 0; i >> x; return x; }