Core: Fix GBK string memory handling in .cht loading

This commit is contained in:
Vicki Pfau 2023-03-01 20:32:18 -08:00
parent bc048094b1
commit a2072b67ba
1 changed files with 8 additions and 3 deletions

View File

@ -489,8 +489,10 @@ bool mCheatParseEZFChtFile(struct mCheatDevice* device, struct VFile* vf) {
return false;
}
char* name = gbkToUtf8(&cheat[1], end - cheat - 1);
strncpy(cheatName, name, sizeof(cheatName) - 1);
free(name);
if (name) {
strncpy(cheatName, name, sizeof(cheatName) - 1);
free(name);
}
cheatNameLength = strlen(cheatName);
continue;
}
@ -501,7 +503,10 @@ bool mCheatParseEZFChtFile(struct mCheatDevice* device, struct VFile* vf) {
}
if (strncmp(cheat, "ON", eq - cheat) != 0) {
char* subname = gbkToUtf8(cheat, eq - cheat);
snprintf(&cheatName[cheatNameLength], sizeof(cheatName) - cheatNameLength - 1, ": %s", subname);
if (subname) {
snprintf(&cheatName[cheatNameLength], sizeof(cheatName) - cheatNameLength - 1, ": %s", subname);
free(subname);
}
}
set = device->createSet(device, cheatName);
set->enabled = false;