[evolution/gnome-3-16] Avoid use of uninitialized variables



commit 6ad8f92b1023cf4bd14a6c2c2e0212af8831ddec
Author: Milan Crha <mcrha redhat com>
Date:   Fri Apr 3 11:58:38 2015 +0200

    Avoid use of uninitialized variables
    
    Most of them were rather false-positives, the cases when something
    went really wrong.

 .../gui/contact-editor/e-contact-editor-dyntable.c |    9 +-
 calendar/gui/e-cal-data-model.c                    |    4 +-
 calendar/gui/e-cal-model.c                         |    2 +-
 calendar/gui/e-calendar-view.c                     |    4 +-
 calendar/gui/itip-utils.c                          |    4 +-
 composer/e-msg-composer.c                          |    8 +-
 e-util/e-html-editor-image-dialog.c                |   12 ++--
 e-util/e-html-editor-selection.c                   |   79 +++++++++++---------
 e-util/e-html-editor-spell-check-dialog.c          |    4 +-
 e-util/e-html-editor-view.c                        |    2 +-
 e-util/e-name-selector-entry.c                     |   10 +-
 mail/em-folder-tree-model.c                        |    2 +-
 mail/test-mail-autoconfig.c                        |    4 +-
 modules/calendar/e-cal-base-shell-content.c        |    2 +-
 modules/calendar/e-cal-base-shell-sidebar.c        |    8 +-
 15 files changed, 83 insertions(+), 71 deletions(-)
---
diff --git a/addressbook/gui/contact-editor/e-contact-editor-dyntable.c 
b/addressbook/gui/contact-editor/e-contact-editor-dyntable.c
index 68f298c..7bfa11b 100644
--- a/addressbook/gui/contact-editor/e-contact-editor-dyntable.c
+++ b/addressbook/gui/contact-editor/e-contact-editor-dyntable.c
@@ -299,7 +299,7 @@ add_empty_entry (EContactEditorDynTable *dyntable)
 static void
 remove_empty_entries (EContactEditorDynTable *dyntable, gboolean fillup)
 {
-       guint row, col, pos;
+       guint row, col = G_MAXUINT, pos;
        GtkGrid* grid;
        GtkWidget* w;
        EContactEditorDynTableClass *class;
@@ -334,11 +334,10 @@ remove_empty_entries (EContactEditorDynTable *dyntable, gboolean fillup)
 
        }
 
-       if (fillup
-               && (dyntable->priv->curr_entries < dyntable->priv->show_min_entries
-                           || (dyntable->priv->justified && col < dyntable->priv->columns-1)))
+       if (fillup &&
+           (dyntable->priv->curr_entries < dyntable->priv->show_min_entries ||
+           (dyntable->priv->justified && col < dyntable->priv->columns-1)))
                add_empty_entry (dyntable);
-
 }
 
 /* clears data, not the combo box list store */
