Skip to content

Commit f1aa796

Browse files
committed
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 <[email protected]>
1 parent 4e7ee5f commit f1aa796

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Diff for: rest/api.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ func (a *API) diagnostics(w http.ResponseWriter, r *http.Request) {
140140
return
141141
}
142142

143-
items := diagnostics.Diagnostics
143+
items := []protocol.Diagnostic{}
144+
if diagnostics != nil {
145+
items = diagnostics.Diagnostics
146+
}
147+
144148
limit := requestData.Limit
145149
if limit != nil && uint64(len(items)) > *limit {
146150
items = items[:*limit]
@@ -204,7 +208,10 @@ func (a *API) completion(w http.ResponseWriter, r *http.Request) {
204208
return
205209
}
206210

207-
items := completion.Items
211+
items := []protocol.CompletionItem{}
212+
if completion != nil {
213+
items = completion.Items
214+
}
208215
limit := requestData.Limit
209216
if limit != nil && uint64(len(items)) > *limit {
210217
items = items[:*limit]

0 commit comments

Comments
 (0)