From d344f8d840ad4cde66b79f3d7fc4efd391663536 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@uliege.be>
Date: Sat, 18 Jun 2022 08:48:16 +0200
Subject: [PATCH] fix crash if option is null (can happen when parsing
 incorrect field option)

---
 src/fltk/fieldWindow.cpp | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/fltk/fieldWindow.cpp b/src/fltk/fieldWindow.cpp
index 3be7b27cfe..172d16b197 100644
--- a/src/fltk/fieldWindow.cpp
+++ b/src/fltk/fieldWindow.cpp
@@ -255,6 +255,7 @@ void fieldWindow::saveFieldOptions()
   sstream.precision(16);
   for(auto it = f->options.begin(); it != f->options.end(); it++) {
     FieldOption *option = it->second;
+    if(!option) continue;
     if(option->isDeprecated()) continue;
     sstream.str("");
     switch(option->getType()) {
@@ -329,6 +330,7 @@ void fieldWindow::loadFieldOptions()
   auto input = options_widget.begin();
   for(auto it = f->options.begin(); it != f->options.end(); it++) {
     FieldOption *option = it->second;
+    if(!option) continue;
     if(option->isDeprecated()) continue;
     std::ostringstream vstr;
     switch(option->getType()) {
@@ -415,12 +417,14 @@ void fieldWindow::editField(Field *f)
   if(!f->options.empty())
     help += std::string("<p><center><b>Options</b></center>");
   for(auto it = f->options.begin(); it != f->options.end(); it++) {
-    if(it->second->isDeprecated()) continue;
+    FieldOption *option = it->second;
+    if(!option) continue;
+    if(option->isDeprecated()) continue;
     Fl_Widget *input;
     help += std::string("<p><b>") + it->first + "</b>";
-    help += " (<em>" + it->second->getTypeName() + "</em>): ";
-    help += it->second->getDescription();
-    switch(it->second->getType()) {
+    help += " (<em>" + option->getTypeName() + "</em>): ";
+    help += option->getDescription();
+    switch(option->getType()) {
     case FIELD_OPTION_INT:
     case FIELD_OPTION_DOUBLE:
       input = new Fl_Value_Input(xx, yy, IW, BH, it->first.c_str());
-- 
GitLab