diff --git a/calendar/gui/e-cal-data-model.c b/calendar/gui/e-cal-data-model.c
index 5b2599b..ea6430a 100644
--- a/calendar/gui/e-cal-data-model.c
+++ b/calendar/gui/e-cal-data-model.c
@@ -1527,8 +1527,8 @@ cal_data_model_update_client_view (ECalDataModel *data_model,
        ESource *source;
        ViewData *view_data;
        CreateViewData *cv_data;
-       const gchar *alert_ident;
-       gchar *description;
+       const gchar *alert_ident = NULL;
+       gchar *description = NULL;
 
        LOCK_PROPS ();
 
diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c
index b4f399e..893ba53 100644
--- a/calendar/gui/e-cal-model.c
+++ b/calendar/gui/e-cal-model.c
@@ -2961,7 +2961,7 @@ e_cal_model_create_component_with_defaults_sync (ECalModel *model,
                                                 GCancellable *cancellable,
                                                 GError **error)
 {
-       ECalComponent *comp;
+       ECalComponent *comp = NULL;
        icalcomponent *icalcomp;
 
        g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c
index 799054e..d04ea5a 100644
--- a/calendar/gui/e-calendar-view.c
+++ b/calendar/gui/e-calendar-view.c
@@ -792,7 +792,7 @@ cal_view_paste_clipboard_thread (EAlertSinkThreadJobData *job_data,
        icaltimezone *default_zone;
        ECalModel *model;
        ESourceRegistry *registry;
-       ESource *source, *default_source;
+       ESource *source = NULL, *default_source = NULL;
        EClientCache *client_cache;
        EClient *e_client;
        ECalClient *client = NULL;
@@ -1702,7 +1702,7 @@ e_calendar_view_get_tooltips (const ECalendarViewEventData *data)
 {
        GtkWidget *label, *box, *hbox, *ebox, *frame;
        const gchar *str;
-       gchar *tmp, *tmp1, *tmp2;
+       gchar *tmp, *tmp1 = NULL, *tmp2 = NULL;
        ECalComponentOrganizer organiser;
        ECalComponentDateTime dtstart, dtend;
        icalcomponent *clone_comp;
diff --git a/calendar/gui/itip-utils.c b/calendar/gui/itip-utils.c
index a043bd4..dab30ce 100644
--- a/calendar/gui/itip-utils.c
+++ b/calendar/gui/itip-utils.c
@@ -1904,8 +1904,8 @@ itip_send_component (ECalModel *model,
        ESourceRegistry *registry;
        ECalDataModel *data_model;
        ESource *source;
-       const gchar *alert_ident;
-       const gchar *description;
+       const gchar *alert_ident = NULL;
+       const gchar *description = NULL;
        GCancellable *cancellable;
        ItipSendComponentData *isc;
 
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 2768315..94ccfb2 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -3236,8 +3236,8 @@ handle_multipart (EMsgComposer *composer,
                } else if (depth == 0 && i == 0) {
                        EHTMLEditor *editor;
                        gboolean is_message_from_draft, is_html = FALSE;
-                       gchar *html;
-                       gssize length;
+                       gchar *html = NULL;
+                       gssize length = 0;
 
                        editor = e_msg_composer_get_editor (composer);
                        is_message_from_draft = e_html_editor_view_is_message_from_draft (
@@ -3271,7 +3271,9 @@ handle_multipart (EMsgComposer *composer,
                                html = emcu_part_to_html (
                                        composer, mime_part, &length, keep_signature, cancellable);
                        }
-                       e_msg_composer_set_pending_body (composer, html, length, is_html);
+
+                       if (html)
+                               e_msg_composer_set_pending_body (composer, html, length, is_html);
 
                } else if (camel_mime_part_get_content_id (mime_part) ||
                           camel_mime_part_get_content_location (mime_part)) {
diff --git a/e-util/e-html-editor-image-dialog.c b/e-util/e-html-editor-image-dialog.c
index 7290235..eaeea5f 100644
--- a/e-util/e-html-editor-image-dialog.c
+++ b/e-util/e-html-editor-image-dialog.c
@@ -102,9 +102,7 @@ html_editor_image_dialog_set_width (EHTMLEditorImageDialog *dialog)
        requested = gtk_spin_button_get_value_as_int (
                        GTK_SPIN_BUTTON (dialog->priv->width_edit));
 
-       switch (gtk_combo_box_get_active (
-               GTK_COMBO_BOX (dialog->priv->width_units))) {
-
+       switch (gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->width_units))) {
                case 0: /* px */
                        width = requested;
                        break;
@@ -117,6 +115,8 @@ html_editor_image_dialog_set_width (EHTMLEditorImageDialog *dialog)
                        width = natural;
                        break;
 
+               default:
+                       return;
        }
 
        webkit_dom_html_image_element_set_width (dialog->priv->image, width);
@@ -187,9 +187,7 @@ html_editor_image_dialog_set_height (EHTMLEditorImageDialog *dialog)
        requested = gtk_spin_button_get_value_as_int (
                        GTK_SPIN_BUTTON (dialog->priv->height_edit));
 
-       switch (gtk_combo_box_get_active (
-               GTK_COMBO_BOX (dialog->priv->height_units))) {
-
+       switch (gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->height_units))) {
                case 0: /* px */
                        height = requested;
                        break;
@@ -202,6 +200,8 @@ html_editor_image_dialog_set_height (EHTMLEditorImageDialog *dialog)
                        height = natural;
                        break;
 
+               default:
+                       return;
        }
 
        webkit_dom_html_image_element_set_height (dialog->priv->image, height);
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 0f445b3..001c4ab 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -3732,7 +3732,7 @@ unindent_block (EHTMLEditorSelection *selection,
        EHTMLEditorSelectionAlignment alignment;
        WebKitDOMElement *element;
        WebKitDOMElement *prev_blockquote = NULL, *next_blockquote = NULL;
-       WebKitDOMNode *block_to_process, *node_clone, *child;
+       WebKitDOMNode *block_to_process, *node_clone = NULL, *child;
 
        block_to_process = block;
 
@@ -3778,33 +3778,37 @@ unindent_block (EHTMLEditorSelection *selection,
                        NULL);
        }
 
-       element_remove_class (WEBKIT_DOM_ELEMENT (node_clone), "-x-evo-to-unindent");
+       if (node_clone) {
+               element_remove_class (WEBKIT_DOM_ELEMENT (node_clone), "-x-evo-to-unindent");
 
-       /* Insert blockqoute with nodes that were before the element that we want to unindent */
-       if (prev_blockquote) {
-               if (webkit_dom_node_has_child_nodes (WEBKIT_DOM_NODE (prev_blockquote))) {
-                       webkit_dom_node_insert_before (
-                               webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),
-                               WEBKIT_DOM_NODE (prev_blockquote),
-                               WEBKIT_DOM_NODE (element),
-                               NULL);
+               /* Insert blockqoute with nodes that were before the element that we want to unindent */
+               if (prev_blockquote) {
+                       if (webkit_dom_node_has_child_nodes (WEBKIT_DOM_NODE (prev_blockquote))) {
+                               webkit_dom_node_insert_before (
+                                       webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),
+                                       WEBKIT_DOM_NODE (prev_blockquote),
+                                       WEBKIT_DOM_NODE (element),
+                                       NULL);
+                       }
                }
-       }
 
-       if (level == 1 && element_has_class (WEBKIT_DOM_ELEMENT (node_clone), "-x-evo-paragraph")) {
-               e_html_editor_selection_set_paragraph_style (
-                       selection, WEBKIT_DOM_ELEMENT (node_clone), word_wrap_length, 0, "");
-               element_add_class (
-                       WEBKIT_DOM_ELEMENT (node_clone),
-                       get_css_alignment_value_class (alignment));
-       }
+               if (level == 1 && element_has_class (WEBKIT_DOM_ELEMENT (node_clone), "-x-evo-paragraph")) {
+                       e_html_editor_selection_set_paragraph_style (
+                               selection, WEBKIT_DOM_ELEMENT (node_clone), word_wrap_length, 0, "");
+                       element_add_class (
+                               WEBKIT_DOM_ELEMENT (node_clone),
+                               get_css_alignment_value_class (alignment));
+               }
 
-       /* Insert the unindented element */
-       webkit_dom_node_insert_before (
-               webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),
-               node_clone,
-               WEBKIT_DOM_NODE (element),
-               NULL);
+               /* Insert the unindented element */
+               webkit_dom_node_insert_before (
+                       webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (element)),
+                       node_clone,
+                       WEBKIT_DOM_NODE (element),
+                       NULL);
+       } else {
+               g_warn_if_reached ();
+       }
 
        /* Insert blockqoute with nodes that were after the element that we want to unindent */
        if (next_blockquote) {
@@ -4078,7 +4082,7 @@ html_editor_selection_set_font_style (EHTMLEditorSelection *selection,
 
        if (e_html_editor_selection_is_collapsed (selection)) {
                WebKitDOMDocument *document;
-               const gchar *element_name;
+               const gchar *element_name = NULL;
 
                if (command == E_HTML_EDITOR_VIEW_COMMAND_BOLD)
                        element_name = "b";
@@ -4090,7 +4094,8 @@ html_editor_selection_set_font_style (EHTMLEditorSelection *selection,
                        element_name = "strike";
 
                document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
-               set_font_style (document, element_name, value);
+               if (element_name)
+                       set_font_style (document, element_name, value);
                e_html_editor_selection_restore (selection);
 
                goto exit;
@@ -6558,7 +6563,7 @@ e_html_editor_selection_save (EHTMLEditorSelection *selection)
        WebKitDOMRange *range;
        WebKitDOMNode *container, *next_sibling, *marker_node;
        WebKitDOMNode *split_node, *parent_node, *anchor;
-       WebKitDOMElement *start_marker, *end_marker;
+       WebKitDOMElement *start_marker = NULL, *end_marker = NULL;
 
        g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection));
 
@@ -6872,8 +6877,12 @@ e_html_editor_selection_save (EHTMLEditorSelection *selection)
        }
  out:
        if (!collapsed) {
-               webkit_dom_range_set_start_after (range, WEBKIT_DOM_NODE (start_marker), NULL);
-               webkit_dom_range_set_end_before (range, WEBKIT_DOM_NODE (end_marker), NULL);
+               if (start_marker && end_marker) {
+                       webkit_dom_range_set_start_after (range, WEBKIT_DOM_NODE (start_marker), NULL);
+                       webkit_dom_range_set_end_before (range, WEBKIT_DOM_NODE (end_marker), NULL);
+               } else {
+                       g_warn_if_reached ();
+               }
 
                webkit_dom_dom_selection_remove_all_ranges (dom_selection);
                webkit_dom_dom_selection_add_range (dom_selection, range);
@@ -7070,7 +7079,7 @@ html_editor_selection_modify (EHTMLEditorSelection *selection,
        WebKitDOMDocument *document;
        WebKitDOMDOMWindow *dom_window;
        WebKitDOMDOMSelection *dom_selection;
-       const gchar *granularity_str;
+       const gchar *granularity_str = NULL;
 
        g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection));
 
@@ -7092,10 +7101,12 @@ html_editor_selection_modify (EHTMLEditorSelection *selection,
                        break;
        }
 
-       webkit_dom_dom_selection_modify (
-               dom_selection, alter,
-               forward ? "forward" : "backward",
-               granularity_str);
+       if (granularity_str) {
+               webkit_dom_dom_selection_modify (
+                       dom_selection, alter,
+                       forward ? "forward" : "backward",
+                       granularity_str);
+       }
 
        g_object_unref (dom_selection);
        g_object_unref (dom_window);
diff --git a/e-util/e-html-editor-spell-check-dialog.c b/e-util/e-html-editor-spell-check-dialog.c
index a51f344..505097b 100644
--- a/e-util/e-html-editor-spell-check-dialog.c
+++ b/e-util/e-html-editor-spell-check-dialog.c
@@ -154,7 +154,7 @@ static gboolean
 html_editor_spell_check_dialog_next (EHTMLEditorSpellCheckDialog *dialog)
 {
        WebKitDOMNode *start = NULL, *end = NULL;
-       gulong start_offset, end_offset;
+       gulong start_offset = 0, end_offset = 0;
 
        if (dialog->priv->word == NULL) {
                webkit_dom_dom_selection_modify (
@@ -248,7 +248,7 @@ static gboolean
 html_editor_spell_check_dialog_prev (EHTMLEditorSpellCheckDialog *dialog)
 {
        WebKitDOMNode *start = NULL, *end = NULL;
-       gulong start_offset, end_offset;
+       gulong start_offset = 0, end_offset = 0;
 
        if (dialog->priv->word == NULL) {
                webkit_dom_dom_selection_modify (
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index f8852dc..13ebc91 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -7188,7 +7188,7 @@ e_html_editor_view_exec_command (EHTMLEditorView *view,
 {
        WebKitDOMDocument *document;
        const gchar *cmd_str = 0;
-       gboolean has_value;
+       gboolean has_value = FALSE;
 
        g_return_val_if_fail (E_IS_HTML_EDITOR_VIEW (view), FALSE);
 
diff --git a/e-util/e-name-selector-entry.c b/e-util/e-name-selector-entry.c
index 0b53b35..a82b04f 100644
--- a/e-util/e-name-selector-entry.c
+++ b/e-util/e-name-selector-entry.c
@@ -1055,9 +1055,9 @@ find_existing_completion (ENameSelectorEntry *name_selector_entry,
 
        do {
                EContact      *current_contact;
-               gint           current_field_rank;
-               gint           current_email_num;
-               EContactField  current_field;
+               gint           current_field_rank = best_field_rank;
+               gint           current_email_num = best_email_num;
+               EContactField  current_field = best_field;
                gboolean       matches;
 
                current_contact = e_contact_store_get_contact (name_selector_entry->priv->contact_store, 
&iter);
@@ -1153,9 +1153,9 @@ type_ahead_complete (ENameSelectorEntry *name_selector_entry)
 {
        EContact      *contact;
        EBookClient   *book_client = NULL;
-       EContactField  matched_field;
+       EContactField  matched_field = E_CONTACT_FIELD_LAST;
        EDestination  *destination;
-       gint           matched_email_num;
+       gint           matched_email_num = -1;
        gint           cursor_pos;
        gint           range_start = 0;
        gint           range_end = 0;
diff --git a/mail/em-folder-tree-model.c b/mail/em-folder-tree-model.c
index bdbaebf..ebe61b8 100644
--- a/mail/em-folder-tree-model.c
+++ b/mail/em-folder-tree-model.c
@@ -1480,7 +1480,7 @@ folder_tree_model_update_status_icon (StoreInfo *si)
        GtkTreePath *path;
        GtkTreeIter iter;
        GIcon *icon = NULL;
-       const gchar *icon_name;
+       const gchar *icon_name = NULL;
        gboolean was_connecting;
        gboolean host_reachable;
 
diff --git a/mail/test-mail-autoconfig.c b/mail/test-mail-autoconfig.c
index 9c96a67..8016384 100644
--- a/mail/test-mail-autoconfig.c
+++ b/mail/test-mail-autoconfig.c
@@ -25,7 +25,7 @@ main (gint argc,
       gchar **argv)
 {
        ESourceRegistry *registry;
-       EMailAutoconfig *autoconfig;
+       EMailAutoconfig *autoconfig = NULL;
        GError *error = NULL;
 
        if (argc < 2) {
@@ -54,7 +54,7 @@ main (gint argc,
 
        e_mail_autoconfig_dump_results (autoconfig);
 
-       g_object_unref (autoconfig);
+       g_clear_object (&autoconfig);
 
        return EXIT_SUCCESS;
 }
diff --git a/modules/calendar/e-cal-base-shell-content.c b/modules/calendar/e-cal-base-shell-content.c
index 70cda06..399aa85 100644
--- a/modules/calendar/e-cal-base-shell-content.c
+++ b/modules/calendar/e-cal-base-shell-content.c
@@ -302,7 +302,7 @@ cal_base_shell_content_constructed (GObject *object)
        ECalBaseShellContentClass *klass;
        ESourceRegistry *registry;
        ESource *default_source = NULL;
-       const gchar *created_signal_name;
+       const gchar *created_signal_name = NULL;
 
        /* Chain up to parent's method. */
        G_OBJECT_CLASS (e_cal_base_shell_content_parent_class)->constructed (object);
diff --git a/modules/calendar/e-cal-base-shell-sidebar.c b/modules/calendar/e-cal-base-shell-sidebar.c
index 83fe540..03a2ba8 100644
--- a/modules/calendar/e-cal-base-shell-sidebar.c
+++ b/modules/calendar/e-cal-base-shell-sidebar.c
@@ -108,7 +108,7 @@ cal_base_shell_sidebar_restore_state_cb (EShellWindow *shell_window,
        ESourceRegistry *registry;
        ESourceSelector *selector;
        GSettings *settings;
-       const gchar *primary_source_key;
+       const gchar *primary_source_key = NULL;
 
        priv = E_CAL_BASE_SHELL_SIDEBAR (shell_sidebar)->priv;
 
@@ -337,7 +337,7 @@ e_cal_base_shell_sidebar_ensure_source_opened (ECalBaseShellSidebar *sidebar,
        EShellView *shell_view;
        EActivity *activity;
        gchar *description = NULL, *alert_ident = NULL, *alert_arg_0 = NULL;
-       const gchar *extension_name;
+       const gchar *extension_name = NULL;
 
        g_return_if_fail (E_IS_CAL_BASE_SHELL_SIDEBAR (sidebar));
        g_return_if_fail (E_IS_SOURCE (source));
@@ -503,7 +503,7 @@ e_cal_base_shell_sidebar_selector_data_dropped (ESourceSelector *selector,
        gchar **segments;
        gchar *source_uid = NULL;
        gchar *message = NULL;
-       const gchar *display_name, *alert_ident;
+       const gchar *display_name, *alert_ident = NULL;
        const guchar *data;
        gboolean do_copy;
        TransferItemToData *titd;
@@ -629,7 +629,7 @@ cal_base_shell_sidebar_constructed (GObject *object)
        EShellBackend *shell_backend;
        EShell *shell;
        EClientCache *client_cache;
-       const gchar *source_extension, *selector_name, *restore_state_signal;
+       const gchar *source_extension = NULL, *selector_name = NULL, *restore_state_signal = NULL;
        ECalBaseShellSidebar *cal_base_shell_sidebar;
        GtkWidget *container, *widget;
        AtkObject *a11y;


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