diff options
author | James Youngman <jay@gnu.org> | 2011-06-03 10:21:06 +0100 |
---|---|---|
committer | James Youngman <jay@gnu.org> | 2011-06-04 00:55:51 +0100 |
commit | 97218037b0cc7062599e47e54387f15ba720f7fa (patch) | |
tree | bfb3e45dc9c767d6554b9540162a51d63cfeb933 | |
parent | c8e53a0c71bce22be58bec07f90ac20d54df20f7 (diff) | |
download | findutils-97218037b0cc7062599e47e54387f15ba720f7fa.tar.gz |
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).
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | find/pred.c | 15 |
2 files changed, 18 insertions, 7 deletions
@@ -1,5 +1,15 @@ 2011-06-03 James Youngman <jay@gnu.org> + 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 3acfe9f8..0c68df67 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); } |