Ensure that Volume::GetRegion doesn't return invalid enum values

This commit is contained in:
JosJuice 2017-07-16 14:52:17 +02:00
parent db1c534b3e
commit be8e93f472
2 changed files with 8 additions and 2 deletions

View File

@ -61,7 +61,10 @@ std::string VolumeGC::GetGameID(const Partition& partition) const
Region VolumeGC::GetRegion() const
{
const std::optional<u32> region_code = ReadSwapped<u32>(0x458, PARTITION_NONE);
return region_code ? static_cast<Region>(*region_code) : Region::UNKNOWN_REGION;
if (!region_code)
return Region::UNKNOWN_REGION;
const Region region = static_cast<Region>(*region_code);
return region <= Region::PAL ? region : Region::UNKNOWN_REGION;
}
Country VolumeGC::GetCountry(const Partition& partition) const

View File

@ -233,7 +233,10 @@ std::string VolumeWii::GetGameID(const Partition& partition) const
Region VolumeWii::GetRegion() const
{
const std::optional<u32> region_code = m_pReader->ReadSwapped<u32>(0x4E000);
return region_code ? static_cast<Region>(*region_code) : Region::UNKNOWN_REGION;
if (!region_code)
return Region::UNKNOWN_REGION;
const Region region = static_cast<Region>(*region_code);
return region <= Region::NTSC_K ? region : Region::UNKNOWN_REGION;
}
Country VolumeWii::GetCountry(const Partition& partition) const