[glom] Fix (unlikely) possible null dereferences shown by cppcheck.



commit 353df2d9f8b211c2437cfcf9c77cadda1e797718
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Oct 1 19:00:20 2010 +0200

    Fix (unlikely) possible null dereferences shown by cppcheck.
    
    * Several files: Check the output parameter when getting widgets from glade.
    When this fails there is already a stderr warning and we could not recover
    anyway, but this helps cppcheck or maybe other chekers to only tell us
    interesting things.

 ChangeLog                                          |    9 +++++++++
 glom/application.cc                                |    3 +++
 glom/base_db.cc                                    |   14 +++++++++++++-
 glom/dialog_invalid_data.cc                        |    3 +++
 glom/frame_glom.cc                                 |   16 +++++++++++++++-
 glom/glade_utils.cc                                |    3 +++
 glom/mode_data/buttonglom.cc                       |    2 ++
 glom/mode_data/datawidget/datawidget.cc            |    2 ++
 glom/mode_data/datawidget/label.cc                 |    2 ++
 glom/mode_data/flowtablewithfields.cc              |    5 +++++
 glom/mode_design/fields/dialog_fielddefinition.cc  |   11 +++++++++--
 glom/mode_design/layout/dialog_layout_details.cc   |    5 +++++
 .../report_layout/dialog_layout_report.cc          |    2 ++
 .../script_library/dialog_script_library.cc        |    3 +++
 .../mode_design/translation/window_translations.cc |    6 ++++++
 glom/mode_design/users/dialog_groups_list.cc       |    6 ++++++
 glom/mode_design/users/dialog_users_list.cc        |    6 ++++++
 glom/print_layout/canvas_print_layout.cc           |    2 ++
 18 files changed, 96 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0ae7bea..fb63762 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-10-01  Murray Cumming  <murrayc murrayc com>
+
+	Fix (unlikely) possible null dereferences shown by cppcheck.
+
+	* Several files: Check the output parameter when getting widgets from glade.
+	When this fails there is already a stderr warning and we could not recover 
+	anyway, but this helps cppcheck or maybe other chekers to only tell us 
+	interesting things.
+
 2010-10-01  Murray Cumming  <murrayc murrayc-x61>
 
 	DbUtils: Move fill_full_field_details() here from Base_DB.
