[evolution-data-server] Fix some issues found by Coverity Scan



commit a37ae2cf0b1217cec624ba12d83b991ff0738775
Author: Milan Crha <mcrha redhat com>
Date:   Tue Sep 26 13:35:07 2017 +0200

    Fix some issues found by Coverity Scan

 src/addressbook/libedata-book/e-book-cache.c  |    4 ++--
 src/calendar/libedata-cal/e-cal-cache.c       |    3 ++-
 src/camel/camel-filter-search.c               |   14 ++++++++++----
 src/camel/providers/nntp/camel-nntp-summary.c |    5 -----
 src/camel/tests/folder/test2.c                |    2 +-
 src/camel/tests/folder/test8.c                |    6 +++---
 src/camel/tests/folder/test9.c                |    2 +-
 src/camel/tests/message/test1.c               |    8 ++++----
 src/camel/tests/mime-filter/test-charset.c    |    3 ++-
 src/libebackend/e-server-side-source.c        |   10 +++++-----
 src/libebackend/e-source-registry-server.c    |    5 ++++-
 src/libedataserver/e-webdav-session.c         |    6 +++++-
 src/libedataserver/e-xml-document.c           |    8 +++-----
 tests/libedata-book/test-book-meta-backend.c  |    4 ++--
 tests/libedata-cal/test-cal-meta-backend.c    |    4 ++--
 15 files changed, 46 insertions(+), 38 deletions(-)
