bug-findutils
[Top][All Lists]
Advanced

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

[PATCH 2/2] Fix further compiler warnings.


From: James Youngman
Subject: [PATCH 2/2] Fix further compiler warnings.
Date: Tue, 14 Jun 2011 23:46:01 +0100

* find/ftsfind.c (show_outstanding_execdirs): Now that
execp->state.cmd_argc is a size_t, we can't print it with %d.  So
print it with PRIuMAX (and include <inttypes.h> to define that).
* find/tree.c (prec_name): change return type to const char*.
(type_name): Likewise.
* find/exec.c (impl_pred_exec): use a separate variable (buf) to
point the memory allocated/freed with malloc/free, so that the
existing variable target can then be const (and so we can assign
pathname to it without a compiler warning).
---
 ChangeLog      |   12 ++++++++++++
 find/exec.c    |    9 +++++----
 find/ftsfind.c |    3 ++-
 find/tree.c    |    4 ++--
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index eec86a0..6e12156 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2011-06-14  James Youngman  <address@hidden>
 
+       Fix further compiler warnings.
+       * find/ftsfind.c (show_outstanding_execdirs): Now that
+       execp->state.cmd_argc is a size_t, we can't print it with %d.  So
+       print it with PRIuMAX (and include <inttypes.h> to define that).
+       * find/tree.c (prec_name): change return type to const char*.
+       (type_name): Likewise.
+       * find/exec.c (impl_pred_exec): use a separate variable (buf) to
+       point the memory allocated/freed with malloc/free, so that the
+       existing variable target can then be const (and so we can assign
+       pathname to it without a compiler warning).
+
        Eliminate some compiler warnings.
        * find/find.c: Remove definition of SAFE_CHDIR, which we don't
        use.
@@ -31,6 +42,7 @@
        (prec_name): Likewise!  Also remove spurious parentheses around
        return value.
        (prec_name): Remove spurious parentheses around return value.
+
        * lib/buildcmd.h (buildcmd_state): change types of several fields
        to size_t: cmd_argc, cmd_argv_alloc, largest_successful_arg_count,
        smallest_failed_arg_count.
diff --git a/find/exec.c b/find/exec.c
index 95e3c6b..989f207 100644
--- a/find/exec.c
+++ b/find/exec.c
@@ -114,7 +114,8 @@ impl_pred_exec (const char *pathname,
                struct predicate *pred_ptr)
 {
   struct exec_val *execp = &pred_ptr->args.exec_vec;
-  char *target;
+  char *buf = NULL;
+  const char *target;
   bool result;
   const bool local = is_exec_in_local_dir (pred_ptr->pred_func);
   char *prefix;
@@ -135,7 +136,7 @@ impl_pred_exec (const char *pathname,
                 safely_quote_err_filename (0, pathname));
          /*NOTREACHED*/
        }
-      target = base_name (state.rel_pathname);
+      target = buf = base_name (state.rel_pathname);
       if ('/' == target[0])
        {
          /* find / execdir ls -d {} \; */
@@ -210,10 +211,10 @@ impl_pred_exec (const char *pathname,
          result = false;
        }
     }
-  if (target != pathname)
+  if (buf)
     {
       assert (local);
-      free (target);
+      free (buf);
     }
   return result;
 }
diff --git a/find/ftsfind.c b/find/ftsfind.c
index 0d372f1..51d5749 100644
--- a/find/ftsfind.c
+++ b/find/ftsfind.c
@@ -38,6 +38,7 @@
 #include <errno.h>
 #include <assert.h>
 #include <locale.h>
+#include <inttypes.h>
 
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -305,7 +306,7 @@ show_outstanding_execdirs (FILE *fp)
              fprintf (fp, "%s ", pfx);
              if (execp->multiple)
                fprintf (fp, "multiple ");
-             fprintf (fp, "%d args: ", execp->state.cmd_argc);
+             fprintf (fp, "%" PRIuMAX " args: ", (uintmax_t) 
execp->state.cmd_argc);
              for (i=0; i<execp->state.cmd_argc; ++i)
                {
                  fprintf (fp, "%s ", execp->state.cmd_argv[i]);
diff --git a/find/tree.c b/find/tree.c
index 038bfc9..0177aac 100644
--- a/find/tree.c
+++ b/find/tree.c
@@ -1642,7 +1642,7 @@ cost_name (enum EvaluationCost cost)
 }
 
 
-static char *
+static const char *
 type_name (short type)
 {
   int i;
@@ -1653,7 +1653,7 @@ type_name (short type)
   return type_table[i].type_name;
 }
 
-static char *
+static const char *
 prec_name (short prec)
 {
   int i;
-- 
1.7.2.5




reply via email to

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