Skip to content

Commit

Permalink
fix: Protect RenderBlank() and IsFinished() with the lock
Browse files Browse the repository at this point in the history
RenderBlank() calls render() which requires the mutex to be held. IsFinished accesses p.state, which also requires the mutex to be held
  • Loading branch information
RichieSams committed Jul 28, 2023
1 parent 3d12297 commit 31e9c17
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions progressbar.go
Expand Up @@ -456,6 +456,9 @@ func (p *ProgressBar) String() string {

// RenderBlank renders the current bar state, you can use this to render a 0% state
func (p *ProgressBar) RenderBlank() error {
p.lock.Lock()
defer p.lock.Unlock()

if p.config.invisible {
return nil
}
Expand Down Expand Up @@ -628,6 +631,9 @@ func (p *ProgressBar) ChangeMax64(newMax int64) {

// IsFinished returns true if progress bar is completed
func (p *ProgressBar) IsFinished() bool {
p.lock.Lock()
defer p.lock.Unlock()

return p.state.finished
}

Expand Down

0 comments on commit 31e9c17

Please sign in to comment.