[evolution-data-server] Address some compiler warnings and Coverity scan issues in a different way



commit 0d7ce26e331c5571589baa8a8e50685009283451
Author: Milan Crha <mcrha redhat com>
Date:   Fri Nov 15 21:06:44 2013 +0100

    Address some compiler warnings and Coverity scan issues in a different way
    
    The previous Coverity scan commit used not so great way of dealing
    with certain warnings, which also did not help with compiler warnings,
    which this commit tries to change.

 camel/camel-file-utils.c                    |   14 ++++++++++----
 camel/camel-gpg-context.c                   |   18 ++++++++++++------
 camel/camel-lock-client.c                   |   25 +++++++++++++++++--------
 camel/camel-lock.c                          |   12 +++++++++---
 camel/camel-movemail.c                      |    8 +++++++-
 camel/camel-multipart-signed.c              |   10 ++++++++--
 camel/camel-smime-context.c                 |    4 +++-
 camel/camel-stream-process.c                |    8 +++++++-
 camel/providers/imapx/test-imapx.c          |    4 +++-
 camel/providers/local/camel-maildir-store.c |   15 +++++++++++----
 camel/providers/local/camel-mbox-summary.c  |    8 +++++++-
 camel/providers/local/camel-spool-summary.c |    4 +++-
 camel/providers/pop3/camel-pop3-folder.c    |    6 ++++--
 13 files changed, 101 insertions(+), 35 deletions(-)
---
diff --git a/camel/camel-file-utils.c b/camel/camel-file-utils.c
index 0ef9f98..c80cf3e 100644
--- a/camel/camel-file-utils.c
+++ b/camel/camel-file-utils.c
@@ -47,6 +47,12 @@
 
 #define IO_TIMEOUT (60*4)
 
+#define CHECK_CALL(x) G_STMT_START { \
+       if ((x) == -1) { \
+               g_debug ("%s: Call of '" #x "' failed: %s", G_STRFUNC, g_strerror (errno)); \
+       } \
+       } G_STMT_END
+
 /**
  * camel_file_util_encode_uint32:
  * @out: file to output to
@@ -454,7 +460,7 @@ camel_read (gint fd,
                fd_set rdset;
 
                flags = fcntl (fd, F_GETFL);
-               (void) fcntl (fd, F_SETFL, flags | O_NONBLOCK);
+               CHECK_CALL (fcntl (fd, F_SETFL, flags | O_NONBLOCK));
 
                do {
                        struct timeval tv;
@@ -484,7 +490,7 @@ camel_read (gint fd,
                } while (nread == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
        failed:
                errnosav = errno;
-               (void) fcntl (fd, F_SETFL, flags);
+               CHECK_CALL (fcntl (fd, F_SETFL, flags));
                errno = errnosav;
 #endif
        }
@@ -550,7 +556,7 @@ camel_write (gint fd,
                fd_set rdset, wrset;
 
                flags = fcntl (fd, F_GETFL);
-               (void) fcntl (fd, F_SETFL, flags | O_NONBLOCK);
+               CHECK_CALL (fcntl (fd, F_SETFL, flags | O_NONBLOCK));
 
                fdmax = MAX (fd, cancel_fd) + 1;
                do {
@@ -587,7 +593,7 @@ camel_write (gint fd,
                } while (w != -1 && written < n);
 
                errnosav = errno;
-               (void) fcntl (fd, F_SETFL, flags);
+               CHECK_CALL (fcntl (fd, F_SETFL, flags));
                errno = errnosav;
 #endif
        }
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index 2dd52ac..7878cb8 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -73,6 +73,12 @@
 static gint logid;
 #endif
 
+#define CHECK_CALL(x) G_STMT_START { \
+       if ((x) == -1) { \
+               g_debug ("%s: Call of '" #x "' failed: %s", G_STRFUNC, g_strerror (errno)); \
+       } \
+       } G_STMT_END
+
 #define CAMEL_GPG_CONTEXT_GET_PRIVATE(obj) \
        (G_TYPE_INSTANCE_GET_PRIVATE \
        ((obj), CAMEL_TYPE_GPG_CONTEXT, CamelGpgContextPrivate))
@@ -645,7 +651,7 @@ gpg_ctx_op_start (struct _GpgCtx *gpg,
                for (i = 3; i < maxfd; i++) {
                        /* don't close the status-fd or passwd-fd */
                        if (i != fds[7] && i != fds[8])
