shithub: rgbds

Download patch

ref: d9b1402ef872edf36884670dbff30fdd2467efda
parent: 832e0ec972c2890bc08f36d546a17d187a348e40
author: ISSOtm <eldredhabert0@gmail.com>
date: Sat May 21 06:25:22 EDT 2022

Fix RGBGFX number parsing

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