[evolution-data-server] Address some Coveriry Scan detected issues



commit 2e800e11a57b8cc076c65ead5532437b359ce1fc
Author: Milan Crha <mcrha redhat com>
Date:   Fri May 22 08:49:12 2015 +0200

    Address some Coveriry Scan detected issues

 addressbook/libebook-contacts/e-vcard.c            |    2 +-
 addressbook/libedata-book/e-book-sqlite.c          |    3 +-
 addressbook/libedata-book/e-data-book-cursor.c     |    6 +++-
 calendar/libedata-cal/e-cal-backend-intervaltree.c |    5 ++-
 camel/providers/imapx/camel-imapx-server.c         |    8 +++--
 camel/providers/imapx/camel-imapx-store-summary.c  |    1 +
 camel/providers/imapx/camel-imapx-utils.c          |   38 +++++++++++--------
 camel/providers/pop3/camel-pop3-store.c            |    8 ++--
 tests/test-server-utils/e-test-server-utils.c      |    2 +-
 9 files changed, 45 insertions(+), 28 deletions(-)
---
diff --git a/addressbook/libebook-contacts/e-vcard.c b/addressbook/libebook-contacts/e-vcard.c
index caced51..5a74eea 100644
--- a/addressbook/libebook-contacts/e-vcard.c
+++ b/addressbook/libebook-contacts/e-vcard.c
@@ -1337,7 +1337,7 @@ e_vcard_to_string_vcard_30 (EVCard *evc)
                                        gchar *value = v->data;
                                        gchar *pval = value;
                                        gboolean quotes = FALSE;
