Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens EventBase::checkEvents against undefined behavior / SIGFPE when converting a potentially huge floating-point forecast value to an integer, by clamping the computed ratio to the representable range of integer before casting.
Changes:
- Compute the pre-start forecast as a floating-point ratio
(m_beginTime - time) / dt. - Clamp that ratio to
[NumericLimits<integer>::min, NumericLimits<integer>::max]before casting tointeger. - Use the clamped
forecastvalue when callingsetForecast()to avoid overflow on conversion.
|
@dkachuma Why is this an integer? |
I can't say I fully understand this. From the use it appears that we are 'forecasting' if the event will be active at the next step ( @cssherman Maybe you know better how this value is used. |
|
@dkachuma it sounds like it can be a floating point value. |
This is a fix for the forecast set in
EventBase. Depending onm_beginTime,timeand ifdtis too small, the value of(m_beginTime - time)/dtmight be too large to be cast into an integer. On some systems this throws a floating point exception. This PR puts some checks so that we never overflow the integer.