findutils-patches
[Top][All Lists]
Advanced

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

[Findutils-patches] [PATCH 7/8] find: fix some compiler warnings.


From: James Youngman
Subject: [Findutils-patches] [PATCH 7/8] find: fix some compiler warnings.
Date: Sat, 2 Jan 2016 23:54:57 +0000

* find/util.c (check_nofollow): Avoid compiler warnings about
comparison between the float variable release and some double
constants by changing the constants to be floats, too.
* find/parser.c (estimate_file_age_success_rate): Avoid warnings
of comparison of float against other types by consistently using
float constants.
(insert_type): move the definition of type_cell and set it in the
switch cases handling S_IFLINK and other types of file which may
not be defined on the platform we're building for.  We do this in
order to silence a compiler warning about use of an uninitialised
value.  It's not really used uninitialised, it's just that the
compiler doesn't know that the way we're calling error() will
cause that function not to return.
(parse_time): Avoid a compiler warning about signed/unsigned
comparison by using a cast.
* find/ftsfind.c: Don't #define USE_SAFE_CHDIR, it's unused.
Likewise STRINGIFY.
(show_outstanding_execdirs): Avoid overflowing int variable seen
by making a bool and setting it to true, instead of incrementing
it.
(main): Correct the call to ctime; it takes time_t*, so don't pass
struct timeval* (instead, pass the address of the tv_sec member).
* find/exec.c (launch): Avoid warnign of unused parameter ctl.  We
really don't use it, but this function takes the parameter as
it's a callback.
* find/pred.c (struct pred_assoc): make the pred_name member const.
* find/defs.h: Declare pred_quit as __noreturn__.
---
 find/defs.h    |   7 ++-
 find/exec.c    |   1 +
 find/ftsfind.c |   8 +--
 find/parser.c  | 178 ++++++++++++++++++++++++++++++---------------------------
 find/pred.c    |   2 +-
 find/util.c    |   4 +-
 6 files changed, 105 insertions(+), 95 deletions(-)

diff --git a/find/defs.h b/find/defs.h
index 34125a8..7fa866a 100644
--- a/find/defs.h
+++ b/find/defs.h
@@ -445,7 +445,6 @@ PREDICATEFUNCTION pred_perm;
 PREDICATEFUNCTION pred_print;
 PREDICATEFUNCTION pred_print0;
 PREDICATEFUNCTION pred_prune;
-PREDICATEFUNCTION pred_quit;
 PREDICATEFUNCTION pred_readable;
 PREDICATEFUNCTION pred_regex;
 PREDICATEFUNCTION pred_samefile;
@@ -459,7 +458,11 @@ PREDICATEFUNCTION pred_writable;
 PREDICATEFUNCTION pred_xtype;
 PREDICATEFUNCTION pred_context;
 
-
+bool pred_quit(const char *pathname, struct stat *stat_buf, struct predicate 
*pred_ptr)
+#ifdef HAVE_ATTRIBUTE_NORETURN
+__attribute__ ((__noreturn__))
+#endif
+  ;
 
 char *find_pred_name (PRED_FUNC pred_func);
 
diff --git a/find/exec.c b/find/exec.c
index 8d20143..a283bd0 100644
--- a/find/exec.c
+++ b/find/exec.c
@@ -292,6 +292,7 @@ launch (struct buildcmd_control *ctl, void *usercontext, 
int argc, char **argv)
   static int first_time = 1;
   struct exec_val *execp = usercontext;
 
+  (void) ctl;                  /* silence compiler warning */
   (void) argc;                 /* silence compiler warning */
 
   /* Make sure output of command doesn't get mixed with find output. */
diff --git a/find/ftsfind.c b/find/ftsfind.c
index 5128e57..c4a615e 100644
--- a/find/ftsfind.c
+++ b/find/ftsfind.c
@@ -56,7 +56,6 @@
 #include "fdleak.h"
 #include "unused-result.h"
 
-#define USE_SAFE_CHDIR 1
 #undef  STAT_MOUNTPOINTS
 
 
@@ -149,7 +148,6 @@ inside_dir (int dir_fd)
 static void init_mounted_dev_list (void);
 #endif
 
-#define STRINGIFY(X) #X
 #define HANDLECASE(N) case N: return #N;
 
 static const char *
