Skip to content

Commit

Permalink
gopls/internal/util/frob: Decode: improve panic on empty
Browse files Browse the repository at this point in the history
Also, add justification for fall through.

Updates golang/go#71244

Change-Id: I781d015a9d4659815588e95dea92eb350388b925
Reviewed-on: https://go-review.googlesource.com/c/tools/+/642435
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
adonovan committed Jan 13, 2025
1 parent 0b95e04 commit 1335f05
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions gopls/internal/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@ func (s *Snapshot) typerefData(ctx context.Context, id PackageID, imports map[Im
return data, nil
} else if err != filecache.ErrNotFound {
bug.Reportf("internal error reading typerefs data: %v", err)
// Unexpected error: treat as cache miss, and fall through.
}

pgfs, err := s.view.parseCache.parseFiles(ctx, token.NewFileSet(), parsego.Full&^parser.ParseComments, true, cgfs...)
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/util/frob/frob.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ func (fr *frob) Decode(data []byte, ptr any) {
panic(fmt.Sprintf("got %v, want %v", rv.Type(), fr.t))
}
rd := &reader{data}
if string(rd.bytes(4)) != magic {
panic("not a frob-encoded message")
if len(data) < len(magic) || string(rd.bytes(len(magic))) != magic {
panic("not a frob-encoded message") // (likely an empty message)
}
fr.decode(rd, rv)
if len(rd.data) > 0 {
Expand Down

0 comments on commit 1335f05

Please sign in to comment.