diff options
Diffstat (limited to 'internal/casino/machine.go')
| -rw-r--r-- | internal/casino/machine.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/internal/casino/machine.go b/internal/casino/machine.go index 0f137ec..844c5e9 100644 --- a/internal/casino/machine.go +++ b/internal/casino/machine.go @@ -228,8 +228,12 @@ func (m *Machine) finishSpin() []Event { events := []Event{} result := m.spin.Payout + m.payoutRemainder // Checked conversion: a runaway profile or overflow must clamp at the - // economy cap instead of wrapping through a machine-sized int. - if result > MaxCredits || result != result || result < 0 { + // economy cap instead of wrapping through a machine-sized int. A NaN or + // negative result is a corrupt computation, not a jackpot: clamp it to + // zero (fail closed) rather than up to the economy ceiling (fail open). + if math.IsNaN(result) || result < 0 { + result = 0 + } else if result > MaxCredits { result = MaxCredits } credits := int(math.Floor(result)) |