@@ -280,7 +278,7 @@ show_outstanding_execdirs (FILE *fp)
 {
   if (options.debug_options & DebugExec)
     {
-      int seen=0;
+      bool seen = false;
       struct predicate *p;
       p = get_eval_tree ();
       fprintf (fp, "Outstanding execdirs:");
@@ -299,7 +297,7 @@ show_outstanding_execdirs (FILE *fp)
            {
              size_t i;
              const struct exec_val *execp = &p->args.exec_vec;
-             ++seen;
+             seen = true;
 
              fprintf (fp, "%s ", pfx);
              if (execp->multiple)
@@ -699,7 +697,7 @@ main (int argc, char **argv)
 
 
   if (options.debug_options & DebugTime)
-    fprintf (stderr, "cur_day_start = %s", ctime (&options.cur_day_start));
+    fprintf (stderr, "cur_day_start = %s", ctime 
(&options.cur_day_start.tv_sec));
 
 
   /* We are now processing the part of the "find" command line
diff --git a/find/parser.c b/find/parser.c
index f186e4a..5cedd48 100644
--- a/find/parser.c
+++ b/find/parser.c
@@ -661,17 +661,17 @@ find_parser (const char *search_name)
 static float
 estimate_file_age_success_rate (float num_days)
 {
-  if (num_days < 0.1)
+  if (num_days < 0.1f)
     {
       /* Assume 1% of files have timestamps in the future */
       return 0.01f;
     }
-  else if (num_days < 1)
+  else if (num_days < 1.0f)
     {
       /* Assume 30% of files have timestamps today */
       return 0.3f;
     }
-  else if (num_days > 100)
+  else if (num_days > 100.0f)
     {
       /* Assume 30% of files are very old */
       return 0.3f;
@@ -1284,7 +1284,7 @@ parse_ilname (const struct parser_table* entry, char 
**argv, int *arg_ptr)
       /* Use the generic glob pattern estimator to figure out how many
        * links will match, but bear in mind that most files won't be links.
        */
-      our_pred->est_success_rate = 0.1 * estimate_pattern_match_rate (name, 0);
+      our_pred->est_success_rate = 0.1f * estimate_pattern_match_rate (name, 
0);
       return true;
     }
   else
@@ -1415,7 +1415,7 @@ parse_lname (const struct parser_table* entry, char 
**argv, int *arg_ptr)
     {
       struct predicate *our_pred = insert_primary (entry, name);
       our_pred->args.str = name;
-      our_pred->est_success_rate = 0.1 * estimate_pattern_match_rate (name, 0);
+      our_pred->est_success_rate = 0.1f * estimate_pattern_match_rate (name, 
0);
       return true;
     }
   return false;
@@ -2701,7 +2701,6 @@ insert_type (char **argv, int *arg_ptr,
             const struct parser_table *entry,
             PRED_FUNC which_pred)
 {
-  mode_t type_cell;
   struct predicate *our_pred;
   float rate = 0.01;
   const char *typeletter;
@@ -2726,96 +2725,105 @@ insert_type (char **argv, int *arg_ptr,
          s         80  1.59e-05
          p         38  7.54e-06
        */
-      switch (typeletter[0])
-       {
-       case 'b':                       /* block special */
-         type_cell = S_IFBLK;
-         rate = 0.000888f;
-         break;
-       case 'c':                       /* character special */
-         type_cell = S_IFCHR;
-         rate = 0.000443f;
-         break;
-       case 'd':                       /* directory */
-         type_cell = S_IFDIR;
-         rate = 0.0922f;
-         break;
-       case 'f':                       /* regular file */
-         type_cell = S_IFREG;
-         rate = 0.875f;
-         break;
-       case 'l':                       /* symbolic link */
+      {
+       mode_t type_cell;
+
+       switch (typeletter[0])
+         {
+         case 'b':                     /* block special */
+           type_cell = S_IFBLK;
+           rate = 0.000888f;
+           break;
+         case 'c':                     /* character special */
+           type_cell = S_IFCHR;
+           rate = 0.000443f;
+           break;
+         case 'd':                     /* directory */
+           type_cell = S_IFDIR;
+           rate = 0.0922f;
+           break;
+         case 'f':                     /* regular file */
+           type_cell = S_IFREG;
+           rate = 0.875f;
+           break;
+         case 'l':                     /* symbolic link */
 #ifdef S_IFLNK
-         type_cell = S_IFLNK;
-         rate = 0.0311f;
+           type_cell = S_IFLNK;
+           rate = 0.0311f;
 #else
-         error (EXIT_FAILURE, 0,
-                _("-type %c is not supported because symbolic links "
-                  "are not supported on the platform find was compiled on."),
-                (*typeletter));
+           type_cell = 0;
+           error (EXIT_FAILURE, 0,
+                  _("-type %c is not supported because symbolic links "
+                    "are not supported on the platform find was compiled on."),
+                  (*typeletter));
 #endif
-         break;
-       case 'p':                       /* pipe */
+           break;
+         case 'p':                     /* pipe */
 #ifdef S_IFIFO
-         type_cell = S_IFIFO;
-         rate = 7.554e-6f;
+           type_cell = S_IFIFO;
+           rate = 7.554e-6f;
 #else
-         error (EXIT_FAILURE, 0,
-                _("-type %c is not supported because FIFOs "
-                  "are not supported on the platform find was compiled on."),
-                (*typeletter));
+           type_cell = 0;
+           error (EXIT_FAILURE, 0,
+                  _("-type %c is not supported because FIFOs "
+                    "are not supported on the platform find was compiled on."),
+                  (*typeletter));
 #endif
-         break;
-       case 's':                       /* socket */
+           break;
+         case 's':                     /* socket */
 #ifdef S_IFSOCK
-         type_cell = S_IFSOCK;
-         rate = 1.59e-5f;
+           type_cell = S_IFSOCK;
+           rate = 1.59e-5f;
 #else
-         error (EXIT_FAILURE, 0,
-                _("-type %c is not supported because named sockets "
-                  "are not supported on the platform find was compiled on."),
-                (*typeletter));
+           type_cell = 0;
+           error (EXIT_FAILURE, 0,
+                  _("-type %c is not supported because named sockets "
+                    "are not supported on the platform find was compiled on."),
+                  (*typeletter));
 #endif
-         break;
-       case 'D':                       /* Solaris door */
+           break;
+         case 'D':                     /* Solaris door */
 #ifdef S_IFDOOR
-         type_cell = S_IFDOOR;
-         /* There are no Solaris doors on the example system surveyed
-          * above, but if someone uses -type D, they are presumably
-          * expecting to find a non-zero number.  We guess at a
-          * rate. */
-         rate = 1.0e-5f;
+           type_cell = S_IFDOOR;
+           /* There are no Solaris doors on the example system surveyed
+            * above, but if someone uses -type D, they are presumably
+            * expecting to find a non-zero number.  We guess at a
+            * rate. */
+           rate = 1.0e-5f;
 #else
-         error (EXIT_FAILURE, 0,
-                _("-type %c is not supported because Solaris doors "
-                  "are not supported on the platform find was compiled on."),
-                (*typeletter));
+           type_cell = 0;
+           error (EXIT_FAILURE, 0,
+                  _("-type %c is not supported because Solaris doors "
+                    "are not supported on the platform find was compiled on."),
+                  (*typeletter));
 #endif
-         break;
-       default:                        /* None of the above ... nuke 'em. */
-         error (EXIT_FAILURE, 0,
-                _("Unknown argument to -type: %c"), (*typeletter));
-         /*NOTREACHED*/
-         return false;
-       }
-      our_pred = insert_primary_withpred (entry, which_pred, typeletter);
-      our_pred->est_success_rate = rate;
-
-      /* Figure out if we will need to stat the file, because if we don't
-       * need to follow symlinks, we can avoid a stat call by using
-       * struct dirent.d_type.
-       */
-      if (which_pred == pred_xtype)
-       {
-         our_pred->need_stat = true;
-         our_pred->need_type = false;
-       }
-      else
-       {
-         our_pred->need_stat = false; /* struct dirent is enough */
-         our_pred->need_type = true;
-       }
-      our_pred->args.type = type_cell;
+           break;
+         default:                      /* None of the above ... nuke 'em. */
+           type_cell = 0;
+           error (EXIT_FAILURE, 0,
+                  _("Unknown argument to -type: %c"), (*typeletter));
+           /*NOTREACHED*/
+           return false;
+         }
+       our_pred = insert_primary_withpred (entry, which_pred, typeletter);
+       our_pred->est_success_rate = rate;
+
+       /* Figure out if we will need to stat the file, because if we don't
+        * need to follow symlinks, we can avoid a stat call by using
+        * struct dirent.d_type.
+        */
+       if (which_pred == pred_xtype)
+         {
+           our_pred->need_stat = true;
+           our_pred->need_type = false;
+         }
+       else
+         {
+           our_pred->need_stat = false; /* struct dirent is enough */
+           our_pred->need_type = true;
+         }
+       our_pred->args.type = type_cell;
+      }
       return true;
     }
   return false;
@@ -3235,7 +3243,7 @@ parse_time (const struct parser_table* entry, char 
*argv[], int *arg_ptr)
        {
          uintmax_t expected = origin.tv_sec + (DAYSECS-1);
          origin.tv_sec += (DAYSECS-1);
-         if (origin.tv_sec != expected)
+         if (expected != (uintmax_t)origin.tv_sec)
            {
              error (EXIT_FAILURE, 0,
                     _("arithmetic overflow when trying to calculate the end of 
today"));
diff --git a/find/pred.c b/find/pred.c
index 76683cc..0528048 100644
--- a/find/pred.c
+++ b/find/pred.c
@@ -73,7 +73,7 @@ static bool match_lname (const char *pathname, struct stat 
*stat_buf, struct pre
 struct pred_assoc
 {
   PRED_FUNC pred_func;
-  char *pred_name;
+  const char *pred_name;
 };
 
 struct pred_assoc pred_table[] =
diff --git a/find/util.c b/find/util.c
index 1b4a07a..2e047c2 100644
--- a/find/util.c
+++ b/find/util.c
@@ -325,12 +325,12 @@ check_nofollow (void)
       if (0 == strcmp ("Linux", uts.sysname))
        {
          /* Linux kernels 2.1.126 and earlier ignore the O_NOFOLLOW flag. */
-         return release >= 2.2; /* close enough */
+         return release >= 2.2f; /* close enough */
        }
       else if (0 == strcmp ("FreeBSD", uts.sysname))
        {
          /* FreeBSD 3.0-CURRENT and later support it */
-         return release >= 3.1;
+         return release >= 3.1f;
        }
     }
 
-- 
2.1.4




reply via email to

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