[evolution/gnome-3-24] Fix few issues reported by Coverity scan



commit 115c4699846de3deb0dd5d7d3136177ff240f116
Author: Milan Crha <mcrha redhat com>
Date:   Tue Mar 21 14:49:17 2017 +0100

    Fix few issues reported by Coverity scan
    
    Part of the change done by Tomas Popela

 src/calendar/gui/itip-utils.c                      |    2 -
 src/e-util/e-color-chooser-widget.c                |    3 ++
 src/e-util/test-html-editor-units.c                |    4 ++-
 src/mail/e-mail-display.c                          |    6 ++--
 src/mail/e-mail-free-form-exp.c                    |    7 +---
 src/modules/calendar/e-cal-attachment-handler.c    |    2 +-
 src/modules/calendar/e-cal-shell-content.c         |    8 ++--
 src/modules/webkit-editor/e-webkit-editor.c        |    6 +--
 .../web-extension/e-editor-dom-functions.c         |   39 ++++++--------------
 .../web-extension/e-editor-undo-redo-manager.c     |    7 ++--
 src/plugins/mail-notification/mail-notification.c  |    5 ++-
 src/smime/lib/e-cert-db.c                          |    6 ++-
 src/web-extensions/e-dom-utils.c                   |    2 +-
 13 files changed, 43 insertions(+), 54 deletions(-)