-                                       while (*pval) {
+                                       while (pval && *pval) {
                                                if (!g_unichar_isalnum (g_utf8_get_char (pval))) {
                                                        quotes = TRUE;
                                                        break;
diff --git a/addressbook/libedata-book/e-book-sqlite.c b/addressbook/libedata-book/e-book-sqlite.c
index 0e9ea83..784af2d 100644
--- a/addressbook/libedata-book/e-book-sqlite.c
+++ b/addressbook/libedata-book/e-book-sqlite.c
@@ -2807,7 +2807,7 @@ ebsql_init_legacy_keys (EBookSqlite *ebsql,
                }
 
                /* Repeat for 'sync_data' */
-               success = ebsql_exec_printf (
+               success = success && ebsql_exec_printf (
                        ebsql, "SELECT sync_data FROM folders WHERE folder_id = %Q",
                        get_string_cb, &sync_data, NULL, error, ebsql->priv->folderid);
 
@@ -5492,6 +5492,7 @@ ebsql_generate_constraints (EBookSqlite *ebsql,
                g_warn_if_fail (test->field != NULL);
 
                /* Generate the field test */
+               /* coverity[var_deref_op] */
                generate_test_func (ebsql, string, test);
        }
 
diff --git a/addressbook/libedata-book/e-data-book-cursor.c b/addressbook/libedata-book/e-data-book-cursor.c
index 16375e7..fc01872 100644
--- a/addressbook/libedata-book/e-data-book-cursor.c
+++ b/addressbook/libedata-book/e-data-book-cursor.c
@@ -499,9 +499,13 @@ calculate_step_position (EDataBookCursor *cursor,
                          gint results)
 {
        EDataBookCursorPrivate *priv = cursor->priv;
-       gint new_position = priv->position;
+       gint new_position;
        gint offset = results;
 
+       g_return_if_fail (origin == E_BOOK_CURSOR_ORIGIN_CURRENT ||
+                         origin == E_BOOK_CURSOR_ORIGIN_BEGIN ||
+                         origin == E_BOOK_CURSOR_ORIGIN_END);
+
        /* If we didnt get as many contacts as asked for, it indicates that
         * we've reached the end of the list (or beginning)... in this case
         * we add 1 to the offset
diff --git a/calendar/libedata-cal/e-cal-backend-intervaltree.c 
b/calendar/libedata-cal/e-cal-backend-intervaltree.c
index 0cc6194..17b4f92 100644
--- a/calendar/libedata-cal/e-cal-backend-intervaltree.c
+++ b/calendar/libedata-cal/e-cal-backend-intervaltree.c
@@ -228,7 +228,7 @@ static void
 fixup_min_max_fields (EIntervalTree *tree,
                       EIntervalNode *node)
 {
-       while (node != tree->priv->root) {
+       while (node && node != tree->priv->root) {
                node->max = MAX (node->end, MAX (node->left->max, node->right->max));
                node->min = MIN (node->start, node->left->min);
 
@@ -319,6 +319,9 @@ intervaltree_fixup_deletion (EIntervalTree *tree,
        EIntervalNode *w;
 
        while ((!x->red) && (root != x)) {
+               if (!x->parent)
+                       break;
+
                if (x == x->parent->left) {
                        w = x->parent->right;
 
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 533f52f..641c733 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -1261,6 +1261,7 @@ imapx_command_start (CamelIMAPXServer *is,
        GCancellable *cancellable = NULL;
        gboolean cp_continuation;
        gboolean cp_literal_plus;
+       gboolean success;
        GList *head;
        gchar *string;
        GError *local_error = NULL;
@@ -1326,13 +1327,13 @@ imapx_command_start (CamelIMAPXServer *is,
        string = g_strdup_printf (
                "%c%05u %s\r\n", is->tagprefix, ic->tag, cp->data);
        g_mutex_lock (&is->priv->stream_lock);
-       g_output_stream_write_all (
+       success = g_output_stream_write_all (
                output_stream, string, strlen (string),
                NULL, cancellable, &local_error);
        g_mutex_unlock (&is->priv->stream_lock);
        g_free (string);
 
-       if (local_error != NULL)
+       if (local_error != NULL || !success)
                goto fail;
 
        while (is->literal == ic && cp_literal_plus) {
@@ -1362,7 +1363,7 @@ fail:
        if (ic->complete != NULL)
                ic->complete (is, ic);
 
-       g_error_free (local_error);
+       g_clear_error (&local_error);
 
 exit:
        g_clear_object (&input_stream);
@@ -4628,6 +4629,7 @@ connected:
 
                input_stream = camel_imapx_server_ref_input_stream (is);
 
+               token = NULL;
                tok = camel_imapx_input_stream_token (
                        CAMEL_IMAPX_INPUT_STREAM (input_stream),
                        &token, &len, cancellable, error);
diff --git a/camel/providers/imapx/camel-imapx-store-summary.c 
b/camel/providers/imapx/camel-imapx-store-summary.c
index 3465135..577aff4 100644
--- a/camel/providers/imapx/camel-imapx-store-summary.c
+++ b/camel/providers/imapx/camel-imapx-store-summary.c
@@ -187,6 +187,7 @@ imapx_store_summary_store_info_load (CamelStoreSummary *summary,
 
        if (camel_file_util_decode_string (in, &mailbox_name) == -1) {
                camel_store_summary_info_unref (summary, si);
+               g_free (separator);
                return NULL;
        }
 
diff --git a/camel/providers/imapx/camel-imapx-utils.c b/camel/providers/imapx/camel-imapx-utils.c
index 9e39bdf..956b22b 100644
--- a/camel/providers/imapx/camel-imapx-utils.c
+++ b/camel/providers/imapx/camel-imapx-utils.c
@@ -845,14 +845,12 @@ imapx_parse_ext_optional (CamelIMAPXInputStream *stream,
                        dinfo = g_malloc0 (sizeof (*dinfo));
                        dinfo->refcount = 1;
                        /* should be string */
-                       tok = camel_imapx_input_stream_astring (
-                               stream, &token, cancellable, NULL);
-
-                       if (tok != IMAPX_TOK_STRING) {
-                               g_set_error (
-                                       &local_error,
-                                       CAMEL_IMAPX_ERROR, 1,
-                                       "expecting string");
+                       if (!camel_imapx_input_stream_astring (stream, &token, cancellable, &local_error)) {
+                               if (!local_error)
+                                       g_set_error (
+                                               &local_error,
+                                               CAMEL_IMAPX_ERROR, 1,
+                                               "expecting string");
                                goto done;
                        }
 
@@ -1057,14 +1055,20 @@ imapx_parse_address_list (CamelIMAPXInputStream *stream,
                        addr = camel_header_address_new ();
                        addr->type = CAMEL_HEADER_ADDRESS_NAME;
                        camel_imapx_input_stream_nstring (stream, &token, cancellable, &local_error);
-                       if (local_error)
+                       if (local_error) {
+                               camel_header_address_unref (addr);
                                goto error;
+                       }
 
                        addr->name = g_strdup ((gchar *) token);
                        /* we ignore the route, nobody uses it in the real world */
                        camel_imapx_input_stream_nstring (stream, &token, cancellable, &local_error);
-                       if (local_error)
+                       if (local_error) {
+                               camel_header_address_unref (addr);
                                goto error;
+                       }
+
+                       mbox = NULL;
 
                        /* [RFC-822] group syntax is indicated by a special
                         * form of address structure in which the host name
@@ -1075,18 +1079,23 @@ imapx_parse_address_list (CamelIMAPXInputStream *stream,
                         * mailbox name field holds the group name phrase. */
 
                        camel_imapx_input_stream_nstring (stream, (guchar **) &mbox, cancellable, 
&local_error);
-                       if (local_error)
+                       if (local_error) {
+                               camel_header_address_unref (addr);
                                goto error;
+                       }
 
                        mbox = g_strdup (mbox);
 
                        camel_imapx_input_stream_nstring (stream, &host, cancellable, &local_error);
-                       if (local_error)
+                       if (local_error) {
+                               camel_header_address_unref (addr);
                                goto error;
+                       }
 
                        if (host == NULL) {
                                if (mbox == NULL) {
                                        group = NULL;
+                                       camel_header_address_unref (addr);
                                } else {
                                        g_free (addr->name);
                                        addr->name = mbox;
@@ -1337,10 +1346,7 @@ imapx_parse_body (CamelIMAPXInputStream *stream,
                                stream, tok, token, len);
                } while (tok == '(');
 
-               camel_imapx_input_stream_astring (
-                       stream, &token, cancellable, &local_error);
-
-               if (local_error)
+               if (!camel_imapx_input_stream_astring (stream, &token, cancellable, &local_error) || 
local_error)
                        goto error;
 
                cinfo->type = camel_content_type_new (
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index 9d83889..25dd1ae 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -340,10 +340,10 @@ try_sasl (CamelPOP3Store *store,
                if (strncmp ((gchar *) line, "+ ", 2) != 0
                    || camel_sasl_get_authenticated (sasl)
                    || (resp = (guchar *) camel_sasl_challenge_base64_sync (sasl, (const gchar *) line + 2, 
cancellable, &local_error)) == NULL) {
-                       camel_stream_write_string (
-                               CAMEL_STREAM (pop3_stream), "*\r\n", cancellable, NULL);
-                       /* coverity[unchecked_value] */
-                       camel_pop3_stream_line (pop3_stream, &line, &len, cancellable, NULL);
+                       if (camel_stream_write_string (CAMEL_STREAM (pop3_stream), "*\r\n", cancellable, 
NULL)) {
+                               /* coverity[unchecked_value] */
+                               camel_pop3_stream_line (pop3_stream, &line, &len, cancellable, NULL);
+                       }
 
                        if (local_error) {
                                g_propagate_error (error, local_error);
diff --git a/tests/test-server-utils/e-test-server-utils.c b/tests/test-server-utils/e-test-server-utils.c
index d0784dd..180ef03 100644
--- a/tests/test-server-utils/e-test-server-utils.c
+++ b/tests/test-server-utils/e-test-server-utils.c
@@ -412,7 +412,7 @@ e_test_server_utils_source_added (ESourceRegistry *registry,
 
                if (!pair->closure->use_async_connect &&
                    !pair->fixture->service.book_client)
-                       g_error ("Unable to create the test book: %s", error->message);
+                       g_error ("Unable to create the test book: %s", error ? error->message : "Unknown 
error");
 
                break;
 


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