Skip to content

Commit

Permalink
Add some paranoia checks in the GameDB
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 15, 2024
1 parent ddeb211 commit dc40530
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions Core/Util/GameDB.cpp
Expand Up @@ -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;
Expand All @@ -143,5 +146,6 @@ bool GameDB::GetGameInfos(std::string_view id, std::vector<GameDBInfo> *infos) {
}
}
}

return !infos->empty();
}
4 changes: 2 additions & 2 deletions UI/GameScreen.cpp
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit dc40530

Please sign in to comment.