Work around an MSVCRT limitation, fixes cheat import on SDL Windows, fixes #716

This commit is contained in:
Lior Halphon
2025-08-03 16:54:04 +03:00
parent 20e5e18122
commit 5b88346537

View File

@@ -155,8 +155,15 @@ const GB_cheat_t *GB_import_cheat(GB_gameboy_t *gb, const char *cheat, const cha
uint8_t dummy;
/* GameShark */
if (strlen(cheat) == 8) {
#ifdef _WIN32
// The hh modifier is not supported on old MSVCRT, it's completely ignored
uint32_t bank = 0;
uint32_t value = 0;
#pragma GCC diagnostic ignored "-Wformat"
#else
uint8_t bank;
uint8_t value;
#endif
uint16_t address;
if (sscanf(cheat, "%02hhx%02hhx%04hx%c", &bank, &value, &address, &dummy) == 3) {
address = __builtin_bswap16(address);
@@ -178,8 +185,13 @@ const GB_cheat_t *GB_import_cheat(GB_gameboy_t *gb, const char *cheat, const cha
stripped_cheat[7] = stripped_cheat[8];
stripped_cheat[8] = 0;
#ifdef _WIN32
uint32_t old_value = 0;
uint32_t value = 0;
#else
uint8_t old_value;
uint8_t value;
#endif
uint16_t address;
if (strlen(stripped_cheat) != 8 && strlen(stripped_cheat) != 6) {
return NULL;