[balsa] Fix some issues raised by scan-build



commit 0791ec1d675fb8c6d86b91e66406c95650d24fbb
Author: Pawel Salek <pawsa0 gmail com>
Date:   Sun Feb 24 15:58:14 2019 -0500

    Fix some issues raised by scan-build
    
    Fix some issues raised by scan-build, the clang static analyzer
    
    * libbalsa/imap/imap-commands.c (imap_mbox_store_flag): insert
      missing "else";
    * libbalsa/imap/imap-handle.c (imap_get_flag),
      (imap_cmd_get_tag): always null-terminate the string;
      (imap_message_deserialize): omit a dead increment;
      (imap_cmd_exec_cmds): store a return code for return;
    * libbalsa/imap/imap_tst.c (test_mbox_append_common): check a
      return code for error.
    
    Signed-off-by: Peter Bloomfield <PeterBloomfield bellsouth net>

 ChangeLog                     | 13 +++++++++++++
 libbalsa/imap/imap-commands.c |  4 +++-
 libbalsa/imap/imap-handle.c   | 13 ++-----------
 libbalsa/imap/imap_tst.c      |  3 +--
 4 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 572d6ecc0..adbf11f0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2019-02-24  Pawel Salek  <pawsa0 gmail com>
+
+       Fix some issues raised by scan-build, the clang static analyzer
+
+       * libbalsa/imap/imap-commands.c (imap_mbox_store_flag): insert
+       missing "else";
+       * libbalsa/imap/imap-handle.c (imap_get_flag),
+       (imap_cmd_get_tag): always null-terminate the string;
+       (imap_message_deserialize): omit a dead increment;
+       (imap_cmd_exec_cmds): store the return code for return;
+       * libbalsa/imap/imap_tst.c (test_mbox_append_common): check the
+       return code for error.
+
 2019-02-23  Peter Bloomfield  <pbloomfield bellsouth net>
 
        gtk_window_present() will be deprecated in later versions of
diff --git a/libbalsa/imap/imap-commands.c b/libbalsa/imap/imap-commands.c
index 19feef702..d67272e38 100644
--- a/libbalsa/imap/imap-commands.c
+++ b/libbalsa/imap/imap-commands.c
@@ -1528,7 +1528,9 @@ imap_mbox_store_flag(ImapMboxHandle *h, unsigned msgcnt, unsigned*seqno,
   if(cmd) {
     res = imap_cmd_exec(h, cmd);
     g_free(cmd);
-  } res = IMR_OK;
+  } else {
+    res = IMR_OK; /* No action needs to be taken */
+  }
   g_mutex_unlock(&h->mutex);
   return res;
 }
diff --git a/libbalsa/imap/imap-handle.c b/libbalsa/imap/imap-handle.c
index 2fd5ded0b..4d62c27e1 100644
--- a/libbalsa/imap/imap-handle.c
+++ b/libbalsa/imap/imap-handle.c
@@ -794,12 +794,8 @@ imap_get_flag(NetClientSioBuf *sio, char* flag, size_t len)
 {
   unsigned i;
   int c = 0;
-  for(i=0; i<len-1 && (c=sio_getc(sio)) >=0 && IS_FLAG_CHAR(c); i++)
+  for(i=0; i<len-1 && (c=sio_getc(sio)) >=0 && IS_FLAG_CHAR(c); i++) {
     flag[i] = c;
-
-  if(i<len-1) {
-    if (c < 0)
-      return c;
   }
   flag[i] = '\0';
   return c;
@@ -817,10 +813,6 @@ imap_cmd_get_tag(NetClientSioBuf *sio, char* tag, size_t len)
   for(i=0; i<len-1 && (c=sio_getc(sio)) >=0 && IS_TAG_CHAR(c); i++) {
     tag[i] = c;
   }
-  if(i<len-1) {
-    if (c < 0)
-      return c;
-  }
   tag[i] = '\0';
   return c;
 }
@@ -1790,7 +1782,6 @@ imap_message_deserialize(void *data)
   imsg->envelope = imap_envelope_from_string(ptr);
   ptr += strlen(ptr) + 1;
   imsg->body = imap_body_from_string(ptr);
-  ptr += strlen(ptr) + 1;
   return imsg;
 }
 
@@ -2000,7 +1991,7 @@ imap_cmd_exec_cmds(ImapMboxHandle* handle, const char** cmds,
   if (rc == IMR_OK) {
     g_return_val_if_fail(handle->state != IMHS_DISCONNECTED && 1, IMR_BAD);
     if(handle->state == IMHS_DISCONNECTED)
-      rc = IMR_SEVERED;
+      ret_rc = IMR_SEVERED;
     else {
       for (cmd_count=0; cmds[cmd_count]; ++cmd_count) {
          rc = imap_cmd_process_untagged(handle, cmdnos[cmd_count]);
diff --git a/libbalsa/imap/imap_tst.c b/libbalsa/imap/imap_tst.c
index 7b14c8f9f..59ec2107a 100644
--- a/libbalsa/imap/imap_tst.c
+++ b/libbalsa/imap/imap_tst.c
@@ -470,7 +470,6 @@ test_mbox_append_common(gboolean multi, int argc, char *argv[])
     mi.dir = dir;
     mi.fh = NULL;
     res = imap_mbox_append_multi(h, mailbox, msg_iterator, &mi, NULL);
-
   } else {
     for(res = IMR_OK; res == IMR_OK && (file = readdir(dir)) != NULL;) {
       struct stat buf;
@@ -496,7 +495,7 @@ test_mbox_append_common(gboolean multi, int argc, char *argv[])
   }
 
   g_object_unref(h);
-  return 0;
+  return res == IMR_OK ? 1 : 0;
 }
 
 /** Tests appending message by message. */


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