diff --git a/components/nif/recordptr.hpp b/components/nif/recordptr.hpp index 5b890eec54..eb704dbc21 100644 --- a/components/nif/recordptr.hpp +++ b/components/nif/recordptr.hpp @@ -1,9 +1,10 @@ #ifndef OPENMW_COMPONENTS_NIF_RECORDPTR_HPP #define OPENMW_COMPONENTS_NIF_RECORDPTR_HPP +#include + #include "niffile.hpp" #include "nifstream.hpp" -#include namespace Nif { @@ -39,7 +40,7 @@ namespace Nif assert(index == -2); // Store the index for later - index = nif->getInt(); + index = nif->get(); assert(index >= -1); } @@ -90,12 +91,13 @@ namespace Nif template void readRecordList(NIFStream* nif, RecordListT& list) { - const int length = nif->getInt(); + const std::uint32_t length = nif->get(); - if (length < 0) - throw std::runtime_error("Negative NIF record list length: " + std::to_string(length)); + // No reasonable list can hit this generous limit + if (length >= (1 << 24)) + throw std::runtime_error("Record list too long: " + std::to_string(length)); - list.resize(static_cast(length)); + list.resize(length); for (auto& value : list) value.read(nif);