Skip to content

Commit

Permalink
Add missing nil pointer check
Browse files Browse the repository at this point in the history
Fixes #189.

This fixes some unchecked pointer accesses in the cache package.

Independently of how errors are handled, these checks should be in place.

Proper error handling as discussed in #189 and #181 can happen separately.

Signed-off-by: Tobias Guggenmos <[email protected]>
  • Loading branch information
slrtbtfs committed Jul 17, 2020
1 parent 4e7ee5f commit f1aa796
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions rest/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ func (a *API) diagnostics(w http.ResponseWriter, r *http.Request) {
return
}

items := diagnostics.Diagnostics
items := []protocol.Diagnostic{}
if diagnostics != nil {
items = diagnostics.Diagnostics
}

limit := requestData.Limit
if limit != nil && uint64(len(items)) > *limit {
items = items[:*limit]
Expand Down Expand Up @@ -204,7 +208,10 @@ func (a *API) completion(w http.ResponseWriter, r *http.Request) {
return
}

items := completion.Items
items := []protocol.CompletionItem{}
if completion != nil {
items = completion.Items
}
limit := requestData.Limit
if limit != nil && uint64(len(items)) > *limit {
items = items[:*limit]
Expand Down

0 comments on commit f1aa796

Please sign in to comment.