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

Fix is_number() returning true for empty strings

Just like is_positive_num(), an empty string is not a number.

I've also decided to unroll iteration 0 of the loop here so readability
is improved; this happens to also knock out the whole "accepting empty
string" thing, too.
This commit is contained in:
Misa 2021-02-11 17:10:38 -08:00 committed by Ethan Lee
parent b9bf2be436
commit 7ea70ad1d6

View file

@ -267,9 +267,14 @@ void UtilityClass::updateglow()
bool is_number(const char* str)
{
for (int i = 0; str[i] != '\0'; i++)
if (!SDL_isdigit(str[0]) && str[0] != '-')
{
if (!SDL_isdigit(str[i]) && (i != 0 || str[0] != '-'))
return false;
}
for (int i = 1; str[i] != '\0'; i++)
{
if (!SDL_isdigit(str[i]))
{
return false;
}