[evolution-mapi] Fix/mute issues found by Coverity scan



commit fffbac63d8e7d4768992a412a90f29d1226504da
Author: Milan Crha <mcrha redhat com>
Date:   Fri Nov 15 14:20:58 2013 +0100

    Fix/mute issues found by Coverity scan
    
    This makes the code free of Coverity scan issues.
    It is sometimes quite pedantic and expects/suggests some
    coding habits, thus certain changes may look weird, but for a good
    thing, I hope. The code is also tagged with Coverity scan
    suppressions, to keep the code as is and hide the warning too.
    Also note that Coverity treats g_return_if_fail(), g_assert() and
    similar macros as unreliable, and it's true these can be disabled
    during the compile time, thus it brings in other set of 'weird'
    changes.

 src/addressbook/e-book-backend-mapi.c          |    2 +-
 src/camel/camel-mapi-folder.c                  |   42 +++++++++--------------
 src/camel/camel-mapi-store.c                   |    3 +-
 src/configuration/e-mail-config-mapi-backend.c |    4 --
 src/configuration/e-mapi-config-utils.c        |    1 +
 src/libexchangemapi/e-mapi-connection.c        |   17 +++++++---
 src/libexchangemapi/e-mapi-utils.c             |    4 ++-
 7 files changed, 36 insertions(+), 37 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-mapi.c b/src/addressbook/e-book-backend-mapi.c
index 9725aea..065a369 100644
--- a/src/addressbook/e-book-backend-mapi.c
+++ b/src/addressbook/e-book-backend-mapi.c
@@ -748,7 +748,7 @@ ebbm_book_view_thread (gpointer data)
                        ebbm_maybe_invoke_cache_update (bvtd->ebma);
 
                        e_book_backend_mapi_update_view_by_cache (bvtd->ebma, bvtd->book_view, &error);
