Issue #2713 - Check for NaN before std::min/max() in DOMQuad and DOMRect.

If there is a NaN involved we should not return 0 here.
This commit is contained in:
Moonchild 2025-03-22 20:15:52 +01:00 committed by roytam1
commit f1c456c625
3 changed files with 35 additions and 10 deletions

View file

@ -14,6 +14,7 @@
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Types.h"
#include <algorithm>
#include <stdint.h>
namespace mozilla {
@ -450,6 +451,30 @@ EqualOrBothNaN(T aValue1, T aValue2)
return aValue1 == aValue2;
}
/**
* Return NaN if either |aValue1| or |aValue2| is NaN, or the minimum of
* |aValue1| and |aValue2| otherwise.
*/
template <typename T>
static inline T NaNSafeMin(T aValue1, T aValue2) {
if (IsNaN(aValue1) || IsNaN(aValue2)) {
return UnspecifiedNaN<T>();
}
return std::min(aValue1, aValue2);
}
/**
* Return NaN if either |aValue1| or |aValue2| is NaN, or the maximum of
* |aValue1| and |aValue2| otherwise.
*/
template <typename T>
static inline T NaNSafeMax(T aValue1, T aValue2) {
if (IsNaN(aValue1) || IsNaN(aValue2)) {
return UnspecifiedNaN<T>();
}
return std::max(aValue1, aValue2);
}
namespace detail {
template<typename T>