diff --git a/glom/application.cc b/glom/application.cc
index 6df660e..e96796c 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -2660,6 +2660,9 @@ void Application::on_menu_developer_changelanguage()
 {
   Dialog_ChangeLanguage* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
+    
   dialog->set_transient_for(*this);
   const int response = Glom::Utils::dialog_run_with_help(dialog);
   dialog->hide();
diff --git a/glom/base_db.cc b/glom/base_db.cc
index 35efd43..73c7601 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -421,6 +421,8 @@ sharedptr<LayoutItem_Field> Base_DB::offer_field_list_select_one_field(const sha
 
   Dialog_ChooseField* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
 
   if(dialog)
   {
@@ -449,6 +451,8 @@ Base_DB::type_list_field_items Base_DB::offer_field_list(const Glib::ustring& ta
 
   Dialog_ChooseField* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
 
   if(dialog)
   {
@@ -501,7 +505,9 @@ sharedptr<LayoutItem_Field> Base_DB::offer_field_formatting(const sharedptr<cons
 
   Dialog_FieldLayout* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
-
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
+  
   if(transient_for)
     dialog->set_transient_for(*transient_for);
 
@@ -531,6 +537,8 @@ sharedptr<LayoutItem_Text> Base_DB::offer_textobject(const sharedptr<LayoutItem_
 
   Dialog_TextObject* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
 
   if(transient_for)
     dialog->set_transient_for(*transient_for);
@@ -555,6 +563,8 @@ sharedptr<LayoutItem_Image> Base_DB::offer_imageobject(const sharedptr<LayoutIte
 
   Dialog_ImageObject* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
 
   if(transient_for)
     dialog->set_transient_for(*transient_for);
@@ -579,6 +589,8 @@ sharedptr<LayoutItem_Notebook> Base_DB::offer_notebook(const sharedptr<LayoutIte
 
   Dialog_Notebook* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
 
   if(transient_for)
     dialog->set_transient_for(*transient_for);
diff --git a/glom/dialog_invalid_data.cc b/glom/dialog_invalid_data.cc
index f7829f8..136f42c 100644
--- a/glom/dialog_invalid_data.cc
+++ b/glom/dialog_invalid_data.cc
@@ -36,6 +36,9 @@ bool glom_show_dialog_invalid_data(Field::glom_field_type glom_type)
 {
   Dialog_InvalidData* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return false;
+    
   dialog->set_example_data(glom_type);
   //dialog->set_transient_for(*this);
   const int response = Glom::Utils::dialog_run_with_help(dialog);
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index e918eb9..6f702ea 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -893,6 +893,9 @@ void Frame_Glom::on_menu_file_import()
 
       Dialog_Import_CSV* dialog = 0;
       Glom::Utils::get_glade_widget_derived_with_warning(dialog);
+      if(!dialog) //Unlikely and it already warns on stderr.
+        return;
+
       add_view(dialog);
 
       dialog->import(file_chooser.get_uri(), m_table_name);
@@ -1683,6 +1686,9 @@ void Frame_Glom::on_menu_developer_database_preferences()
 {
   Dialog_Database_Preferences* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
+        
   dialog->set_transient_for(*(get_app_window()));
   add_view(dialog);
   dialog->load_from_document();
@@ -1779,13 +1785,18 @@ void Frame_Glom::on_menu_developer_relationships()
   if(m_table_name.empty())
     return;
 
-  do_menu_developer_relationships(*get_app_window(), m_table_name);
+  Gtk::Window* app = get_app_window();
+  if(app)
+    do_menu_developer_relationships(*app, m_table_name);
 }
 
 void Frame_Glom::on_menu_developer_users()
 {
   Dialog_GroupsList* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
+    
   dialog->set_transient_for(*get_app_window());
 
   add_view(dialog); //Give it access to the document.
@@ -1871,6 +1882,9 @@ void Frame_Glom::on_menu_developer_script_library()
 {
   Dialog_ScriptLibrary* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
+    
   dialog->set_transient_for(*(get_app_window()));
   add_view(dialog); //Give it access to the document.
   dialog->load_from_document();
diff --git a/glom/glade_utils.cc b/glom/glade_utils.cc
index 7109bb1..0626e34 100644
--- a/glom/glade_utils.cc
+++ b/glom/glade_utils.cc
@@ -35,6 +35,9 @@ Dialog_ProgressCreating* get_and_show_pulse_dialog(const Glib::ustring& message,
 
   Dialog_ProgressCreating* dialog_progress = 0;
   Utils::get_glade_widget_derived_with_warning(dialog_progress);
+  if(!dialog_progress) //Unlikely and it already warns on stderr.
+    return 0;
+    
   dialog_progress->set_message(_("Processing"), message);
   dialog_progress->set_modal();
 
diff --git a/glom/mode_data/buttonglom.cc b/glom/mode_data/buttonglom.cc
index b5ee96c..462ef85 100644
--- a/glom/mode_data/buttonglom.cc
+++ b/glom/mode_data/buttonglom.cc
@@ -65,6 +65,8 @@ void ButtonGlom::on_menu_properties_activate()
 {
   Dialog_ButtonScript* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
 
   sharedptr<LayoutItem_Button> layout_item = 
     sharedptr<LayoutItem_Button>::cast_dynamic(get_layout_item());
diff --git a/glom/mode_data/datawidget/datawidget.cc b/glom/mode_data/datawidget/datawidget.cc
index c94720c..82e17d6 100644
--- a/glom/mode_data/datawidget/datawidget.cc
+++ b/glom/mode_data/datawidget/datawidget.cc
@@ -501,6 +501,8 @@ sharedptr<LayoutItem_Field> DataWidget::offer_field_layout(const sharedptr<const
 
   Dialog_FieldLayout* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
 
   add_view(dialog); //Give it access to the document.
   dialog->set_field(start_field, m_table_name);
diff --git a/glom/mode_data/datawidget/label.cc b/glom/mode_data/datawidget/label.cc
index 6d32c93..12a14a5 100644
--- a/glom/mode_data/datawidget/label.cc
+++ b/glom/mode_data/datawidget/label.cc
@@ -80,6 +80,8 @@ void Label::on_menu_properties_activate()
 
   Dialog_TextObject* dialog = 0;
   Glom::Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
 
   dialog->set_textobject(textobject, m_table_name);
   const int response = dialog->run();
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 2cec814..203fbc0 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -1632,6 +1632,8 @@ void FlowTableWithFields::on_menu_properties_activate()
 {
   Dialog_FlowTable* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
 
   dialog->set_flowtable(this);
   const int response = dialog->run();
@@ -1691,10 +1693,13 @@ bool FlowTableWithFields::on_button_press_event(GdkEventButton *event)
   return Gtk::Widget::on_button_press_event(event);
 }
 
+//TODO: Rename this? It's not a simpler getter. It does UI.
 sharedptr<LayoutItem_Portal> FlowTableWithFields::get_portal_relationship()
 {
   Dialog_ChooseRelationship* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return sharedptr<LayoutItem_Portal>();
 
   Document* pDocument = static_cast<Document*>(get_document());
   dialog->set_document(pDocument, m_table_name);
diff --git a/glom/mode_design/fields/dialog_fielddefinition.cc b/glom/mode_design/fields/dialog_fielddefinition.cc
index de5a404..273c9ff 100644
--- a/glom/mode_design/fields/dialog_fielddefinition.cc
+++ b/glom/mode_design/fields/dialog_fielddefinition.cc
@@ -88,14 +88,19 @@ Dialog_FieldDefinition::Dialog_FieldDefinition(BaseObjectType* cobject, const Gl
 
   //Get the formatting stuff:
   Utils::get_glade_widget_derived_with_warning(m_box_formatting);
-  m_box_formatting_placeholder->pack_start(*m_box_formatting);
+    
+  if(m_box_formatting) ////Unlikely to fail and it already warns on stderr.
+    m_box_formatting_placeholder->pack_start(*m_box_formatting);
+
   add_view(m_box_formatting);
 
 
   on_foreach_connect(*this);
   on_foreach_connect(*m_pBox_DefaultValueSimple);
   on_foreach_connect(*m_pBox_ValueTab);
-  on_foreach_connect(*m_box_formatting);
+  
+  if(m_box_formatting) ////Unlikely to fail and it already warns on stderr.
+    on_foreach_connect(*m_box_formatting);
 
   //Plus an extra signal for the related extra show-also fields:
   m_box_formatting->signal_modified().connect(
@@ -376,6 +381,8 @@ void Dialog_FieldDefinition::on_button_edit_calculation()
   //TODO: Share a global instance, to make this quicker?
   Dialog_FieldCalculation* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
 
   add_view(dialog); //Give it access to the document.
 
diff --git a/glom/mode_design/layout/dialog_layout_details.cc b/glom/mode_design/layout/dialog_layout_details.cc
index ea32d6d..6f767d7 100644
--- a/glom/mode_design/layout/dialog_layout_details.cc
+++ b/glom/mode_design/layout/dialog_layout_details.cc
@@ -553,6 +553,9 @@ sharedptr<LayoutItem_Button> Dialog_Layout_Details::offer_button_script_edit(con
 
   Dialog_ButtonScript* dialog = 0;
   Glom::Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
+        
   dialog->set_script(button, m_table_name);
   dialog->set_transient_for(*this);
   const int response = Glom::Utils::dialog_run_with_help(dialog);
@@ -579,6 +582,8 @@ sharedptr<Relationship> Dialog_Layout_Details::offer_relationship_list(const sha
 
   Dialog_ChooseRelationship* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
 
   dialog->set_document(get_document(), m_table_name);
   dialog->select_item(item);
diff --git a/glom/mode_design/report_layout/dialog_layout_report.cc b/glom/mode_design/report_layout/dialog_layout_report.cc
index ac51069..d2c0f09 100644
--- a/glom/mode_design/report_layout/dialog_layout_report.cc
+++ b/glom/mode_design/report_layout/dialog_layout_report.cc
@@ -698,6 +698,8 @@ sharedptr<Relationship> Dialog_Layout_Report::offer_relationship_list()
 
   Dialog_ChooseRelationship* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
 
   dialog->set_document(get_document(), m_table_name);
   dialog->set_transient_for(*this);
diff --git a/glom/mode_design/script_library/dialog_script_library.cc b/glom/mode_design/script_library/dialog_script_library.cc
index f357545..6e72779 100644
--- a/glom/mode_design/script_library/dialog_script_library.cc
+++ b/glom/mode_design/script_library/dialog_script_library.cc
@@ -94,6 +94,9 @@ void Dialog_ScriptLibrary::on_button_add()
 
   Dialog_NewScript* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
+    
   dialog->set_transient_for(*this);
   const int response = Glom::Utils::dialog_run_with_help(dialog);
   dialog->hide();
diff --git a/glom/mode_design/translation/window_translations.cc b/glom/mode_design/translation/window_translations.cc
index cda089e..e676dc6 100644
--- a/glom/mode_design/translation/window_translations.cc
+++ b/glom/mode_design/translation/window_translations.cc
@@ -134,6 +134,9 @@ void Window_Translations::on_button_identify()
 {
   Dialog_IdentifyOriginal* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
+
   add_view(dialog);
   dialog->load_from_document(); //Doesn't seem to happen otherwise.
   dialog->set_transient_for(*this);
@@ -357,6 +360,9 @@ void Window_Translations::on_button_copy_translation()
 {
   Dialog_CopyTranslation* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
+
   dialog->set_transient_for(*this);
   const int response = Glom::Utils::dialog_run_with_help(dialog);
   dialog->hide();
diff --git a/glom/mode_design/users/dialog_groups_list.cc b/glom/mode_design/users/dialog_groups_list.cc
index 573f4da..01f86f9 100644
--- a/glom/mode_design/users/dialog_groups_list.cc
+++ b/glom/mode_design/users/dialog_groups_list.cc
@@ -240,6 +240,9 @@ void Dialog_GroupsList::on_button_group_new()
 {
   Dialog_NewGroup* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
+    
   dialog->set_transient_for(*this);
   const int response = Glom::Utils::dialog_run_with_help(dialog);
 
@@ -291,6 +294,9 @@ void Dialog_GroupsList::on_button_group_users()
 
       Dialog_UsersList* dialog = 0;
       Utils::get_glade_widget_derived_with_warning(dialog);
+      if(!dialog) //Unlikely and it already warns on stderr.
+        return;
+    
       dialog->set_transient_for(*this);
       add_view(dialog); //Give it access to the document.
 
diff --git a/glom/mode_design/users/dialog_users_list.cc b/glom/mode_design/users/dialog_users_list.cc
index 1cee708..95608d7 100644
--- a/glom/mode_design/users/dialog_users_list.cc
+++ b/glom/mode_design/users/dialog_users_list.cc
@@ -184,6 +184,8 @@ void Dialog_UsersList::on_button_user_add()
 {
   Dialog_ChooseUser* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
 
   dialog->set_transient_for(*this);
 
@@ -226,6 +228,8 @@ void Dialog_UsersList::on_button_user_new()
 {
   Dialog_User* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return;
 
   dialog->set_transient_for(*this);
   dialog->m_combo_group->set_sensitive(false); //It is being added to the current group, so don't offer a different group.
@@ -272,6 +276,8 @@ void Dialog_UsersList::on_button_user_edit()
 
       Dialog_User* dialog = 0;
       Utils::get_glade_widget_derived_with_warning(dialog);
+      if(!dialog) //Unlikely and it already warns on stderr.
+        return;
 
       dialog->set_transient_for(*this);
 
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index 384459f..dac3411 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -293,6 +293,8 @@ sharedptr<LayoutItem_Portal> Canvas_PrintLayout::offer_related_records(const sha
 
   Dialog_Layout_List_Related* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
+  if(!dialog) //Unlikely and it already warns on stderr.
+    return result;
 
   add_view(dialog); //Give it access to the document.
 



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