Skip to content

Commit f2df9cd

Browse files
committed
bpp-lsp: ProgramPool: Verify parsing was successful before changing pool state
This prevents crashes which may come from storing 'nullptr' parse results in the program pool's state, and later (unthinkingly) using them as if they were valid pointers. It also prevents us from losing diagnostic information about programs which have been parsed, which have also undergone incomplete updates that can't yet be fully re-parsed
1 parent 8add037 commit f2df9cd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/lsp/ProgramPool.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ std::shared_ptr<bpp::bpp_program> ProgramPool::re_parse_program(const std::strin
202202
if (has_program(file_path)) {
203203
size_t index = program_indices[file_path];
204204
std::string main_source_file = programs[index]->get_main_source_file();
205+
206+
auto new_program = _parse_program(main_source_file);
207+
if (new_program == nullptr) {
208+
return nullptr; // Return nullptr if parsing fails
209+
}
210+
205211
programs[index] = _parse_program(main_source_file);
206212
open_files[file_path] = true; // Mark the file as open
207213

@@ -221,6 +227,13 @@ std::shared_ptr<bpp::bpp_program> ProgramPool::re_parse_program(
221227
if (has_program(file_path)) {
222228
size_t index = program_indices[file_path];
223229
std::string main_source_file = programs[index]->get_main_source_file();
230+
231+
auto new_program = _parse_program(main_source_file, replacement_file_contents);
232+
233+
if (new_program == nullptr) {
234+
return nullptr; // Return nullptr if parsing fails
235+
}
236+
224237
programs[index] = _parse_program(main_source_file, replacement_file_contents);
225238
open_files[file_path] = true; // Mark the file as open
226239

0 commit comments

Comments
 (0)