mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-04 17:06:25 +00:00
stdlib: fix SDL_strtol of "0" with base 0
SDL_strtol("0") skipped the "0" octal prefix and returned a failure because the remainder of the string was empty.
This commit is contained in:

committed by
Anonymous Maarten

parent
54752f8d1c
commit
b713e7581b
@@ -368,7 +368,7 @@ static size_t SDL_ScanUnsignedLongLongInternal(const char *text, int count, int
|
|||||||
negative = *text == '-';
|
negative = *text == '-';
|
||||||
++text;
|
++text;
|
||||||
}
|
}
|
||||||
if ((radix == 0 || radix == 16) && *text == '0') {
|
if ((radix == 0 || radix == 16) && *text == '0' && text[1] != '\0') {
|
||||||
++text;
|
++text;
|
||||||
if (*text == 'x' || *text == 'X') {
|
if (*text == 'x' || *text == 'X') {
|
||||||
radix = 16;
|
radix = 16;
|
||||||
|
@@ -1324,6 +1324,9 @@ static int SDLCALL stdlib_strtox(void *arg)
|
|||||||
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "-uvwxyz", 32, -991, 3);
|
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "-uvwxyz", 32, -991, 3);
|
||||||
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "ZzZzZzZzZzZzZzZzZzZzZzZzZ", 36, ullong_max, 25);
|
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "ZzZzZzZzZzZzZzZzZzZzZzZzZ", 36, ullong_max, 25);
|
||||||
|
|
||||||
|
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "0", 0, 0, 1);
|
||||||
|
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "0", 10, 0, 1);
|
||||||
|
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "-0", 0, 0, 2);
|
||||||
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "-0", 10, 0, 2);
|
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "-0", 10, 0, 2);
|
||||||
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, " - 1", 0, 0, 0); // invalid input
|
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, " - 1", 0, 0, 0); // invalid input
|
||||||
|
|
||||||
@@ -1335,6 +1338,10 @@ static int SDLCALL stdlib_strtox(void *arg)
|
|||||||
// Since the CI runs the tests against a variety of targets, this should be fine in practice.
|
// Since the CI runs the tests against a variety of targets, this should be fine in practice.
|
||||||
|
|
||||||
if (sizeof(long) == 4) {
|
if (sizeof(long) == 4) {
|
||||||
|
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "0", 0, 0, 1);
|
||||||
|
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "0", 10, 0, 1);
|
||||||
|
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "-0", 0, 0, 2);
|
||||||
|
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "-0", 10, 0, 2);
|
||||||
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "2147483647", 10, 2147483647, 10);
|
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "2147483647", 10, 2147483647, 10);
|
||||||
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "2147483648", 10, 2147483647, 10);
|
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "2147483648", 10, 2147483647, 10);
|
||||||
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "-2147483648", 10, -2147483647L - 1, 11);
|
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "-2147483648", 10, -2147483647L - 1, 11);
|
||||||
@@ -1347,6 +1354,10 @@ static int SDLCALL stdlib_strtox(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sizeof(long long) == 8) {
|
if (sizeof(long long) == 8) {
|
||||||
|
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "0", 0, 0LL, 1);
|
||||||
|
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "0", 10, 0LL, 1);
|
||||||
|
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "-0", 0, 0LL, 2);
|
||||||
|
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "-0", 10, 0LL, 2);
|
||||||
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "9223372036854775807", 10, 9223372036854775807LL, 19);
|
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "9223372036854775807", 10, 9223372036854775807LL, 19);
|
||||||
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "9223372036854775808", 10, 9223372036854775807LL, 19);
|
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "9223372036854775808", 10, 9223372036854775807LL, 19);
|
||||||
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "-9223372036854775808", 10, -9223372036854775807LL - 1, 20);
|
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "-9223372036854775808", 10, -9223372036854775807LL - 1, 20);
|
||||||
|
Reference in New Issue
Block a user