[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 9/9] Compiler warning fixes in find/pred.c.
From: |
James Youngman |
Subject: |
[PATCH 9/9] Compiler warning fixes in find/pred.c. |
Date: |
Sat, 4 Jun 2011 01:21:53 +0100 |
* find/pred.c (mode_to_filetype): return const char*.
(impl_pred_exec): Make target and prefix variables const.
(impl_pred_exec): Separate 'target' variable (which sometimes
points to a string literal) from a separate 'buf' variable (which,
if set, is always the value returned by base_name, which needs to
be freed.
(checked_fwrite): Store the result of fwrite in a size_t (i.e. the
same type the function returns).
---
ChangeLog | 10 ++++++++++
find/pred.c | 15 ++++++++-------
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9bc411f..987fe22 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2011-06-03 James Youngman <address@hidden>
+ Compiler warning fixes in find/pred.c.
+ * find/pred.c (mode_to_filetype): return const char*.
+ (impl_pred_exec): Make target and prefix variables const.
+ (impl_pred_exec): Separate 'target' variable (which sometimes
+ points to a string literal) from a separate 'buf' variable (which,
+ if set, is always the value returned by base_name, which needs to
+ be freed.
+ (checked_fwrite): Store the result of fwrite in a size_t (i.e. the
+ same type the function returns).
+
Eliminate some compiler warnings in parser.c
* find/parser.c: Don't define the macros STRINGIFY and
PARSE_ACTION_NP.
diff --git a/find/pred.c b/find/pred.c
index 3acfe9f..0c68df6 100644
--- a/find/pred.c
+++ b/find/pred.c
@@ -561,10 +561,11 @@ 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;
+ const char *prefix;
size_t pfxlen;
(void) stat_buf;
@@ -582,7 +583,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 {} \; */
@@ -657,10 +658,10 @@ impl_pred_exec (const char *pathname,
result = false;
}
}
- if (target != pathname)
+ if (buf)
{
assert (local);
- free (target);
+ free (buf);
}
return result;
}
@@ -729,7 +730,7 @@ pred_fprint0 (const char *pathname, struct stat *stat_buf,
struct predicate *pre
-static char*
+static const char*
mode_to_filetype (mode_t m)
{
#define HANDLE_TYPE(t,letter) if (m==t) { return letter; }
@@ -810,7 +811,7 @@ checked_print_quoted (struct format_val *dest,
static void
checked_fwrite (void *p, size_t siz, size_t nmemb, struct format_val *dest)
{
- int items_written = fwrite (p, siz, nmemb, dest->stream);
+ const size_t items_written = fwrite (p, siz, nmemb, dest->stream);
if (items_written < nmemb)
nonfatal_nontarget_file_error (errno, dest->filename);
}
--
1.7.2.5
- [PATCH 1/9] Don't display a separate gnulib version., James Youngman, 2011/06/03
- [PATCH 2/9] Fix some compiler warnings in findutils-version.c., James Youngman, 2011/06/03
- [PATCH 4/9] Fix compiler warnings in lib/fdleak.c, James Youngman, 2011/06/03
- [PATCH 5/9] Fix a compiler warning in lib/buildcmd.c, James Youngman, 2011/06/03
- [PATCH 9/9] Compiler warning fixes in find/pred.c.,
James Youngman <=
- [PATCH 7/9] Avoid code redundancy in lib/buildcmd.c., James Youngman, 2011/06/03
- [PATCH 8/9] Eliminate some compiler warnings in parser.c, James Youngman, 2011/06/03
- [PATCH 6/9] Eliminate some compiler warnings in find/parser.c., James Youngman, 2011/06/03
- [PATCH 3/9] Fix several small compiler warnings., James Youngman, 2011/06/03