Fix RGBGFX number parsing

This commit is contained in:
ISSOtm
2022-05-21 10:25:22 +02:00
committed by Eldred Habert
parent 832e0ec972
commit d9b1402ef8

View File

@@ -204,13 +204,13 @@ static uint16_t parseNumber(char *&string, char const *errPrefix, uint16_t errVa
uint16_t number = 0; uint16_t number = 0;
do { do {
// Read a character, and check if it's valid in the given base // Read a character, and check if it's valid in the given base
number *= base;
uint8_t index = charIndex(*string); uint8_t index = charIndex(*string);
if (index == 255) { if (index == 255) {
break; // Found an invalid character, end break; // Found an invalid character, end
} }
++string; ++string;
number *= base;
number += index; number += index;
// The lax check covers the addition on top of the multiplication // The lax check covers the addition on top of the multiplication
if (number >= UINT16_MAX / base) { if (number >= UINT16_MAX / base) {
@@ -223,7 +223,7 @@ static uint16_t parseNumber(char *&string, char const *errPrefix, uint16_t errVa
} }
static void skipWhitespace(char *&arg) { static void skipWhitespace(char *&arg) {
arg += strcspn(arg, " \t"); arg += strspn(arg, " \t");
} }
static void registerInput(char const *arg) { static void registerInput(char const *arg) {
@@ -349,6 +349,7 @@ static char *parseArgv(int argc, char **argv, bool &autoAttrmap, bool &autoTilem
musl_optarg); musl_optarg);
break; break;
} }
++arg; // Skip comma
skipWhitespace(arg); skipWhitespace(arg);
options.baseTileIDs[1] = parseNumber(arg, "Bank 1 base tile ID", 0); options.baseTileIDs[1] = parseNumber(arg, "Bank 1 base tile ID", 0);
if (options.baseTileIDs[1] >= 256) { if (options.baseTileIDs[1] >= 256) {
@@ -412,6 +413,7 @@ static char *parseArgv(int argc, char **argv, bool &autoAttrmap, bool &autoTilem
musl_optarg); musl_optarg);
break; break;
} }
++arg; // Skip comma
skipWhitespace(arg); skipWhitespace(arg);
options.maxNbTiles[1] = parseNumber(arg, "Number of tiles in bank 1", 256); options.maxNbTiles[1] = parseNumber(arg, "Number of tiles in bank 1", 256);
if (options.maxNbTiles[1] > 256) { if (options.maxNbTiles[1] > 256) {