[balsa/wip/gtk4] Fix some issues raised by scan-build



commit 11b02125c753d8c314e0cc733877480bca62a43a
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 57128216a..2e4959564 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 5a73defec..7007a5eff 100644
--- a/libbalsa/imap/imap-commands.c
+++ b/libbalsa/imap/imap-commands.c
@@ -1529,7 +1529,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 b9f6cbc3e..833ebf6a4 100644
--- a/libbalsa/imap/imap-handle.c
+++ b/libbalsa/imap/imap-handle.c
@@ -793,12 +793,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;
@@ -816,10 +812,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;
 }
@@ -1773,7 +1765,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;
 }
 
@@ -1983,7 +1974,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]