@@ -197,7 +197,8 @@ contains |
| 197 | 197 | type(json_value_t) :: diagnostics_array, diag_obj, range_obj |
| 198 | 198 | type(json_value_t) :: start_obj, end_obj |
| 199 | 199 | character(len=:), allocatable :: uri |
| 200 | | - integer :: i, n_diagnostics, file_idx, old_count, new_count, j |
| 200 | + integer :: i, n_diagnostics, file_idx, new_count, j |
| 201 | + integer :: old_count = 0 |
| 201 | 202 | type(diagnostic_t) :: diag |
| 202 | 203 | type(diagnostic_t), allocatable :: old_items(:) |
| 203 | 204 | |
@@ -210,7 +211,6 @@ contains |
| 210 | 211 | |
| 211 | 212 | ! First, remove any existing diagnostics from this server |
| 212 | 213 | if (allocated(store%files(file_idx)%items) .and. store%files(file_idx)%count > 0) then |
| 213 | | - old_count = 0 |
| 214 | 214 | ! Count diagnostics NOT from this server |
| 215 | 215 | do i = 1, store%files(file_idx)%count |
| 216 | 216 | if (store%files(file_idx)%items(i)%server_index /= server_index) then |
@@ -230,8 +230,6 @@ contains |
| 230 | 230 | end do |
| 231 | 231 | end if |
| 232 | 232 | deallocate(store%files(file_idx)%items) |
| 233 | | - else |
| 234 | | - old_count = 0 |
| 235 | 233 | end if |
| 236 | 234 | |
| 237 | 235 | ! Parse new diagnostics array |
@@ -249,7 +247,7 @@ contains |
| 249 | 247 | store%files(file_idx)%count = new_count |
| 250 | 248 | |
| 251 | 249 | ! Copy old diagnostics first |
| 252 | | - if (old_count > 0) then |
| 250 | + if (old_count > 0 .and. allocated(old_items)) then |
| 253 | 251 | store%files(file_idx)%items(1:old_count) = old_items(1:old_count) |
| 254 | 252 | deallocate(old_items) |
| 255 | 253 | end if |