Fix #2994, non-existent path causes segmentation fault when saving plot (#3038)

Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
pitkajuh 2024-06-18 11:56:51 +00:00 committed by GitHub
parent b0732cb6b3
commit e33e66aa88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View file

@ -315,6 +315,11 @@ void Plot::set_output_path(pugi::xml_node plot_node)
} else {
filename = fmt::format("plot_{}", id());
}
const std::string dir_if_present =
filename.substr(0, filename.find_last_of("/") + 1);
if (dir_if_present.size() > 0 && !dir_exists(dir_if_present)) {
fatal_error(fmt::format("Directory '{}' does not exist!", dir_if_present));
}
// add appropriate file extension to name
switch (type_) {
case PlotType::slice: