<<< Date Index >>>     <<< Thread Index >>>

[PATCH] Compilation warnings, configure



Hi,

I believe Brendan already fixed the headercache segfault, but I post my
anti-warning patches anyway.  I believe it's good to have warningless
code.  I attach two patches here.

configure.patch
  might be useful in the future, enables X_CFLAGS to be recognised and
  added to CFLAGS after configure has done its tests

warnings.patch
  warnings I fixed that GCC chokes on using -Werror -std=gnu99.  Because
  I don't know how to solve the "%lld is forbidden in C90" error I used
  the latter option.  Please review carefully.  The "may be used
  unitialised" might actually really happen in some cases.


I commented inside the patches, feel free to reject or apply.  :)

-- 
Fabian Groffen
Gentoo on a different level
* allow to use CFLAGS that are not used in configure itself, X_CFLAGS,
  useful for injecting -Werror -std=gnu99 for instance.

diff -ur mutt-1.5.14cvs.orig/configure.ac mutt-1.5.14cvs/configure.ac
--- mutt-1.5.14cvs.orig/configure.ac    2007-04-03 17:32:43.786111000 +0200
+++ mutt-1.5.14cvs/configure.ac 2007-04-03 19:04:21.070349000 +0200
@@ -1158,6 +1158,8 @@
 fi
 AC_SUBST(DSLROOT)
 
+CFLAGS="$CFLAGS $X_CFLAGS"
+
 AC_OUTPUT(Makefile intl/Makefile m4/Makefile
         po/Makefile.in doc/Makefile contrib/Makefile
         muttbug.sh
diff -ur mutt-1.5.14cvs.orig/copy.c mutt-1.5.14cvs/copy.c

warning: XXX may be used initialised

--- mutt-1.5.14cvs.orig/copy.c  2007-04-03 17:32:43.834331000 +0200
+++ mutt-1.5.14cvs/copy.c       2007-04-03 19:07:58.526065000 +0200
@@ -56,7 +56,7 @@
   int hdr_count;
   int x;
   char *this_one = NULL;
-  size_t this_one_len;
+  size_t this_one_len = 0;
   int error;
 
   if (ftello (in) != off_start)
@@ -851,7 +851,7 @@
   char buf[HUGE_STRING];
   char cbuf[STRING];
   char c2buf[STRING];
-  char *p;
+  char *p = NULL;
   int l, linelen, buflen, count, cbuflen, c2buflen, plen;
 
   linelen = mutt_strlen (*h);
diff -ur mutt-1.5.14cvs.orig/hdrline.c mutt-1.5.14cvs/hdrline.c

On Solaris alloca.h needs to be included before it can be used (without
a warning)

--- mutt-1.5.14cvs.orig/hdrline.c       2007-04-03 17:32:43.838939000 +0200
+++ mutt-1.5.14cvs/hdrline.c    2007-04-03 19:09:25.441183000 +0200
@@ -32,6 +32,10 @@
 #include <string.h>
 #include <locale.h>
 
+#if HAVE_ALLOCA_H
+# include <alloca.h>
+#endif
+
 int mutt_is_mail_list (ADDRESS *addr)
 {
   if (!mutt_match_rx_list (addr->mailbox, UnMailLists))
diff -ur mutt-1.5.14cvs.orig/imap/message.c mutt-1.5.14cvs/imap/message.c

warning: dereferencing a type-punned variable will break strict aliasing
rules
last hunk: warning: computed value never used

--- mutt-1.5.14cvs.orig/imap/message.c  2007-04-03 17:32:44.174306000 +0200
+++ mutt-1.5.14cvs/imap/message.c       2007-04-03 18:47:36.410996000 +0200
@@ -80,6 +80,7 @@
   unsigned int *uidnext = NULL;
   int evalhc = 0;
   char uid_buf[64];
+  void *d;
 #endif /* USE_HCACHE */
 
   ctx = idata->ctx;
@@ -157,7 +158,8 @@
         rc = imap_cmd_step (idata);
         if (rc != IMAP_CMD_CONTINUE)
        {
-         imap_free_header_data ((void**) &h.data);
+         d = &h.data;
+         imap_free_header_data (&d);
           break;
        }
 
@@ -165,7 +167,8 @@
           continue;
         else if (mfhrc < 0)
        {
-         imap_free_header_data ((void**) &h.data);
+         d = &h.data;
+         imap_free_header_data (&d);
           break;
        }
 
@@ -193,9 +196,12 @@
           ctx->size += ctx->hdrs[idx]->content->length;
         }
        else
+        {
          /* bad header in the cache, we'll have to refetch.
           * TODO: consider the possibility of a holey cache. */
-          imap_free_header_data((void**) &h.data);
+          d = &h.data;
+          imap_free_header_data(&d);
+        }
   
         FREE(&uid_validity);
       }
