Bug 1990085 - Improve enum serialization in gfx. r=lsalzman a=RyanVM

Differential Revision: https://phabricator.services.mozilla.com/D266443
This commit is contained in:
Christian Holler (:decoder)
2025-09-26 19:53:38 +00:00
committed by rvandermeulen@mozilla.com
parent dd172dd5bf
commit c6927dad6d

View File

@@ -74,9 +74,16 @@ void ReadElement(S& aStream, T& aElement) {
template <class S, class T> template <class S, class T>
void ReadElementConstrained(S& aStream, T& aElement, const T& aMinValue, void ReadElementConstrained(S& aStream, T& aElement, const T& aMinValue,
const T& aMaxValue) { const T& aMaxValue) {
ElementStreamFormat<S, T>::Read(aStream, aElement); std::underlying_type_t<T> value = 0;
if (aElement < aMinValue || aElement > aMaxValue) { ReadElement(aStream, value);
auto minInt = static_cast<std::underlying_type_t<T>>(aMinValue);
auto maxInt = static_cast<std::underlying_type_t<T>>(aMaxValue);
if (value < minInt || value > maxInt) {
aStream.SetIsBad(); aStream.SetIsBad();
} else {
aElement = static_cast<T>(value);
} }
} }
template <class S, class T> template <class S, class T>