---
diff --git a/src/calendar/gui/itip-utils.c b/src/calendar/gui/itip-utils.c
index f126e9c..d808a3c 100644
--- a/src/calendar/gui/itip-utils.c
+++ b/src/calendar/gui/itip-utils.c
@@ -2475,8 +2475,6 @@ reply_to_calendar_comp (ESourceRegistry *registry,
 
  cleanup:
 
-       if (comp != NULL)
-               g_object_unref (comp);
        if (top_level != NULL)
                icalcomponent_free (top_level);
 
diff --git a/src/e-util/e-color-chooser-widget.c b/src/e-util/e-color-chooser-widget.c
index f7d5bbb..f81c3f2 100644
--- a/src/e-util/e-color-chooser-widget.c
+++ b/src/e-util/e-color-chooser-widget.c
@@ -201,6 +201,9 @@ find_swatch (GtkContainer *container)
                GtkWidget *widget = child->data;
                GtkWidget *swatch;
 
+               if (!widget)
+                       continue;
+
                if (GTK_IS_CONTAINER (widget)) {
                        swatch = find_swatch (GTK_CONTAINER (widget));
 
diff --git a/src/e-util/test-html-editor-units.c b/src/e-util/test-html-editor-units.c
index 2778855..54a4045 100644
--- a/src/e-util/test-html-editor-units.c
+++ b/src/e-util/test-html-editor-units.c
@@ -953,6 +953,7 @@ test_image_insert (TestFixture *fixture)
        gchar *image_data;
        gchar *image_data_base64;
        gsize image_data_length;
+       gboolean success;
        GError *error = NULL;
 
        if (!test_utils_process_commands (fixture,
@@ -966,8 +967,9 @@ test_image_insert (TestFixture *fixture)
        uri = g_filename_to_uri (filename, NULL, &error);
        g_assert_no_error (error);
 
-       g_file_get_contents (filename, &image_data, &image_data_length, &error);
+       success = g_file_get_contents (filename, &image_data, &image_data_length, &error);
        g_assert_no_error (error);
+       g_assert (success);
 
        g_free (filename);
 
diff --git a/src/mail/e-mail-display.c b/src/mail/e-mail-display.c
index d92d667..ddbf987 100644
--- a/src/mail/e-mail-display.c
+++ b/src/mail/e-mail-display.c
@@ -524,15 +524,15 @@ headers_collapsed_signal_cb (GDBusConnection *connection,
                              GVariant *parameters,
                              EMailDisplay *display)
 {
-       gboolean expanded;
+       gboolean collapsed = FALSE;
 
        if (g_strcmp0 (signal_name, "HeadersCollapsed") != 0)
                return;
 
        if (parameters)
-               g_variant_get (parameters, "(b)", &expanded);
+               g_variant_get (parameters, "(b)", &collapsed);
 
-       e_mail_display_set_headers_collapsed (display, expanded);
+       e_mail_display_set_headers_collapsed (display, collapsed);
 }
 
 static void
diff --git a/src/mail/e-mail-free-form-exp.c b/src/mail/e-mail-free-form-exp.c
index 62af45a..a7b5485 100644
--- a/src/mail/e-mail-free-form-exp.c
+++ b/src/mail/e-mail-free-form-exp.c
@@ -74,12 +74,9 @@ mail_ffe_build_header_sexp (const gchar *word,
        camel_sexp_encode_string (encoded_word, word);
 
        if (!header_names[1]) {
-               if (!sexp)
-                       sexp = g_string_new ("");
-       } else if (!sexp) {
-               sexp = g_string_new ("(or ");
+               sexp = g_string_new ("");
        } else {
-               g_string_append (sexp, "(or ");
+               sexp = g_string_new ("(or ");
        }
 
        for (ii = 0; header_names[ii]; ii++) {
diff --git a/src/modules/calendar/e-cal-attachment-handler.c b/src/modules/calendar/e-cal-attachment-handler.c
index 989e136..5cf9cd7 100644
--- a/src/modules/calendar/e-cal-attachment-handler.c
+++ b/src/modules/calendar/e-cal-attachment-handler.c
@@ -345,7 +345,7 @@ attachment_handler_run_dialog (GtkWindow *parent,
                                break;
                        default:
                                g_warn_if_reached ();
-                               return;
+                               goto exit;
                }
 
                shell_view = e_shell_window_get_shell_view (shell_window,
diff --git a/src/modules/calendar/e-cal-shell-content.c b/src/modules/calendar/e-cal-shell-content.c
index 518091e..ab21665 100644
--- a/src/modules/calendar/e-cal-shell-content.c
+++ b/src/modules/calendar/e-cal-shell-content.c
@@ -2220,7 +2220,7 @@ e_cal_shell_content_update_filters (ECalShellContent *cal_shell_content,
                hide_completed_tasks_sexp = calendar_config_get_hide_completed_tasks_sexp (FALSE);
 
                if (hide_completed_tasks_sexp != NULL) {
-                       if (cal_filter != NULL) {
+                       if (*cal_filter) {
                                gchar *filter;
 
                                filter = g_strdup_printf ("(and %s %s)", hide_completed_tasks_sexp, 
cal_filter);
@@ -2230,7 +2230,7 @@ e_cal_shell_content_update_filters (ECalShellContent *cal_shell_content,
                                cal_shell_content_update_model_filter (data_model, model, 
hide_completed_tasks_sexp, 0, 0);
                        }
                } else {
-                       cal_shell_content_update_model_filter (data_model, model, cal_filter ? cal_filter : 
"#t", 0, 0);
+                       cal_shell_content_update_model_filter (data_model, model, *cal_filter ? cal_filter : 
"#t", 0, 0);
                }
 
                g_free (hide_completed_tasks_sexp);
@@ -2270,7 +2270,7 @@ e_cal_shell_content_update_filters (ECalShellContent *cal_shell_content,
                                "(and (or (not (has-start?)) "
                                "(occur-in-time-range? (make-time \"%s\") "
                                "(make-time \"%s\") \"%s\")) %s)",
-                               iso_start, iso_end, default_tzloc, cal_filter ? cal_filter : "");
+                               iso_start, iso_end, default_tzloc, cal_filter);
 
                        cal_shell_content_update_model_filter (data_model, model, filter, 0, 0);
 
@@ -2278,7 +2278,7 @@ e_cal_shell_content_update_filters (ECalShellContent *cal_shell_content,
                        g_free (iso_start);
                        g_free (iso_end);
                } else {
-                       cal_shell_content_update_model_filter (data_model, model, cal_filter ? cal_filter : 
"#t", 0, 0);
+                       cal_shell_content_update_model_filter (data_model, model, *cal_filter ? cal_filter : 
"#t", 0, 0);
                }
        }
 }
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 00906e1..e93c89c 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -1781,8 +1781,7 @@ webkit_editor_insert_content (EContentEditor *editor,
                }
 
                if (strstr (content, "data-evo-draft") && !(wk_editor->priv->html_mode)) {
-                       if (content && *content)
-                               set_convert_in_situ (wk_editor, TRUE);
+                       set_convert_in_situ (wk_editor, TRUE);
                        wk_editor->priv->reload_in_progress = TRUE;
                        webkit_web_view_load_html (WEBKIT_WEB_VIEW (wk_editor), content, "file://");
                        return;
@@ -1799,8 +1798,7 @@ webkit_editor_insert_content (EContentEditor *editor,
                                        return;
                                }
                        }
-                       if (content && *content)
-                               set_convert_in_situ (wk_editor, TRUE);
+                       set_convert_in_situ (wk_editor, TRUE);
                }
 
                wk_editor->priv->reload_in_progress = TRUE;
diff --git a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c 
b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index c840194..9873ce5 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -2720,12 +2720,9 @@ save_history_before_event_in_table (EEditorPage *editor_page,
                ev = g_new0 (EEditorHistoryEvent, 1);
                ev->type = HISTORY_TABLE_INPUT;
 
-               if (block) {
-                       e_editor_dom_selection_save (editor_page);
-                       ev->data.dom.from = g_object_ref (webkit_dom_node_clone_node_with_error 
(WEBKIT_DOM_NODE (block), TRUE, NULL));
-                       e_editor_dom_selection_restore (editor_page);
-               } else
-                       ev->data.dom.from = NULL;
+               e_editor_dom_selection_save (editor_page);
+               ev->data.dom.from = g_object_ref (webkit_dom_node_clone_node_with_error (WEBKIT_DOM_NODE 
(block), TRUE, NULL));
+               e_editor_dom_selection_restore (editor_page);
 
                e_editor_dom_selection_get_coordinates (editor_page,
                        &ev->before.start.x,
@@ -5250,7 +5247,7 @@ parse_html_into_blocks (EEditorPage *editor_page,
                if (camel_debug ("webkit:editor"))
                        printf ("\tto_process: '%s'\n", to_process);
 
-               if (!*to_process && processing_last) {
+               if (to_process && !*to_process && processing_last) {
                        g_free (to_process);
                        to_process = g_strdup (next_token);
                        next_token = NULL;
@@ -15308,7 +15305,6 @@ e_editor_dom_selection_set_monospace (EEditorPage *editor_page,
        } else {
                gboolean is_bold = FALSE, is_italic = FALSE;
                gboolean is_underline = FALSE, is_strikethrough = FALSE;
-               guint font_size = 0;
                WebKitDOMElement *tt_element;
                WebKitDOMNode *node;
 
@@ -16147,7 +16143,7 @@ process_block_to_block (EEditorPage *editor_page,
 
                                word_wrap_length =
                                        e_editor_page_get_word_wrap_length (editor_page);
-                               quote = citation_level ? citation_level * 2 : 0;
+                               quote = citation_level * 2;
 
                                element = e_editor_dom_wrap_paragraph_length (
                                        editor_page, element, word_wrap_length - quote);
@@ -16492,8 +16488,7 @@ format_change_list_from_list (EEditorPage *editor_page,
                                WEBKIT_DOM_ELEMENT (item), new_list, to);
 
                        webkit_dom_node_append_child (
-                               after_selection_end ?
-                                       source_list_clone : WEBKIT_DOM_NODE (new_list),
+                               WEBKIT_DOM_NODE (new_list),
                                WEBKIT_DOM_NODE (processed_list),
                                NULL);
                } else if (node_is_list (item) && !after_selection_end) {
@@ -16515,10 +16510,7 @@ format_change_list_from_list (EEditorPage *editor_page,
                                        WEBKIT_DOM_NODE (new_list), FALSE, NULL);
 
                                webkit_dom_node_append_child (
-                                       after_selection_end ?
-                                               source_list_clone : WEBKIT_DOM_NODE (new_list),
-                                       clone,
-                                       NULL);
+                                       WEBKIT_DOM_NODE (new_list), clone, NULL);
 
                                while ((child = webkit_dom_node_get_first_child (item))) {
                                        webkit_dom_node_append_child (clone, child, NULL);
@@ -16528,10 +16520,7 @@ format_change_list_from_list (EEditorPage *editor_page,
 
                                if (webkit_dom_node_get_first_child (item))
                                        webkit_dom_node_append_child (
-                                               after_selection_end ?
-                                                       source_list_clone : WEBKIT_DOM_NODE (new_list),
-                                               item,
-                                               NULL);
+                                               WEBKIT_DOM_NODE (new_list), item, NULL);
                                else
                                        remove_node (item);
                        } else {
@@ -17356,10 +17345,8 @@ e_editor_dom_selection_get_coordinates (EEditorPage *editor_page,
                parent = webkit_dom_element_get_offset_parent (parent);
        }
 
-       if (start_x)
-               *start_x = local_x;
-       if (start_y)
-               *start_y = local_y;
+       *start_x = local_x;
+       *start_y = local_y;
 
        if (e_editor_dom_selection_is_collapsed (editor_page)) {
                *end_x = local_x;
@@ -17384,10 +17371,8 @@ e_editor_dom_selection_get_coordinates (EEditorPage *editor_page,
                parent = webkit_dom_element_get_offset_parent (parent);
        }
 
-       if (end_x)
-               *end_x = local_x;
-       if (end_y)
-               *end_y = local_y;
+       *end_x = local_x;
+       *end_y = local_y;
 
        if (created_selection_markers)
                e_editor_dom_selection_restore (editor_page);
diff --git a/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c 
b/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
index 51d1c8b..eeafaaf 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
@@ -1808,11 +1808,12 @@ undo_redo_replace_all (EEditorUndoRedoManager *manager,
                        if (prev_event->type == HISTORY_REPLACE) {
                                undo_redo_replace (editor_page, prev_event, undo);
                                prev_item = prev_item->prev;
-                       } else
+                       } else {
+                               manager->priv->history = prev_item->next;
                                break;
+                       }
                }
 
-               manager->priv->history = prev_item->next;
        }
 }
 
@@ -2722,7 +2723,7 @@ e_editor_undo_redo_manager_redo (EEditorUndoRedoManager *manager)
                        return;
        }
 
-       if (history->prev && history->prev->prev) {
+       if (history->prev->prev) {
                event = history->prev->prev->data;
                if (event->type == HISTORY_AND) {
                        manager->priv->history = manager->priv->history->prev->prev;
diff --git a/src/plugins/mail-notification/mail-notification.c 
b/src/plugins/mail-notification/mail-notification.c
index 803d3cf..3582d81 100644
--- a/src/plugins/mail-notification/mail-notification.c
+++ b/src/plugins/mail-notification/mail-notification.c
@@ -325,7 +325,10 @@ notify_default_action_cb (NotifyNotification *notification,
        if (!list)
                list = fallback;
 
-       g_return_if_fail (list != NULL);
+       if (!list) {
+               g_warn_if_reached ();
+               return;
+       }
 
        /* Present the shell window. */
        shell_window = E_SHELL_WINDOW (list->data);
diff --git a/src/smime/lib/e-cert-db.c b/src/smime/lib/e-cert-db.c
index bfd2024..690da31 100644
--- a/src/smime/lib/e-cert-db.c
+++ b/src/smime/lib/e-cert-db.c
@@ -412,6 +412,9 @@ p12u_ucs2_ascii_conversion_function(PRBool     toUnicode,
        it.data = inBuf;
        it.len = inBufLen;
        dup = SECITEM_DupItem(&it);
+       if (!dup)
+               return PR_FALSE;
+
        /* If converting Unicode to ASCII, swap bytes before conversion
         * as neccessary.
         */
@@ -424,8 +427,7 @@ p12u_ucs2_ascii_conversion_function(PRBool     toUnicode,
        /* Perform the conversion. */
        ret = PORT_UCS2_UTF8Conversion (toUnicode, dup->data, dup->len,
                                        outBuf, maxOutBufLen, outBufLen);
-       if (dup)
-               SECITEM_ZfreeItem(dup, PR_TRUE);
+       SECITEM_ZfreeItem(dup, PR_TRUE);
 
 #ifdef DEBUG_CONVERSION
        if (pk12_debugging) {
diff --git a/src/web-extensions/e-dom-utils.c b/src/web-extensions/e-dom-utils.c
index 96e8b03..3fdcadc 100644
--- a/src/web-extensions/e-dom-utils.c
+++ b/src/web-extensions/e-dom-utils.c
@@ -522,7 +522,7 @@ e_dom_utils_add_css_rule_into_style_sheet_in_document (WebKitDOMDocument *docume
                rule_text = webkit_dom_css_rule_get_css_text (rule);
 
                /* Find the start of the style => end of the selector */
-               if (rule_text && selector && g_str_has_prefix (rule_text, selector) &&
+               if (rule_text && g_str_has_prefix (rule_text, selector) &&
                    rule_text[selector_length] == ' ' && rule_text[selector_length + 1] == '{') {
                        /* If exists remove it */
                        webkit_dom_css_style_sheet_remove_rule (


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