[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mutt-dev
Subject:    mutt: fix various compiler warnings; most were due to unchecked ...
From:       Brendan Cully <brendan () kublai ! com>
Date:       2013-04-10 22:38:39
Message-ID: hg.c1371176ea45.1365633519.1928362535899276112 () dev ! cs ! ubc ! ca
[Download RAW message or body]

changeset: 6301:c1371176ea45
user:      Michael Elkins <me@sigpipe.org>
date:      Wed Apr 10 22:38:47 2013 +0000
link:      http://dev.mutt.org/hg/mutt/rev/c1371176ea45

fix various compiler warnings; most were due to unchecked return values from system \
calls.

diffs (313 lines):

diff -r d498f0e91914 -r c1371176ea45 browser.c
--- a/browser.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/browser.c	Wed Apr 10 22:38:47 2013 +0000
@@ -615,7 +615,11 @@
       }
       else
       {
-	getcwd (LastDir, sizeof (LastDir));
+	if (getcwd (LastDir, sizeof (LastDir)) == NULL)
+	{
+	  dprint(1, (debugfile, "%s:%d getcwd() returned NULL\n", __FILE__, __LINE__));
+	  LastDir[0] = '\0';
+	}
 	safe_strcat (LastDir, sizeof (LastDir), "/");
 	safe_strncat (LastDir, sizeof (LastDir), f, i);
       }
@@ -625,7 +629,13 @@
       if (f[0] == '/')
 	strcpy (LastDir, "/");		/* __STRCPY_CHECKED__ */
       else
-	getcwd (LastDir, sizeof (LastDir));
+      {
+	if (getcwd (LastDir, sizeof (LastDir)) == NULL)
+	{
+	  dprint(1, (debugfile, "%s:%d getcwd() returned NULL\n", __FILE__, __LINE__));
+	  LastDir[0] = '\0';
+	}
+      }
     }
 
     if (i <= 0 && f[0] != '/')
@@ -640,7 +650,13 @@
   else 
   {
     if (!folder)
-      getcwd (LastDir, sizeof (LastDir));
+    {
+      if (getcwd (LastDir, sizeof (LastDir)) == NULL)
+      {
+	dprint(1, (debugfile, "%s:%d getcwd() returned NULL\n", __FILE__, __LINE__));
+	LastDir[0] = '\0';
+      }
+    }
     else if (!LastDir[0])
       strfcpy (LastDir, NONULL(Maildir), sizeof (LastDir));
     
@@ -659,7 +675,13 @@
       while (i && LastDir[--i] == '/')
         LastDir[i] = '\0';
       if (!LastDir[0])
-        getcwd (LastDir, sizeof (LastDir));
+      {
+        if (getcwd (LastDir, sizeof (LastDir)) == NULL)
+	{
+	  dprint(1, (debugfile, "%s:%d getcwd() returned NULL\n", __FILE__, __LINE__));
+	  LastDir[0] = '\0';
+	}
+      }
     }
   }
 
diff -r d498f0e91914 -r c1371176ea45 enter.c
--- a/enter.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/enter.c	Wed Apr 10 22:38:47 2013 +0000
@@ -28,6 +28,7 @@
 #include "history.h"
 
 #include <string.h>
+#include <errno.h>
 
 /* redraw flags for mutt_enter_string() */
 enum
@@ -94,7 +95,8 @@
 
   /* If this works, we can stop now */
   if (dlen >= MB_LEN_MAX) {
-    wcrtomb (dest, 0, &st);
+    if (wcrtomb (dest, 0, &st) == (size_t) -1)
+      dprint(1, (debugfile, "%s:%d wcrtomb() returned -1, errno=%d\n", __FILE__, \
__LINE__, errno));  return;
   }
 
diff -r d498f0e91914 -r c1371176ea45 imap/message.c
--- a/imap/message.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/imap/message.c	Wed Apr 10 22:38:47 2013 +0000
@@ -561,11 +561,13 @@
   }
 
   h->lines = 0;
-  fgets (buf, sizeof (buf), msg->fp);
+  if (fgets (buf, sizeof (buf), msg->fp) == NULL)
+      ; /* EOF checked below */
   while (!feof (msg->fp))
   {
     h->lines++;
-    fgets (buf, sizeof (buf), msg->fp);
+    if (fgets (buf, sizeof (buf), msg->fp) == NULL)
+	; /* EOF checked in while loop condition */
   }
 
   h->content->length = ftell (msg->fp) - h->content->offset;