-                               (void) fcntl (i, F_SETFD, FD_CLOEXEC);
+                               CHECK_CALL (fcntl (i, F_SETFD, FD_CLOEXEC));
                }
 
                /* run gpg */
@@ -676,20 +682,20 @@ gpg_ctx_op_start (struct _GpgCtx *gpg,
                close (fds[8]);
                gpg->passwd_fd = fds[9];
                flags = fcntl (gpg->passwd_fd, F_GETFL);
-               (void) fcntl (gpg->passwd_fd, F_SETFL, flags | O_NONBLOCK);
+               CHECK_CALL (fcntl (gpg->passwd_fd, F_SETFL, flags | O_NONBLOCK));
        }
 
        flags = fcntl (gpg->stdin_fd, F_GETFL);
-       (void) fcntl (gpg->stdin_fd, F_SETFL, flags | O_NONBLOCK);
+       CHECK_CALL (fcntl (gpg->stdin_fd, F_SETFL, flags | O_NONBLOCK));
 
        flags = fcntl (gpg->stdout_fd, F_GETFL);
-       (void) fcntl (gpg->stdout_fd, F_SETFL, flags | O_NONBLOCK);
+       CHECK_CALL (fcntl (gpg->stdout_fd, F_SETFL, flags | O_NONBLOCK));
 
        flags = fcntl (gpg->stderr_fd, F_GETFL);
-       (void) fcntl (gpg->stderr_fd, F_SETFL, flags | O_NONBLOCK);
+       CHECK_CALL (fcntl (gpg->stderr_fd, F_SETFL, flags | O_NONBLOCK));
 
        flags = fcntl (gpg->status_fd, F_GETFL);
-       (void) fcntl (gpg->status_fd, F_SETFL, flags | O_NONBLOCK);
+       CHECK_CALL (fcntl (gpg->status_fd, F_SETFL, flags | O_NONBLOCK));
 
        return TRUE;
 
diff --git a/camel/camel-lock-client.c b/camel/camel-lock-client.c
index 5ccb525..6ea158b 100644
--- a/camel/camel-lock-client.c
+++ b/camel/camel-lock-client.c
@@ -32,6 +32,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <glib/gi18n-lib.h>
 
 #include "camel-lock-client.h"
 #include "camel-lock-helper.h"
@@ -39,9 +40,11 @@
 
 #define d(x)
 
-/* dunno where this thing is got from */
-/* see also camel-lock.c */
-#define _(x) (x)
+#define CHECK_CALL(x) G_STMT_START { \
+       if ((x) == -1) { \
+               g_debug ("%s: Call of '" #x "' failed: %s", G_STRFUNC, g_strerror (errno)); \
+       } \
+       } G_STMT_END
 
 static GMutex lock_lock;
 #define LOCK() g_mutex_lock(&lock_lock)
