From f1aa796e610966d4ccda520cee5fd11a00123666 Mon Sep 17 00:00:00 2001 From: Tobias Guggenmos Date: Fri, 17 Jul 2020 20:59:01 +0200 Subject: [PATCH] Add missing nil pointer check 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 --- rest/api.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rest/api.go b/rest/api.go index 936113f2..0b5a898a 100644 --- a/rest/api.go +++ b/rest/api.go @@ -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] @@ -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]