diff -r d498f0e91914 -r c1371176ea45 init.c
--- a/init.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/init.c	Wed Apr 10 22:38:47 2013 +0000
@@ -2822,7 +2822,6 @@
 #ifdef DEBUG
 static void start_debug (void)
 {
-  time_t t;
   int i;
   char buf[_POSIX_PATH_MAX];
   char buf2[_POSIX_PATH_MAX];
@@ -2836,7 +2835,6 @@
   }
   if ((debugfile = safe_fopen(buf, "w")) != NULL)
   {
-    t = time (0);
     setbuf (debugfile, NULL); /* don't buffer the debugging output! */
     dprint(1,(debugfile,"Mutt/%s (%s) debugging at level %d\n",
 	      MUTT_VERSION, ReleaseDate, debuglevel));
diff -r d498f0e91914 -r c1371176ea45 mbox.c
--- a/mbox.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/mbox.c	Wed Apr 10 22:38:47 2013 +0000
@@ -968,7 +968,11 @@
     if (i == 0)
     {
       ctx->size = ftello (ctx->fp); /* update the size of the mailbox */
-      ftruncate (fileno (ctx->fp), ctx->size);
+      if (ftruncate (fileno (ctx->fp), ctx->size) == -1)
+      {
+	dprint(1, (debugfile, "%s:%d ftrunctate() returned -1, errno=%d\n", __FILE__, \
__LINE__, errno)); +	i = -1;
+      }
     }
   }
 
diff -r d498f0e91914 -r c1371176ea45 muttlib.c
--- a/muttlib.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/muttlib.c	Wed Apr 10 22:38:47 2013 +0000
@@ -67,6 +67,7 @@
   char buf[_POSIX_PATH_MAX];
   char tmp[_POSIX_PATH_MAX];
   char *period;
+  char *r;
   size_t sl;
   struct stat sb;
   
