[glom] Field definition: Add some null checks.



commit 88ec941b01cd58dc5ad6fcca1be5083e4cb888cf
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Mar 10 09:44:27 2016 +0100

    Field definition: Add some null checks.
    
    Because this is preferrable to a crash, even though these nulls
    should not happen.

 glom/mode_design/fields/box_db_table_definition.cc |    5 +++++
 glom/mode_design/fields/dialog_fielddefinition.cc  |    6 ++++++
 2 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/glom/mode_design/fields/box_db_table_definition.cc 
b/glom/mode_design/fields/box_db_table_definition.cc
index 39e8e38..14b0aa2 100644
--- a/glom/mode_design/fields/box_db_table_definition.cc
+++ b/glom/mode_design/fields/box_db_table_definition.cc
@@ -519,6 +519,11 @@ std::shared_ptr<Field> Box_DB_Table_Definition::get_field_definition(const Gtk::
 void Box_DB_Table_Definition::on_field_definition_apply()
 {
   auto field_New = m_dialog_field_definition->get_field();
+  if(!field_New)
+  {
+    std::cerr << G_STRFUNC << ": field_New is null." << std::endl;
+    return;
+  }
 
   if(*m_Field_BeingEdited != *field_New)
   {
diff --git a/glom/mode_design/fields/dialog_fielddefinition.cc 
b/glom/mode_design/fields/dialog_fielddefinition.cc
index 3aaa3ab..ade7a7f 100644
--- a/glom/mode_design/fields/dialog_fielddefinition.cc
+++ b/glom/mode_design/fields/dialog_fielddefinition.cc
@@ -213,6 +213,12 @@ void Dialog_FieldDefinition::set_field(const std::shared_ptr<const Field>& field
 
 std::shared_ptr<Field> Dialog_FieldDefinition::get_field() const
 {
+  if(!m_Field)
+  {
+    std::cerr << G_STRFUNC << ": m_Field is null." << std::endl;
+    return std::shared_ptr<Field>();
+  }
+
   auto field = glom_sharedptr_clone(m_Field); //Start with the old details, to preserve anything that is not 
in our UI.
   // const_cast is necessary and save here for the window (jhs)
   auto sharedcnc = connect_to_server(const_cast<Dialog_FieldDefinition*>(this));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]