Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
lint/lintutil/format: avoid panic in Stylish if first Position to rep…
Browse files Browse the repository at this point in the history
…ort is empty

Pointer tw was not initialised before use, if the first call to Format
was with an empty Position, leading to panic. This change forces the
Filename to be something ("-"), to avoid that.

Closes: dominikhgh-383 [via git-merge-pr]
  • Loading branch information
helloPiers authored and dominikh committed Jan 6, 2019
1 parent f72fdd6 commit 3f1c825
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lint/lintutil/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ type Stylish struct {
}

func (o *Stylish) Format(p lint.Problem) {
if p.Position.Filename == "" {
p.Position.Filename = "-"
}

if p.Position.Filename != o.prevFile {
if o.prevFile != "" {
o.tw.Flush()
Expand Down

0 comments on commit 3f1c825

Please sign in to comment.