diff --git a/gfx/2d/RecordingTypes.h b/gfx/2d/RecordingTypes.h index d80f7e6b4be0..ea94ee74f411 100644 --- a/gfx/2d/RecordingTypes.h +++ b/gfx/2d/RecordingTypes.h @@ -74,9 +74,16 @@ void ReadElement(S& aStream, T& aElement) { template void ReadElementConstrained(S& aStream, T& aElement, const T& aMinValue, const T& aMaxValue) { - ElementStreamFormat::Read(aStream, aElement); - if (aElement < aMinValue || aElement > aMaxValue) { + std::underlying_type_t value = 0; + ReadElement(aStream, value); + + auto minInt = static_cast>(aMinValue); + auto maxInt = static_cast>(aMaxValue); + + if (value < minInt || value > maxInt) { aStream.SetIsBad(); + } else { + aElement = static_cast(value); } } template