Add some paranoia checks in the GameDB

This commit is contained in:
Henrik Rydgård committed 2024-01-15 10:47:16 +01:00
1 parent ddeb2112cc
commit dc4053095a
2 files changed
+9 -5

No files matched your search

+7 -3
View File
@@ -127,14 +127,17 @@ bool GameDB::GetGameInfos(std::string_view id, std::vector<GameDBInfo> *infos) {
}
for (auto &line : lines_) {
for (auto serial : line.serials) {
for (auto &serial : line.serials) {
// Ignore version and stuff for now
if (IDMatches(id, serial)) {
GameDBInfo info;
if (1 != sscanf(line.crc.data(), "%08x", &info.crc)) {
// zero-terminate before sscanf
std::string crc(line.crc);
if (1 != sscanf(crc.c_str(), "%08x", &info.crc)) {
continue;
}
if (1 != sscanf(line.size.data(), "%llu", (long long *)&info.size)) {
std::string size(line.size);
if (1 != sscanf(size.c_str(), "%llu", (long long *)&info.size)) {
continue;
}
info.title = line.title;
@@ -143,5 +146,6 @@ bool GameDB::GetGameInfos(std::string_view id, std::vector<GameDBInfo> *infos) {
}
}
}
return !infos->empty();
}
+2 -2
View File
@@ -343,7 +343,7 @@ ScreenRenderFlags GameScreen::render(ScreenRenderMode mode) {
// Let's check the CRC in the game database, looking up the ID and also matching the crc.
std::vector<GameDBInfo> dbInfos;
if (tvVerified_ && g_gameDB.GetGameInfos(info->id_version, &dbInfos)) {
if (tvVerified_ && !info->id_version.empty() && g_gameDB.GetGameInfos(info->id_version, &dbInfos)) {
bool found = false;
for (auto &dbInfo : dbInfos) {
if (dbInfo.crc == crcVal) {
@@ -368,7 +368,7 @@ ScreenRenderFlags GameScreen::render(ScreenRenderMode mode) {
GameDBInfo dbInfo;
if (tvVerified_) {
std::vector<GameDBInfo> dbInfos;
if (!g_gameDB.GetGameInfos(info->id_version, &dbInfos)) {
if (!info->id_version.empty() && !g_gameDB.GetGameInfos(info->id_version, &dbInfos)) {
// tvVerified_->SetText(ga->T("Game ID unknown - not in the ReDump database"));
// tvVerified_->SetVisibility(UI::V_VISIBLE);
// tvVerified_->SetLevel(NoticeLevel::WARN);