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.
This commit is contained in:
Misa authored and Ethan Lee committed 2020-02-20 00:05:55 -05:00
1 parent 0531ee9b19
commit ea8053303d
1 file changed
+1 -1
+1 -1
View File
@@ -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;
}