Skip to content

Commit

Permalink
Avoid division by zero
Browse files Browse the repository at this point in the history
In some environments, termbox returns the width as 0 causing a
segmentation fault when trying to calculate if the content fits
the terminal screen.

Avoid the division by zero for now while the specific conditions in
which this zero value is produced are clarified.
  • Loading branch information
Hector Oswaldo Caballero authored and tigrawap committed Jan 16, 2019
1 parent 88bec40 commit 4d4f92b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions slit.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ func (s *Slit) CanFitDisplay(ctx context.Context) bool {
termbox.Init()
w, h := termbox.Size()
termbox.Close()
if w == 0 || h == 0 {
return false
}
localCtx, cancel := context.WithCancel(ctx)
parsedLineCount := 0
lines := s.fetcher.Get(localCtx, Pos{})
Expand Down

0 comments on commit 4d4f92b

Please sign in to comment.