1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-01 08:39:44 +00:00

Guard an undefined behaviour

`std::vector.back()` on an empty `std::vector` is undefined.
This should fix #6725.

Thanks to @Capostrophic for the investigation.
This commit is contained in:
jvoisin 2023-05-20 19:21:32 +02:00
parent 5b36ea0179
commit 81bd034a9e

View file

@ -78,6 +78,9 @@ void ESM4::Header::load(ESM4::Reader& reader)
}
case ESM4::SUB_DATA:
{
if (mMaster.empty())
throw std::runtime_error(
"Failed to read TES4 DATA subrecord: there is no preceding MAST subrecord");
// WARNING: assumes DATA always follows MAST
if (!reader.getExact(mMaster.back().size))
throw std::runtime_error("TES4 DATA data read error");