@@ -92,7 +95,7 @@ static gint write_n (gint fd, gpointer buffer, gint inlen)
 static gint
 lock_helper_init (GError **error)
 {
-       gint i;
+       gint i, dupfd1, dupfd2;
 
        lock_stdin_pipe[0] = -1;
        lock_stdin_pipe[1] = -1;
@@ -132,9 +135,9 @@ lock_helper_init (GError **error)
                return -1;
        case 0:
                close (STDIN_FILENO);
-               dup (lock_stdin_pipe[0]);
+               dupfd1 = dup (lock_stdin_pipe[0]);
                close (STDOUT_FILENO);
-               dup (lock_stdout_pipe[1]);
+               dupfd2 = dup (lock_stdout_pipe[1]);
                close (lock_stdin_pipe[0]);
                close (lock_stdin_pipe[1]);
                close (lock_stdout_pipe[0]);
@@ -142,6 +145,12 @@ lock_helper_init (GError **error)
                for (i = 3; i < 255; i++)
                             close (i);
                execl (CAMEL_LIBEXECDIR "/camel-lock-helper-" API_VERSION, "camel-lock-helper", NULL);
+
+               if (dupfd1 != -1)
+                       close (dupfd1);
+               if (dupfd2 != -1)
+                       close (dupfd2);
+
                /* it'll pick this up when it tries to use us */
                exit (255);
        default:
@@ -149,8 +158,8 @@ lock_helper_init (GError **error)
                close (lock_stdout_pipe[1]);
 
                /* so the child knows when we vanish */
-               (void) fcntl (lock_stdin_pipe[1], F_SETFD, FD_CLOEXEC);
-               (void) fcntl (lock_stdout_pipe[0], F_SETFD, FD_CLOEXEC);
+               CHECK_CALL (fcntl (lock_stdin_pipe[1], F_SETFD, FD_CLOEXEC));
+               CHECK_CALL (fcntl (lock_stdout_pipe[0], F_SETFD, FD_CLOEXEC));
        }
 
        return 0;
diff --git a/camel/camel-lock.c b/camel/camel-lock.c
index 3d67074..768f929 100644
--- a/camel/camel-lock.c
+++ b/camel/camel-lock.c
@@ -58,6 +58,12 @@
 
 #define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
 
