sw_engine: prevent NaN in gradient pixel calculations

Add std::isfinite() check in _pixel() to prevent undefined behavior when NaN values are cast to int32_t. This prevents potential crashes during gradient color table indexing.

NaN can occur from:
- Division by zero in radial gradient calculations
- Negative values passed to sqrtf() in radial gradient determinant
This commit is contained in:
Jinny You 2025-07-25 01:03:24 +09:00
parent 9369642642
commit c9fb28402a

View file

@ -308,6 +308,7 @@ static inline uint32_t _fixedPixel(const SwFill* fill, int32_t pos)
static inline uint32_t _pixel(const SwFill* fill, float pos)
{
if (!std::isfinite(pos)) pos = 0;
auto i = static_cast<int32_t>(pos * (GRADIENT_STOP_SIZE - 1) + 0.5f);
return fill->ctable[_clamp(fill, i)];
}