@@ -75,7 +76,9 @@
   if (s[0] == '\0')
   {
     snprintf (s, l, "%s/muttXXXXXX", buf);
-    mktemp (s);
+    r = mktemp (s);
+    if (*r == '\0')
+      dprint (1, (debugfile, "%s:%d mktemp returned an empty string (errno=%d)\n", \
__FILE__, __LINE__, errno));  }
   else
   {
@@ -87,7 +90,9 @@
     if ((period = strrchr (tmp, '.')) != NULL)
       *period = 0;
     snprintf (s, l, "%s/%s.XXXXXX", buf, tmp);
-    mktemp (s);
+    r = mktemp (s);
+    if (*r == '\0')
+      dprint (1, (debugfile, "%s:%d mktemp returned an empty string (errno=%d)\n", \
__FILE__, __LINE__, errno));  if (period != NULL)
     {
       *period = '.';
diff -r d498f0e91914 -r c1371176ea45 mx.c
--- a/mx.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/mx.c	Wed Apr 10 22:38:47 2013 +0000
@@ -379,6 +379,7 @@
   }
   else if (st.st_size == 0)
   {
+zero_size_file:
     /* hard to tell what zero-length files are, so assume the default magic */
     if (DefaultMagic == M_MBOX || DefaultMagic == M_MMDF)
       return (DefaultMagic);
@@ -389,7 +390,12 @@
   {
     struct utimbuf times;
 
-    fgets (tmp, sizeof (tmp), f);
+    if (fgets (tmp, sizeof (tmp), f) == NULL)
+    {
+      /* This situation should not occur since we check for size==0 above.. */
+      dprint(1, (debugfile, "%s:%d fgets() returned NULL.  this should not \
happen!\n", __FILE__, __LINE__)); +      goto zero_size_file;
+    }
     if (mutt_strncmp ("From ", tmp, 5) == 0)
       magic = M_MBOX;
     else if (mutt_strcmp (MMDF_SEP, tmp) == 0)
diff -r d498f0e91914 -r c1371176ea45 pop.c
--- a/pop.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/pop.c	Wed Apr 10 22:38:47 2013 +0000
@@ -67,6 +67,7 @@
   long length;
   char buf[LONG_STRING];
   char tempfile[_POSIX_PATH_MAX];
+  int rv;
 
   mutt_mktemp (tempfile, sizeof (tempfile));
   if (!(f = safe_fopen (tempfile, "w+")))
@@ -79,7 +80,8 @@
   ret = pop_query (pop_data, buf, sizeof (buf));
   if (ret == 0)
   {
-    sscanf (buf, "+OK %d %ld", &index, &length);
+    if ((rv = sscanf (buf, "+OK %d %ld", &index, &length)) < 2)
+      dprint(1, (debugfile, "%s:%d sscanf() returned %d\n", __FILE__, __LINE__, \
rv));  
     snprintf (buf, sizeof (buf), "TOP %d 0\r\n", h->refno);
     ret = pop_fetch_data (pop_data, buf, NULL, fetch_message, f);
@@ -110,12 +112,21 @@
     {
       rewind (f);
       h->env = mutt_read_rfc822_header (f, h, 0, 0);
+      /*
+       * The following code seems to be trying to alter the content length by
+       * removing the CR characters for the header.  Note that this value is
+       * still incorrect, since "TOP 0" only returns the message header, so it
+       * only ends up accounting for the CR characters in the header.  The
+       * correct length is set when the entire message is downloaded by
+       * pop_fetch_message().
+       */
       h->content->length = length - h->content->offset + 1;
       rewind (f);
       while (!feof (f))
       {
 	h->content->length--;
-	fgets (buf, sizeof (buf), f);
+	if (fgets (buf, sizeof (buf), f) == NULL)
+	  ; /* EOF checked in while loop condition */
       }
       break;
     }
@@ -638,11 +649,13 @@
 
   h->data = uidl;
   h->lines = 0;
-  fgets (buf, sizeof (buf), msg->fp);
+  if (fgets (buf, sizeof (buf), msg->fp) == NULL)
+    ; /* EOF checked in following while loop condition */
   while (!feof (msg->fp))
   {
     ctx->hdrs[msgno]->lines++;
-    fgets (buf, sizeof (buf), msg->fp);
+    if (fgets (buf, sizeof (buf), msg->fp) == NULL)
+      ; /* EOF checked in following while loop condition */
   }
 
   h->content->length = ftello (msg->fp) - h->content->offset;
diff -r d498f0e91914 -r c1371176ea45 query.c
--- a/query.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/query.c	Wed Apr 10 22:38:47 2013 +0000
@@ -93,7 +93,12 @@
   }
   if (!quiet)
     mutt_message _("Waiting for response...");
-  fgets (msg, sizeof (msg), fp);
+  if (fgets (msg, sizeof (msg), fp) == NULL)
+  {
+    dprint(1, (debugfile, "%s:%d query_command produced no output (fgets() returned \
NULL)\n", __FILE__, __LINE__)); +    return 0;
+  }
+
   if ((p = strrchr (msg, '\n')))
     *p = '\0';
   while ((buf = mutt_read_line (buf, &buflen, fp, &dummy, 0)) != NULL)
diff -r d498f0e91914 -r c1371176ea45 smime.c
--- a/smime.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/smime.c	Wed Apr 10 22:38:47 2013 +0000
@@ -391,8 +391,24 @@
     while (!feof(index)) {
         numFields = fscanf (index, MUTT_FORMAT(STRING) " %x.%i " \
MUTT_FORMAT(STRING), fields[0], &hash,  &hash_suffix, fields[2]);
+	/*
+	 * ensure good values for these fields since they may not be set if
+	 * `public` is false, and they are used below.
+	 */
+	fields[3][0] = '\0';
+	fields[4][0] = '\0';
         if (public)
-          fscanf (index, MUTT_FORMAT(STRING) " " MUTT_FORMAT(STRING) "\n", \
fields[3], fields[4]); +	{
+	  /*
+	   * The original code here did not check the return value of fscanf,
+	   * so I'm unsure whether the entire line should be ignored upon
+	   * error.  Just log it for now.
+	   */
+	  int rv;
+          rv = fscanf (index, MUTT_FORMAT(STRING) " " MUTT_FORMAT(STRING) "\n", \
fields[3], fields[4]); +	  if (rv < 2)
+	   dprint (1, (debugfile, "%s:%d fscanf() returned %d\n", __FILE__, __LINE__, \
errno)); +	}
   
       /* 0=email 1=name 2=nick 3=intermediate 4=trust */
       if (numFields < 2) continue;
diff -r d498f0e91914 -r c1371176ea45 system.c
--- a/system.c	Mon Mar 04 04:14:43 2013 +0000
+++ b/system.c	Wed Apr 10 22:38:47 2013 +0000
@@ -92,7 +92,8 @@
 	  close (1);
 	  close (2);
 #endif
-	  chdir ("/");
+	  if (chdir ("/") == -1)
+	    _exit (127);
 	  act.sa_handler = SIG_DFL;
 	  sigaction (SIGCHLD, &act, NULL);
 	  break;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic