1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Add UtilityClass::Int()

This is simply a wrapper function around SDL_atoi(), because SDL_atoi()
could call libc atoi(), and whether or not invalid input passed into the
libc atoi() is undefined behavior depends on the given libc. So it's
safer to just add a wrapper function that checks that the string given
isn't bogus.
This commit is contained in:
Misa 2020-08-06 21:28:51 -07:00 committed by Ethan Lee
parent 502d597aeb
commit 037065910f
2 changed files with 12 additions and 0 deletions

View file

@ -99,6 +99,16 @@ std::string UtilityClass::String( int _v )
return(os.str()); return(os.str());
} }
int UtilityClass::Int(const char* str)
{
if (!is_number(str))
{
return 0;
}
return SDL_atoi(str);
}
std::string UtilityClass::GCString(std::vector<SDL_GameControllerButton> buttons) std::string UtilityClass::GCString(std::vector<SDL_GameControllerButton> buttons)
{ {
std::string retval = ""; std::string retval = "";

View file

@ -37,6 +37,8 @@ public:
static std::string String(int _v); static std::string String(int _v);
static int Int(const char* str);
static std::string GCString(std::vector<SDL_GameControllerButton> buttons); static std::string GCString(std::vector<SDL_GameControllerButton> buttons);
std::string twodigits(int t); std::string twodigits(int t);