+#define CHECK_CALL(x) G_STMT_START { \
+       if ((x) == -1) { \
+               g_debug ("%s: Call of '" #x "' failed: %s", G_STRFUNC, g_strerror (errno)); \
+       } \
+       } G_STMT_END
+
 /**
  * camel_lock_dot:
  * @path:
@@ -172,7 +178,7 @@ camel_unlock_dot (const gchar *path)
        lock = alloca (lock_len);
        g_snprintf (lock, lock_len, "%s.lock", path);
        d (printf ("unlocking %s\n", lock));
-       (void) unlink (lock);
+       CHECK_CALL (unlink (lock));
 #endif
 }
 
@@ -240,7 +246,7 @@ camel_unlock_fcntl (gint fd)
 
        memset (&lock, 0, sizeof (lock));
        lock.l_type = F_UNLCK;
-       (void) fcntl (fd, F_SETLK, &lock);
+       CHECK_CALL (fcntl (fd, F_SETLK, &lock));
 #endif
 }
 
@@ -296,7 +302,7 @@ camel_unlock_flock (gint fd)
 #ifdef USE_FLOCK
        d (printf ("flock unlocking %d\n", fd));
 
-       (void) flock (fd, LOCK_UN);
+       CHECK_CALL (flock (fd, LOCK_UN));
 #endif
 }
 
diff --git a/camel/camel-movemail.c b/camel/camel-movemail.c
index 22790b4..7e326b3 100644
--- a/camel/camel-movemail.c
+++ b/camel/camel-movemail.c
@@ -48,6 +48,12 @@
 
 #define d(x)
 
+#define CHECK_CALL(x) G_STMT_START { \
+       if ((x) == -1) { \
+               g_debug ("%s: Call of '" #x "' failed: %s", G_STRFUNC, g_strerror (errno)); \
+       } \
+       } G_STMT_END
+
 #ifdef MOVEMAIL_PATH
 #include <sys/wait.h>
 
@@ -151,7 +157,7 @@ camel_movemail (const gchar *source,
         */
        if (res != -1) {
                if (close (dfd) == 0) {
-                       (void) ftruncate (sfd, 0);
+                       CHECK_CALL (ftruncate (sfd, 0));
                } else {
                        g_set_error (
                                error, G_IO_ERROR,
diff --git a/camel/camel-multipart-signed.c b/camel/camel-multipart-signed.c
index 79a51f9..9f5816e 100644
--- a/camel/camel-multipart-signed.c
+++ b/camel/camel-multipart-signed.c
@@ -112,8 +112,14 @@ multipart_signed_skip_content (CamelMimeParser *cmp)
                break;
        case CAMEL_MIME_PARSER_STATE_MESSAGE:
                /* message body part */
-               (void) camel_mime_parser_step (cmp, &buf, &len);
-               multipart_signed_skip_content (cmp);
+               state = camel_mime_parser_step (cmp, &buf, &len);
+               if (state != CAMEL_MIME_PARSER_STATE_EOF &&
+                   state != CAMEL_MIME_PARSER_STATE_FROM_END) {
+                       multipart_signed_skip_content (cmp);
+               } else {
+                       camel_mime_parser_unstep (cmp);
+                       break;
+               }
 
                /* clean up followon state if any, see camel-mime-message.c */
                state = camel_mime_parser_step (cmp, &buf, &len);
diff --git a/camel/camel-smime-context.c b/camel/camel-smime-context.c
index 49f89b7..30e1aff 100644
--- a/camel/camel-smime-context.c
+++ b/camel/camel-smime-context.c
@@ -1009,7 +1009,9 @@ smime_context_verify_sync (CamelCipherContext *context,
        camel_data_wrapper_decode_to_stream_sync (
                camel_medium_get_content (
                        CAMEL_MEDIUM (sigpart)), mem, cancellable, NULL);
-       (void) NSS_CMSDecoder_Update (dec, (gchar *) buffer->data, buffer->len);
+       if (NSS_CMSDecoder_Update (dec, (gchar *) buffer->data, buffer->len) != SECSuccess) {
+               g_warning ("%s: Failed to call NSS_CMSDecoder_Update", G_STRFUNC);
+       }
        cmsg = NSS_CMSDecoder_Finish (dec);
        if (cmsg == NULL) {
                set_nss_error (error, _("Decoder failed"));
diff --git a/camel/camel-stream-process.c b/camel/camel-stream-process.c
index d4b16da..b1d1859 100644
--- a/camel/camel-stream-process.c
+++ b/camel/camel-stream-process.c
@@ -44,6 +44,12 @@
 #include "camel-file-utils.h"
 #include "camel-stream-process.h"
 
+#define CHECK_CALL(x) G_STMT_START { \
+       if ((x) == -1) { \
+               g_debug ("%s: Call of '" #x "' failed: %s", G_STRFUNC, g_strerror (errno)); \
+       } \
+       } G_STMT_END
+
 extern gint camel_verbose_debug;
 
 G_DEFINE_TYPE (CamelStreamProcess, camel_stream_process, CAMEL_TYPE_STREAM)
@@ -209,7 +215,7 @@ do_exec_command (gint fd,
 
        maxopen = sysconf (_SC_OPEN_MAX);
        for (i = 3; i < maxopen; i++) {
-               (void) fcntl (i, F_SETFD, FD_CLOEXEC);
+               CHECK_CALL (fcntl (i, F_SETFD, FD_CLOEXEC));
        }
 
        setsid ();
diff --git a/camel/providers/imapx/test-imapx.c b/camel/providers/imapx/test-imapx.c
index f8b9c97..80a3b6b 100644
--- a/camel/providers/imapx/test-imapx.c
+++ b/camel/providers/imapx/test-imapx.c
@@ -34,7 +34,9 @@ main (gint argc,
        }
 
        uri = argv[1];
-       system ("rm -rf /tmp/test-camel-imapx");
+       if (system ("rm -rf /tmp/test-camel-imapx") == -1) {
+               /* no big deal */
+       }
        camel_init ("/tmp/test-camel-imapx", TRUE);
        camel_provider_init ();
 
diff --git a/camel/providers/local/camel-maildir-store.c b/camel/providers/local/camel-maildir-store.c
index e76bda0..de5abf5 100644
--- a/camel/providers/local/camel-maildir-store.c
+++ b/camel/providers/local/camel-maildir-store.c
@@ -50,6 +50,13 @@
 #define HIER_SEP "."
 #define HIER_SEP_CHAR '.'
 
+#define CHECK_MKDIR(x,d) G_STMT_START { \
+       gint mkdir_ret = (x); \
+       if (mkdir_ret == -1 && errno != EEXIST) { \
+               g_debug ("%s: mkdir of '%s' failed: %s", G_STRFUNC, (d), g_strerror (errno)); \
+       } \
+       } G_STMT_END
+
 struct _CamelMaildirStorePrivate {
        gboolean already_migrated;
 };
@@ -377,10 +384,10 @@ maildir_store_delete_folder_sync (CamelStore *store,
 
                if (err != 0) {
                        /* easier just to mkdir all (and let them fail), than remember what we got to */
-                       (void) g_mkdir (name, 0700);
-                       (void) g_mkdir (cur, 0700);
-                       (void) g_mkdir (new, 0700);
-                       (void) g_mkdir (tmp, 0700);
+                       CHECK_MKDIR (g_mkdir (name, 0700), name);
+                       CHECK_MKDIR (g_mkdir (cur, 0700), cur);
+                       CHECK_MKDIR (g_mkdir (new, 0700), new);
+                       CHECK_MKDIR (g_mkdir (tmp, 0700), tmp);
                        g_set_error (
                                error, G_IO_ERROR,
                                g_io_error_from_errno (err),
diff --git a/camel/providers/local/camel-mbox-summary.c b/camel/providers/local/camel-mbox-summary.c
index e14bab1..79d6b3e 100644
--- a/camel/providers/local/camel-mbox-summary.c
+++ b/camel/providers/local/camel-mbox-summary.c
@@ -46,6 +46,12 @@
 
 #define CAMEL_MBOX_SUMMARY_VERSION (1)
 
+#define CHECK_CALL(x) G_STMT_START { \
+       if ((x) == -1) { \
+               g_debug ("%s: Call of '" #x "' failed: %s", G_STRFUNC, g_strerror (errno)); \
+       } \
+       } G_STMT_END
+
 typedef struct _CamelMboxMessageContentInfo CamelMboxMessageContentInfo;
 
 struct _CamelMboxMessageContentInfo {
@@ -927,7 +933,7 @@ mbox_summary_sync_quick (CamelMboxSummary *mbs,
                /* we write out the xevnew string, assuming its been folded identically to the original too! 
*/
 
                lastpos = lseek (fd, 0, SEEK_CUR);
-               (void) lseek (fd, xevoffset + strlen ("X-Evolution: "), SEEK_SET);
+               CHECK_CALL (lseek (fd, xevoffset + strlen ("X-Evolution: "), SEEK_SET));
                do {
                        len = write (fd, xevnew, strlen (xevnew));
                } while (len == -1 && errno == EINTR);
diff --git a/camel/providers/local/camel-spool-summary.c b/camel/providers/local/camel-spool-summary.c
index cfb4eb0..31d5be1 100644
--- a/camel/providers/local/camel-spool-summary.c
+++ b/camel/providers/local/camel-spool-summary.c
@@ -222,7 +222,9 @@ spool_summary_sync_full (CamelMboxSummary *cls,
                        ((CamelLocalSummary *) cls)->folder_path,
                        g_strerror (errno));
                /* incase we ran out of room, remove any trailing space first */
-               ftruncate (fd, spoollen);
+               if (ftruncate (fd, spoollen) == -1) {
+                       g_debug ("%s: Failed to call ftruncate: %s", G_STRFUNC, g_strerror (errno));
+               }
                goto error;
        }
 
diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c
index 47a586e..1bb060c 100644
--- a/camel/providers/pop3/camel-pop3-folder.c
+++ b/camel/providers/pop3/camel-pop3-folder.c
@@ -981,8 +981,10 @@ pop3_folder_synchronize_sync (CamelFolder *folder,
        }
 
        if (g_cancellable_is_cancelled (cancellable)) {
-               if (error && !*error)
-                       (void) g_cancellable_set_error_if_cancelled (cancellable, error);
+               if (error && !*error) {
+                       /* coverity[unchecked_value] */
+                       g_cancellable_set_error_if_cancelled (cancellable, error);
+               }
                return FALSE;
        }
 


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