dualfroz cf25c2235d fix: do not corrupt state when Add/Set overshoots max
Add64 checked currentNum > max only after already mutating currentNum
and currentBytes, so a single call that overshoots max returned an
error but left the bar stuck: currentNum frozen above max, percent
stuck above 100%, and every later Add/Set call failing with the same
error forever, since the top-of-function currentNum < max guard could
never pass again.

Check the bound before mutating state instead, so an overshooting call
is rejected as a whole and leaves currentNum/currentBytes/currentPercent
exactly as they were. The now-unreachable post-hoc check is removed.

Add TestAddExceedsMaxDoesNotCorruptState covering the corrupted-state
case and that the bar keeps accepting valid progress afterwards.
2026-09-06 00:44:44 +02:00
S
Description
My contributions to schollz/progressbar: 2 commits
82 KiB
0 Stars 1 Watchers 0 Forks
Languages
Go 100%