@@ -205,7 +211,10 @@
       if ((mfhrc < -1) || ((rc != IMAP_CMD_CONTINUE) && (rc != IMAP_CMD_OK)))
       {
         if (h.data)
-          imap_free_header_data ((void**) &h.data);
+               {
+          d = &h.data;
+          imap_free_header_data (&d);
+               }
         fclose (fp);
         mutt_hcache_close (hc);
         return -1;
@@ -308,7 +317,10 @@
     if ((mfhrc < -1) || ((rc != IMAP_CMD_CONTINUE) && (rc != IMAP_CMD_OK)))
     {
       if (h.data)
-        imap_free_header_data ((void**) &h.data);
+         {
+        d = &h.data;
+        imap_free_header_data (&d);
+         }
       fclose (fp);
 #if USE_HCACHE
       mutt_hcache_close (hc);
@@ -877,8 +889,8 @@
     }
     else
       *s = *p;
-    *p++;
-    *s++;
+    p++;
+    s++;
   }
   *s = '\0';
 
diff -ur mutt-1.5.14cvs.orig/mh.c mutt-1.5.14cvs/mh.c

warning: XXX defined but never used

--- mutt-1.5.14cvs.orig/mh.c    2007-04-03 17:32:43.876674000 +0200
+++ mutt-1.5.14cvs/mh.c 2007-04-03 19:09:55.578416000 +0200
@@ -232,7 +232,6 @@
   int fd;
   char path[_POSIX_PATH_MAX];
   mode_t omask;
-  struct mh_data* data = mh_data (dest);
 
   omask = umask (mh_umask (dest));
   FOREVER
diff -ur mutt-1.5.14cvs.orig/muttlib.c mutt-1.5.14cvs/muttlib.c

warning: XXX defined but never used
second hunk: type-pun

--- mutt-1.5.14cvs.orig/muttlib.c       2007-04-03 17:32:43.884057000 +0200
+++ mutt-1.5.14cvs/muttlib.c    2007-04-03 19:11:39.717894000 +0200
@@ -1029,7 +1029,6 @@
     {
       BUFFER *srcbuf, *word, *command;
       char    srccopy[LONG_STRING];
-      int     i = 0;
 
       dprint(3, (debugfile, "fmtpipe = %s\n", src));
 
@@ -1595,12 +1594,14 @@
 void mutt_buffer_add (BUFFER* buf, const char* s, size_t len)
 {
   size_t offset;
+  void *d;
 
   if (buf->dptr + len + 1 > buf->data + buf->dsize)
   {
     offset = buf->dptr - buf->data;
     buf->dsize += len < 128 ? 128 : len + 1;
-    safe_realloc ((void**) &buf->data, buf->dsize);
+    d = &buf->data;
+    safe_realloc (&d, buf->dsize);
     buf->dptr = buf->data + offset;
   }
   memcpy (buf->dptr, s, len);
diff -ur mutt-1.5.14cvs.orig/regex.c mutt-1.5.14cvs/regex.c

warning: comparison always yields in false due to limited data type
second hunk: warning: XXX defined but never used

--- mutt-1.5.14cvs.orig/regex.c 2007-04-03 17:32:43.795576000 +0200
+++ mutt-1.5.14cvs/regex.c      2007-04-03 19:14:11.980070000 +0200
@@ -2197,7 +2197,7 @@
                       {
                         PATFETCH (c);
                         if (c == ':' || c == ']' || p == pend
-                            || c1 == CHAR_CLASS_MAX_LENGTH)
+                            || c1 == (unsigned char) CHAR_CLASS_MAX_LENGTH)
                           break;
                         str[c1++] = c;
                       }
@@ -3117,9 +3117,6 @@
 #ifndef REGEX_MALLOC
   char *destination;
 #endif
-  /* We don't push any register information onto the failure stack.  */
-  unsigned num_regs = 0;
-
   register char *fastmap = bufp->fastmap;
   unsigned char *pattern = bufp->buffer;
   unsigned char *p = pattern;
diff -ur mutt-1.5.14cvs.orig/sendlib.c mutt-1.5.14cvs/sendlib.c

warning: XXX may be used unitialised in this function

--- mutt-1.5.14cvs.orig/sendlib.c       2007-04-03 17:32:43.881800000 +0200
+++ mutt-1.5.14cvs/sendlib.c    2007-04-03 19:10:38.293815000 +0200
@@ -842,7 +842,7 @@
   CONTENT *info;
   CONTENT_STATE state;
   FILE *fp = NULL;
-  char *fromcode;
+  char *fromcode = NULL;
   char *tocode;
   char buffer[100];
   char chsbuf[STRING];