findutils-patches
[Top][All Lists]
Advanced

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

[Findutils-patches] avoid gcc compiler warnings


From: Eric Blake
Subject: [Findutils-patches] avoid gcc compiler warnings
Date: Thu, 28 Jun 2007 14:44:17 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

The following warnings show up with gcc -Wall, when using gcc 3.4.4 on head:

pred.c: In function `pred_timewindow':
pred.c:296: warning: control reaches end of non-void function
[every branch of switch statement returns; and use of the implicit default: 
implies a bug]

tree.c: In function `calculate_derived_rates':
tree.c:1165: warning: control reaches end of non-void function
[every branch of switch statement returns; and use of the implicit default: 
implies a bug]

word_io.c: In function `getword':
word_io.c:153: warning: control reaches end of non-void function
[gcc isn't smart enough to detect that error(1) never returns.  Plus, this 
pointed out a translation error]

OK to apply?

As a followup note, coreutils prefers the style:
error (0,...) for non-fatal messages
error (EXIT_FAILURE,...) (or other, appropriate exit status) for fatal messages

At some point, it might be worth scrubbing for uses of error(1), as they are 
less readable.

2007-06-28  Eric Blake  <address@hidden>

        * find/pred.c (pred_timewindow): Avoid gcc warnings.
        * find/tree.c (calculate_derived_rates): Likewise.
        * locate/word_io.c (getword): Likewise.

Index: find/pred.c
===================================================================
RCS file: /sources/findutils/findutils/find/pred.c,v
retrieving revision 1.101
diff -u -p -r1.101 pred.c
--- find/pred.c 26 Jun 2007 08:24:18 -0000      1.101
+++ find/pred.c 28 Jun 2007 14:39:41 -0000
@@ -293,6 +293,8 @@ pred_timewindow(struct timespec ts, stru
        return (delta >= 0.0 && delta < window);
       }
     }
+  assert (0);
+  abort ();
 }
 
 
Index: find/tree.c
===================================================================
RCS file: /sources/findutils/findutils/find/tree.c,v
retrieving revision 1.38
diff -u -p -r1.38 tree.c
--- find/tree.c 26 Jun 2007 08:24:18 -0000      1.38
+++ find/tree.c 28 Jun 2007 14:39:41 -0000
@@ -1162,6 +1162,8 @@ calculate_derived_rates(struct predicate
       p->est_success_rate = 1.0;
       return p->est_success_rate;
     }
+  assert (0);
+  abort ();
 }
 
 /* opt_expr() rearranges predicates such that each left subtree is
Index: locate/word_io.c
===================================================================
RCS file: /sources/findutils/findutils/locate/word_io.c,v
retrieving revision 1.5
diff -u -p -r1.5 word_io.c
--- locate/word_io.c    26 Jun 2007 08:24:19 -0000      1.5
+++ locate/word_io.c    28 Jun 2007 14:39:41 -0000
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <stdbool.h>           /* for bool */
 #include <assert.h>
+#include <stdlib.h>
 
 #include "error.h"
 #include "quote.h"
@@ -142,9 +143,10 @@ getword (FILE *fp,
        * Either condition is fatal.
        */
       if (feof(fp))
-       error(1, 0, _("Unexpected EOF in %s"), quoted_name);
-      else 
-       error(1, errno, "error reading a word from %s", quoted_name);
+       error(1, 0, _("unexpected EOF in %s"), quoted_name);
+      else
+       error(1, errno, _("error reading a word from %s"), quoted_name);
+      abort ();
     }
   else
     {
@@ -174,4 +176,3 @@ putword (FILE *fp, int word,
   else
     return false;
 }
-






reply via email to

[Prev in Thread] Current Thread [Next in Thread]