---
diff --git a/src/addressbook/libedata-book/e-book-cache.c b/src/addressbook/libedata-book/e-book-cache.c
index 601c030..6899cd7 100644
--- a/src/addressbook/libedata-book/e-book-cache.c
+++ b/src/addressbook/libedata-book/e-book-cache.c
@@ -4263,7 +4263,7 @@ e_book_cache_migrate (ECache *cache,
                        const gchar *name = link->data;
                        gchar *stmt;
 
-                       if (!link)
+                       if (!name)
                                continue;
 
                        stmt = e_cache_sqlite_stmt_printf ("DROP TABLE IF EXISTS %Q", name);
@@ -4695,7 +4695,7 @@ e_book_cache_set_locale (EBookCache *book_cache,
 
        g_free (stored_lc_collate);
 
-       if (success && changed)
+       if (success || changed)
                g_object_notify (G_OBJECT (book_cache), "locale");
 
        return success;
diff --git a/src/calendar/libedata-cal/e-cal-cache.c b/src/calendar/libedata-cal/e-cal-cache.c
index ac82a6c..0f8d198 100644
--- a/src/calendar/libedata-cal/e-cal-cache.c
+++ b/src/calendar/libedata-cal/e-cal-cache.c
@@ -3653,7 +3653,8 @@ ecc_list_cached_timezones (ETimezoneCache *cache)
 {
        GList *timezones = NULL;
 
-       e_cal_cache_list_timezones (E_CAL_CACHE (cache), &timezones, NULL, NULL);
+       if (!e_cal_cache_list_timezones (E_CAL_CACHE (cache), &timezones, NULL, NULL))
+               return NULL;
 
        return timezones;
 }
diff --git a/src/camel/camel-filter-search.c b/src/camel/camel-filter-search.c
index 21374f4..cf8d943 100644
--- a/src/camel/camel-filter-search.c
+++ b/src/camel/camel-filter-search.c
@@ -1194,6 +1194,14 @@ message_location (struct _CamelSExp *f,
        return r;
 }
 
+static const gchar *
+camel_search_result_to_string (gint value)
+{
+       return value == CAMEL_SEARCH_ERROR ? "ERROR" :
+              value == CAMEL_SEARCH_NOMATCH ? "NOMATCH" :
+              value == CAMEL_SEARCH_MATCHED ? "MATCHED" : "???";
+}
+
 /**
  * camel_filter_search_match_with_log:
  * @session:
@@ -1227,7 +1235,7 @@ camel_filter_search_match_with_log (CamelSession *session,
        FilterMessageSearch fms;
        CamelSExp *sexp;
        CamelSExpResult *result;
-       gboolean retval;
+       gint retval;
        GError *local_error = NULL;
        gint i;
 
@@ -1295,9 +1303,7 @@ camel_filter_search_match_with_log (CamelSession *session,
                        camel_message_info_get_uid (info), camel_message_info_get_subject (info),
                        folder ? camel_service_get_display_name (CAMEL_SERVICE (camel_folder_get_parent_store 
(folder))) : "NULL",
                        folder ? camel_folder_get_full_name (folder) : "NULL",
-                       retval == CAMEL_SEARCH_ERROR ? "ERROR" :
-                       retval == CAMEL_SEARCH_NOMATCH ? "NOMATCH" :
-                       retval == CAMEL_SEARCH_MATCHED ? "MATCHED" : "???");
+                       camel_search_result_to_string (retval));
        }
 
        return retval;
diff --git a/src/camel/providers/nntp/camel-nntp-summary.c b/src/camel/providers/nntp/camel-nntp-summary.c
index 39e6fac..d4e1a50 100644
--- a/src/camel/providers/nntp/camel-nntp-summary.c
+++ b/src/camel/providers/nntp/camel-nntp-summary.c
@@ -500,11 +500,6 @@ nntp_get_existing_article_numbers (CamelNNTPSummary *cns,
 
        camel_operation_pop_message (cancellable);
 
-       if (ret != 0 && existing_articles) {
-               g_hash_table_destroy (existing_articles);
-               existing_articles = NULL;
-       }
-
        return existing_articles;
 }
 
diff --git a/src/camel/tests/folder/test2.c b/src/camel/tests/folder/test2.c
index b43bb0e..99ae197 100644
--- a/src/camel/tests/folder/test2.c
+++ b/src/camel/tests/folder/test2.c
@@ -53,7 +53,7 @@ gint main (gint argc, gchar **argv)
        }
 
        /* create a pseudo-spool file, and check that */
-       creat ("/tmp/camel-test/testbox", 0600);
+       g_warn_if_fail (creat ("/tmp/camel-test/testbox", 0600) != -1);
        test_folder_message_ops (session, "spool:///tmp/camel-test/testbox", TRUE, "INBOX");
 
        check_unref (session, 1);
diff --git a/src/camel/tests/folder/test8.c b/src/camel/tests/folder/test8.c
index 1c5ee94..d44de66 100644
--- a/src/camel/tests/folder/test8.c
+++ b/src/camel/tests/folder/test8.c
@@ -88,7 +88,7 @@ worker (gpointer d)
                push ("searching for message %d\n\tusing: %s", id + i, sub);
                res = camel_folder_search_by_expression (info->folder, sub, NULL, &error);
                check_msg (error == NULL, "%s", error->message);
-               check_msg (res->len == 1, "res->len = %d", res->len);
+               check_msg (res && res->len == 1, "res->len = %d", res ? res->len : -1);
                g_clear_error (&error);
                pull ();
 
@@ -106,7 +106,7 @@ worker (gpointer d)
                pull ();
 
                push ("deleting message, cleanup");
-               j = (100.0 * rand () / (RAND_MAX + 1.0));
+               j = g_random_int_range (0, 100);
                if (j <= 70) {
                        camel_folder_delete_message (info->folder, res->pdata[0]);
                }
@@ -119,7 +119,7 @@ worker (gpointer d)
                pull ();
 
                /* about 1-in 100 calls will expunge */
-               j = (200.0 * rand () / (RAND_MAX + 1.0));
+               j = g_random_int_range (0, 200);
                if (j <= 2) {
                        push ("expunging folder");
                        camel_folder_expunge_sync (info->folder, NULL, &error);
diff --git a/src/camel/tests/folder/test9.c b/src/camel/tests/folder/test9.c
index 1b0141a..53716bf 100644
--- a/src/camel/tests/folder/test9.c
+++ b/src/camel/tests/folder/test9.c
@@ -164,7 +164,7 @@ gint main (gint argc, gchar **argv)
                camel_mime_message_set_date (msg, j * 60 * 24, 0);
                pull ();
 
-               camel_stream_write_string (mbox, "From \n", NULL, NULL);
+               g_warn_if_fail (camel_stream_write_string (mbox, "From \n", NULL, NULL));
                check (camel_data_wrapper_write_to_stream_sync (
                        CAMEL_DATA_WRAPPER (msg), mbox, NULL, NULL) != -1);
 #if 0
diff --git a/src/camel/tests/message/test1.c b/src/camel/tests/message/test1.c
index 472456e..273e612 100644
--- a/src/camel/tests/message/test1.c
+++ b/src/camel/tests/message/test1.c
@@ -86,8 +86,8 @@ setup (void)
        srand (42);
        p = texts[12].text = g_malloc (1024);
        for (i = 0; i < 1024; i++) {
-               j = rand ();
-               if (j < RAND_MAX / 120)
+               j = g_random_int ();
+               if (j < G_MAXUINT32 / 120)
                        *p++ = '\n';
                else
                        *p++ = (j % 95) + 32;
@@ -95,8 +95,8 @@ setup (void)
        texts[12].len = 1024;
        p = texts[13].text = g_malloc (102400);
        for (i = 0; i < 102400; i++) {
-               j = rand ();
-               if (j < RAND_MAX / 120)
+               j = g_random_int ();
+               if (j < G_MAXUINT32 / 120)
                        *p++ = '\n';
                else
                        *p++ = (j % 95) + 32;
diff --git a/src/camel/tests/mime-filter/test-charset.c b/src/camel/tests/mime-filter/test-charset.c
index c68e688..e8235df 100644
--- a/src/camel/tests/mime-filter/test-charset.c
+++ b/src/camel/tests/mime-filter/test-charset.c
@@ -103,7 +103,8 @@ test_case (const gchar *basename)
 
        charset = g_strdup (basename + 8);
        ext = strchr (charset, '.');
-       *((gchar *) ext) = '\0';
+       if (ext)
+               *((gchar *) ext) = '\0';
 
        filter = camel_mime_filter_charset_new (charset, "UTF-8");
        if (filter == NULL) {
diff --git a/src/libebackend/e-server-side-source.c b/src/libebackend/e-server-side-source.c
index e357742..8ba51ef 100644
--- a/src/libebackend/e-server-side-source.c
+++ b/src/libebackend/e-server-side-source.c
@@ -1987,7 +1987,7 @@ e_server_side_source_load (EServerSideSource *source,
        EDBusSource *dbus_source;
        GKeyFile *key_file;
        GFile *file;
-       gboolean success;
+       gboolean success = TRUE;
        gchar *data = NULL;
        gsize length;
        GError *local_error = NULL;
@@ -1996,10 +1996,10 @@ e_server_side_source_load (EServerSideSource *source,
 
        file = e_server_side_source_get_file (source);
 
-       if (file != NULL)
-               g_file_load_contents (
-                       file, cancellable, &data,
-                       &length, NULL, &local_error);
+       if (file != NULL && !g_file_load_contents (file, cancellable, &data, &length, NULL, &local_error)) {
+               data = NULL;
+               length = 0;
+       }
 
        /* Disregard G_IO_ERROR_NOT_FOUND and treat it as a successful load. */
        if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
diff --git a/src/libebackend/e-source-registry-server.c b/src/libebackend/e-source-registry-server.c
index ec700be..738d1c4 100644
--- a/src/libebackend/e-source-registry-server.c
+++ b/src/libebackend/e-source-registry-server.c
@@ -1609,7 +1609,10 @@ source_registry_server_tweak_key_file (ESourceRegistryServer *server,
 
        key_file = g_key_file_new ();
 
-       g_file_load_contents (file, NULL, &contents, &length, NULL, error);
+       if (!g_file_load_contents (file, NULL, &contents, &length, NULL, error)) {
+               contents = NULL;
+               length = 0;
+       }
 
        if (contents != NULL) {
                success = g_key_file_load_from_data (
diff --git a/src/libedataserver/e-webdav-session.c b/src/libedataserver/e-webdav-session.c
index 2b9281a..c1c02cb 100644
--- a/src/libedataserver/e-webdav-session.c
+++ b/src/libedataserver/e-webdav-session.c
@@ -4165,7 +4165,11 @@ e_webdav_session_extract_acl_principal (xmlXPathContextPtr xpath_ctx,
        g_return_val_if_fail (principal_prefix != NULL, E_WEBDAV_ACE_PRINCIPAL_UNKNOWN);
        g_return_val_if_fail (out_principal_href != NULL || out_principal_hrefs != NULL, 
E_WEBDAV_ACE_PRINCIPAL_UNKNOWN);
 
-       *out_principal_href = NULL;
+       if (out_principal_href)
+               *out_principal_href = NULL;
+
+       if (out_principal_hrefs)
+               *out_principal_hrefs = NULL;
 
        if (!e_xml_xpath_eval_exists (xpath_ctx, "%s", principal_prefix))
                return E_WEBDAV_ACE_PRINCIPAL_UNKNOWN;
diff --git a/src/libedataserver/e-xml-document.c b/src/libedataserver/e-xml-document.c
index 87d97ef..74f4ad5 100644
--- a/src/libedataserver/e-xml-document.c
+++ b/src/libedataserver/e-xml-document.c
@@ -234,9 +234,10 @@ e_xml_document_add_namespaces (EXmlDocument *xml,
 
                if (!g_hash_table_contains (xml->priv->namespaces_by_href, ns_href)) {
                        ns = xmlNewNs (xml->priv->root, (const xmlChar *) ns_href, (const xmlChar *) 
ns_prefix);
-                       g_return_if_fail (ns != NULL);
+                       g_warn_if_fail (ns != NULL);
 
-                       g_hash_table_insert (xml->priv->namespaces_by_href, g_strdup (ns_href), ns);
+                       if (ns)
+                               g_hash_table_insert (xml->priv->namespaces_by_href, g_strdup (ns_href), ns);
                }
        }
 
@@ -274,9 +275,6 @@ e_xml_document_gen_ns_prefix (EXmlDocument *xml,
        g_return_val_if_fail (E_IS_XML_DOCUMENT (xml), NULL);
        g_return_val_if_fail (ns_href && *ns_href, NULL);
 
-       if (!ns_href)
-               return NULL;
-
        prefixes = g_hash_table_new (g_str_hash, g_str_equal);
 
        g_hash_table_iter_init (&iter, xml->priv->namespaces_by_href);
diff --git a/tests/libedata-book/test-book-meta-backend.c b/tests/libedata-book/test-book-meta-backend.c
index 331032c..a0de5cb 100644
--- a/tests/libedata-book/test-book-meta-backend.c
+++ b/tests/libedata-book/test-book-meta-backend.c
@@ -936,7 +936,7 @@ test_create_contacts (EBookMetaBackend *meta_backend)
        g_assert_nonnull (vcards[0]);
        tmp = strstr (vcards[0], "UID:custom-9\r\n");
        g_assert_nonnull (tmp);
-       strncpy (tmp, "X-TEST:*007*", 12);
+       memcpy (tmp, "X-TEST:*007*", 12);
 
        success = E_BOOK_BACKEND_GET_CLASS (meta_backend)->create_contacts_sync (E_BOOK_BACKEND 
(meta_backend),
                (const gchar * const *) vcards, &new_contacts, NULL, &error);
@@ -1016,7 +1016,7 @@ test_modify_contacts (EBookMetaBackend *meta_backend)
        g_assert_nonnull (vcards[0]);
        tmp = strstr (vcards[0], "UID:custom-1");
        g_assert_nonnull (tmp);
-       strncpy (tmp + 4, "unknown", 7);
+       memcpy (tmp + 4, "unknown", 7);
 
        success = E_BOOK_BACKEND_GET_CLASS (meta_backend)->modify_contacts_sync (E_BOOK_BACKEND 
(meta_backend),
                (const gchar * const *) vcards, &new_contacts, NULL, &error);
diff --git a/tests/libedata-cal/test-cal-meta-backend.c b/tests/libedata-cal/test-cal-meta-backend.c
index 7536c14..2382b09 100644
--- a/tests/libedata-cal/test-cal-meta-backend.c
+++ b/tests/libedata-cal/test-cal-meta-backend.c
@@ -1659,7 +1659,7 @@ test_create_objects (ECalMetaBackend *meta_backend)
        g_assert_nonnull (calobj);
        tmp = strstr (calobj, "UID:event-9\r\n");
        g_assert_nonnull (tmp);
-       strncpy (tmp, "X-TEST:*007", 11);
+       memcpy (tmp, "X-TEST:*007", 11);
 
        objects = g_slist_prepend (NULL, calobj);
 
@@ -1740,7 +1740,7 @@ test_modify_objects (ECalMetaBackend *meta_backend)
        g_assert_nonnull (calobj);
        tmp = strstr (calobj, "UID:event-1");
        g_assert_nonnull (tmp);
-       strncpy (tmp + 4, "unknown", 7);
+       memcpy (tmp + 4, "unknown", 7);
 
        objects = g_slist_prepend (NULL, calobj);
 


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