-               } else if (ebmac->op_list_known_uids && ebmac->op_transfer_contacts) {
+               } else if (ebmac && ebmac->op_list_known_uids && ebmac->op_transfer_contacts) {
                        EBookBackendSExp *sexp;
                        const gchar *query;
 
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index cf0c36a..10f63e5 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -605,6 +605,7 @@ gather_object_summary_cb (EMapiConnection *conn,
        const gchar *transport_headers;
        CamelMessageInfo *info;
        gboolean is_new = FALSE;
+       gboolean user_has_read;
 
        g_return_val_if_fail (gos != NULL, FALSE);
        g_return_val_if_fail (gos->folder != NULL, FALSE);
@@ -648,9 +649,9 @@ gather_object_summary_cb (EMapiConnection *conn,
                        if (camel_mime_part_construct_from_parser_sync (part, parser, NULL, NULL)) {
                                info = camel_folder_summary_info_new_from_header (gos->folder->summary, 
part->headers);
                                if (info) {
-                                       CamelMapiMessageInfo *minfo = (CamelMapiMessageInfo *) info;
                                        const uint32_t *msg_size;
 
+                                       minfo = (CamelMapiMessageInfo *) info;
                                        minfo->info.uid = camel_pstring_strdup (uid_str);
 
                                        msg_size = e_mapi_util_find_array_propval (&object->properties, 
PidTagMessageSize);
@@ -688,11 +689,6 @@ gather_object_summary_cb (EMapiConnection *conn,
                        minfo->info.date_received = e_mapi_util_filetime_to_time_t (delivery_time);
                        minfo->info.size = msg_size ? *msg_size : 0;
 
-                       if (minfo->info.date_sent != 0)
-                               minfo->info.date_sent = minfo->info.date_sent;
-                       if (minfo->info.date_received != 0)
-                               minfo->info.date_received = minfo->info.date_received;
-
                        /* Threading related properties */
                        mapi_set_message_id (minfo, message_id);
                        if (references || in_reply_to)
@@ -747,32 +743,28 @@ gather_object_summary_cb (EMapiConnection *conn,
                }
 
                minfo = (CamelMapiMessageInfo *) info;
-               if (minfo) {
-                       if (minfo->info.date_sent == 0)
-                               minfo->info.date_sent = minfo->info.date_received;
-                       if (minfo->info.date_received == 0)
-                               minfo->info.date_received = minfo->info.date_sent;
-               }
+               if (minfo->info.date_sent == 0)
+                       minfo->info.date_sent = minfo->info.date_received;
+               if (minfo->info.date_received == 0)
+                       minfo->info.date_received = minfo->info.date_sent;
        }
 
-       if (info) {
-               gboolean user_has_read = (camel_message_info_flags (info) & CAMEL_MESSAGE_SEEN) != 0;
+       user_has_read = (camel_message_info_flags (info) & CAMEL_MESSAGE_SEEN) != 0;
 
-               update_message_info (info, object, is_new, gos->is_public_folder, user_has_read);
+       update_message_info (info, object, is_new, gos->is_public_folder, user_has_read);
 
-               if (is_new) {
-                       camel_folder_summary_add (gos->folder->summary, info);
-                       camel_folder_change_info_add_uid (gos->changes, camel_message_info_uid (info));
-                       camel_folder_change_info_recent_uid (gos->changes, camel_message_info_uid (info));
+       if (is_new) {
+               camel_folder_summary_add (gos->folder->summary, info);
+               camel_folder_change_info_add_uid (gos->changes, camel_message_info_uid (info));
+               camel_folder_change_info_recent_uid (gos->changes, camel_message_info_uid (info));
 
-                       camel_message_info_ref (info);
-               } else {
-                       camel_folder_change_info_change_uid (gos->changes, camel_message_info_uid (info));
-               }
-
-               camel_message_info_unref (info);
+               camel_message_info_ref (info);
+       } else {
+               camel_folder_change_info_change_uid (gos->changes, camel_message_info_uid (info));
        }
 
+       camel_message_info_unref (info);
+
        if (obj_total > 0)
                camel_operation_progress (cancellable, obj_index * 100 / obj_total);
 
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index 49c036f..e0d8608 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -2941,7 +2941,8 @@ camel_mapi_store_ref_connection (CamelMapiStore *mapi_store,
        if (!mapi_store->priv->connection) {
                g_rec_mutex_unlock (&mapi_store->priv->connection_lock);
 
-               camel_mapi_store_connected (mapi_store, cancellable, error);
+               if (!camel_mapi_store_connected (mapi_store, cancellable, error))
+                       return NULL;
 
                g_rec_mutex_lock (&mapi_store->priv->connection_lock);
        }
diff --git a/src/configuration/e-mail-config-mapi-backend.c b/src/configuration/e-mail-config-mapi-backend.c
index be86ca8..54fd9d5 100644
--- a/src/configuration/e-mail-config-mapi-backend.c
+++ b/src/configuration/e-mail-config-mapi-backend.c
@@ -453,7 +453,6 @@ validate_credentials_cb (GtkWidget *widget,
        CamelNetworkSettings *network_settings;
        const gchar *host;
        const gchar *user;
-       GError *error = NULL;
 
        if (!e_mapi_config_utils_is_online ()) {
                e_notice (NULL, GTK_MESSAGE_ERROR, "%s", _("Cannot authenticate MAPI accounts in offline 
mode"));
@@ -518,9 +517,6 @@ validate_credentials_cb (GtkWidget *widget,
                e_notice (NULL, GTK_MESSAGE_ERROR, "%s", _("Authentication failed."));
        }
 
-       if (error)
-               g_error_free (error);
-
        if (empd.password) {
                memset (empd.password->str, 0, empd.password->len);
                g_string_free (empd.password, TRUE);
diff --git a/src/configuration/e-mapi-config-utils.c b/src/configuration/e-mapi-config-utils.c
index 5b93f33..f0e4f99 100644
--- a/src/configuration/e-mapi-config-utils.c
+++ b/src/configuration/e-mapi-config-utils.c
@@ -1671,6 +1671,7 @@ e_mapi_config_utils_insert_widgets (ESourceConfigBackend *backend,
                case E_MAPI_FOLDER_TYPE_CONTACT:
                        msg = _("Cannot create MAPI address book in offline mode");
                        break;
+               /* coverity[dead_error_begin] */
                default:
                        g_warn_if_reached ();
                        msg = _("Cannot create MAPI source in offline mode");
diff --git a/src/libexchangemapi/e-mapi-connection.c b/src/libexchangemapi/e-mapi-connection.c
index 048ea99..dc73408 100644
--- a/src/libexchangemapi/e-mapi-connection.c
+++ b/src/libexchangemapi/e-mapi-connection.c
@@ -2777,8 +2777,12 @@ e_mapi_connection_fetch_object_internal (EMapiConnection *conn,
                goto cleanup;
        }
 
-       if (object->properties.lpProps)
-               object->properties.lpProps = talloc_steal (object, object->properties.lpProps);
+       if (!object->properties.lpProps) {
+               /* kinf of success, no properties received */
+               goto cleanup;
+       }
+
+       object->properties.lpProps = talloc_steal (object, object->properties.lpProps);
 
        /* to transform named ids to their PidLid or PidName tags, like the fast-transfer does */
        ms = QueryNamedProperties (obj_message, 0, NULL, &np_count, &np_propID, &np_nameid);
@@ -3079,8 +3083,10 @@ e_mapi_connection_transfer_objects (EMapiConnection *conn,
                }
 
                if (g_cancellable_is_cancelled (cancellable)) {
-                       if (perror && !*perror)
+                       if (perror && !*perror) {
+                               /* coverity[unchecked_value] */
                                g_cancellable_set_error_if_cancelled (cancellable, perror);
+                       }
 
                        ms = MAPI_E_USER_CANCEL;
                        mapi_id_array_release (&ids);
@@ -5744,7 +5750,8 @@ e_mapi_connection_resolve_named_props  (EMapiConnection *conn,
 
                                        if (e_mapi_connection_open_default_folder (conn, olFolderContacts, 
&obj_contacts, cancellable, NULL)) {
                                                /* always keep MAPI_E_NOT_FOUND, thus the later processing on 
the storing of saved items is skipped */
-                                               e_mapi_connection_resolve_named_props (conn, &obj_contacts, 
named_ids_list, named_ids_n_elems, cancellable, NULL);
+                                               if (!e_mapi_connection_resolve_named_props (conn, 
&obj_contacts, named_ids_list, named_ids_n_elems, cancellable, NULL))
+                                                       ms = MAPI_E_NOT_FOUND;
                                                e_mapi_connection_close_folder (conn, &obj_contacts, 
cancellable, NULL);
                                        }
                                }
@@ -6754,7 +6761,7 @@ e_mapi_connection_resolve_username (EMapiConnection *conn,
                        replace_hash = prepare_maybe_replace_hash (named_ids_list, named_ids_len, FALSE);
 
                for (qq = 0; qq < rows->cRows; qq++) {
-                       struct mapi_SPropValue_array *properties;
+                       struct mapi_SPropValue_array *properties = NULL;
                        struct SRow *row;
 
                        row = talloc_zero (mem_ctx, struct SRow);
diff --git a/src/libexchangemapi/e-mapi-utils.c b/src/libexchangemapi/e-mapi-utils.c
index d71831d..b88052f 100644
--- a/src/libexchangemapi/e-mapi-utils.c
+++ b/src/libexchangemapi/e-mapi-utils.c
@@ -101,8 +101,10 @@ e_mapi_cancellable_rec_mutex_lock (EMapiCancellableRecMutex *rec_mutex,
        }
 
        if (g_cancellable_is_cancelled (cancellable)) {
-               if (error && !*error)
+               if (error && !*error) {
+                       /* coverity[unchecked_value] */
                        g_cancellable_set_error_if_cancelled (cancellable, error);
+               }
                g_mutex_unlock (&rec_mutex->cond_mutex);
                return FALSE;
        }


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