From 7046234c8bc77f4f4b7c305aaab4133a8c7682c0 Mon Sep 17 00:00:00 2001 From: James Youngman Date: Fri, 23 Dec 2005 18:24:20 +0000 Subject: [PATCH] Fixed many compilation warnings --- NEWS | 8 ++++-- find/find.c | 11 +++++++-- find/fstype.c | 2 ++ find/ftsfind.c | 1 - find/parser.c | 2 ++ find/pred.c | 13 ++++++++++ lib/buildcmd.c | 34 ++++++++++++++++--------- lib/buildcmd.h | 8 +++--- lib/regexprops.c | 36 +++++++++------------------ lib/regextype.c | 6 ++--- lib/regextype.h | 6 ++--- lib/savedirinfo.c | 2 +- locate/locate.c | 5 ++-- xargs/xargs.c | 63 +++++++++++++++++++++++++---------------------- 14 files changed, 114 insertions(+), 83 deletions(-) diff --git a/NEWS b/NEWS index 11f0fc35..e2d1b6e9 100644 --- a/NEWS +++ b/NEWS @@ -7,8 +7,12 @@ in the four named directories, rather than trying to parse an expression. (Savannah bug #15235). You now get a more helpful error message when you use command lines -which have missing expressions, such as 'find . ( )' or 'find . !'. - +which have missing expressions, such as + find . ( ) + find . ! + find . -a + find . \( -not \) + find . \( -true -a * Major changes in release 4.3.0 diff --git a/find/find.c b/find/find.c index 876e2719..1318c1d5 100644 --- a/find/find.c +++ b/find/find.c @@ -827,8 +827,11 @@ safely_chdir_nofollow(const char *dest, boolean *did_stat) { int extraflags, fd; - extraflags = 0; + (void) direction; + (void) statbuf_dest; + + extraflags = 0; *did_stat = false; switch (symlink_follow_option) @@ -1037,6 +1040,8 @@ static void do_process_top_dir(char *pathname, int mode, struct stat *pstat) { + (void) pstat; + process_path (pathname, base, false, ".", mode); complete_pending_execdirs(get_eval_tree()); } @@ -1046,6 +1051,8 @@ static void do_process_predicate(char *pathname, int mode, struct stat *pstat) { + (void) mode; + state.rel_pathname = base; apply_predicate (pathname, pstat, get_eval_tree()); } @@ -1264,7 +1271,7 @@ process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char * { int subdirs_left; /* Number of unexamined subdirs in PATHNAME. */ boolean subdirs_unreliable; /* if true, cannot use dir link count as subdir limif (if false, it may STILL be unreliable) */ - int idx; /* Which entry are we on? */ + unsigned int idx; /* Which entry are we on? */ struct stat stat_buf; struct savedir_dirinfo *dirinfo; diff --git a/find/fstype.c b/find/fstype.c index 921b54fa..0b4225a2 100644 --- a/find/fstype.c +++ b/find/fstype.c @@ -221,6 +221,8 @@ filesystem_type_uncached (const struct stat *statp, const char *path) struct mount_entry *entries, *entry; char *type; + (void) path; + #ifdef AFS if (in_afs(path)) { diff --git a/find/ftsfind.c b/find/ftsfind.c index 44ac14d8..c243e00c 100644 --- a/find/ftsfind.c +++ b/find/ftsfind.c @@ -414,7 +414,6 @@ process_all_startpoints(int argc, char *argv[]) int main (int argc, char **argv) { - int i; int end_of_leading_options = 0; /* First arg after any -H/-L etc. */ struct predicate *eval_tree; diff --git a/find/parser.c b/find/parser.c index 4bd25e7c..6aa001e6 100644 --- a/find/parser.c +++ b/find/parser.c @@ -135,7 +135,9 @@ static boolean parse_readable PARAMS((const struct parser_table*, char *arg static boolean parse_regex PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_regextype PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_samefile PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); +#if 0 static boolean parse_show_control_chars PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); +#endif static boolean parse_size PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_true PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_type PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); diff --git a/find/pred.c b/find/pred.c index 085475ae..2722b94b 100644 --- a/find/pred.c +++ b/find/pred.c @@ -1263,18 +1263,30 @@ pred_perm (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) boolean pred_executable (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) { + (void) pathname; + (void) stat_buf; + (void) pred_ptr; + return 0 == access(state.rel_pathname, X_OK); } boolean pred_readable (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) { + (void) pathname; + (void) stat_buf; + (void) pred_ptr; + return 0 == access(state.rel_pathname, R_OK); } boolean pred_writable (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) { + (void) pathname; + (void) stat_buf; + (void) pred_ptr; + return 0 == access(state.rel_pathname, W_OK); } @@ -1943,6 +1955,7 @@ pred_sanity_check(const struct predicate *predicates) case ARG_PUNCTUATION: case ARG_TEST: + case ARG_NOOP: /* Punctuation and tests should have no side * effects and not inhibit default print. */ diff --git a/lib/buildcmd.c b/lib/buildcmd.c index 03af0b72..820a193c 100644 --- a/lib/buildcmd.c +++ b/lib/buildcmd.c @@ -118,7 +118,7 @@ bc_do_insert (const struct buildcmd_control *ctl, real arg. */ static char *insertbuf; char *p; - int bytes_left = ctl->arg_max - 1; /* Bytes left on the command line. */ + size_t bytes_left = ctl->arg_max - 1; /* Bytes left on the command line. */ int need_prefix; /* XXX: on systems lacking an upper limit for exec args, ctl->arg_max @@ -145,9 +145,10 @@ bc_do_insert (const struct buildcmd_control *ctl, len = arglen; } - bytes_left -= len; - if (bytes_left <= 0) + if (bytes_left <= len) break; + else + bytes_left -= len; strncpy (p, arg, len); p += len; @@ -156,9 +157,11 @@ bc_do_insert (const struct buildcmd_control *ctl, if (s) { - bytes_left -= lblen; - if (bytes_left <= 0) - break; + if (bytes_left <= lblen) + break; + else + bytes_left -= lblen; + strcpy (p, linebuf); arg += ctl->rplen; arglen -= ctl->rplen; @@ -326,16 +329,21 @@ mbstrstr (const char *haystack, const char *needle) } -long +size_t bc_get_arg_max(void) { long val; + + /* We may resort to using LONG_MAX, so check it fits. */ + /* XXX: better to do a compile-time check */ + assert( (~(size_t)0) >= LONG_MAX); + #ifdef _SC_ARG_MAX val = sysconf(_SC_ARG_MAX); #else val = -1; #endif - + if (val > 0) return val; @@ -372,13 +380,15 @@ static int cb_exec_noop(const struct buildcmd_control *ctl, void bc_init_controlinfo(struct buildcmd_control *ctl) { - long arg_max = bc_get_arg_max(); - assert(arg_max > 0); + size_t arg_max = bc_get_arg_max(); ctl->exit_if_size_exceeded = 0; + + assert(arg_max > 2048u); /* XXX: this is an external condition, should not check it with assert. */ ctl->arg_max = arg_max - 2048; /* a la xargs */ + /* need to subtract 2 on the following line - for Linux/PPC */ - ctl->max_arg_count = (arg_max / sizeof(void*)) - 2; + ctl->max_arg_count = (arg_max / sizeof(void*)) - 2u; assert(ctl->max_arg_count > 0); ctl->rplen = 0u; ctl->replace_pat = NULL; @@ -402,7 +412,7 @@ bc_init_state(const struct buildcmd_control *ctl, * with no ARG_MAX, because ctl->arg_max may actually be LONG_MAX. * Also, adding one to that is a bad idea. */ - state->argbuf = (char *) xmalloc (ctl->arg_max + 1); + state->argbuf = (char *) xmalloc (ctl->arg_max + 1u); state->cmd_argv_chars = state->cmd_initial_argv_chars = 0; state->todo = 0; diff --git a/lib/buildcmd.h b/lib/buildcmd.h index 8d246f54..0c838f76 100644 --- a/lib/buildcmd.h +++ b/lib/buildcmd.h @@ -37,10 +37,10 @@ struct buildcmd_state char *argbuf; /* Number of chars being used in `cmd_argv'. */ - int cmd_argv_chars; + size_t cmd_argv_chars; /* Number of chars being used in `cmd_argv' for the initial args.. */ - int cmd_initial_argv_chars; + size_t cmd_initial_argv_chars; /* User context information. */ void *usercontext; @@ -56,7 +56,7 @@ struct buildcmd_control int exit_if_size_exceeded; /* false */ /* The maximum number of characters that can be used per command line. */ - long arg_max; + size_t arg_max; /* max_arg_count: the maximum number of arguments that can be used. * @@ -113,7 +113,7 @@ extern void bc_init_state(const struct buildcmd_control *ctl, struct buildcmd_state *state, void *usercontext); extern void bc_init_controlinfo(struct buildcmd_control *ctl); -extern long bc_get_arg_max(void); +extern size_t bc_get_arg_max(void); extern void bc_clear_args(const struct buildcmd_control *ctl, struct buildcmd_state *state); diff --git a/lib/regexprops.c b/lib/regexprops.c index 369e6988..06371cc6 100644 --- a/lib/regexprops.c +++ b/lib/regexprops.c @@ -36,6 +36,8 @@ char *program_name; static void output(const char *s, int escape) { + (void) escape; + fputs(s, stdout); } @@ -67,26 +69,16 @@ static void enum_item(const char *s) literal(s); newline(); } -static void table_item(const char *s) -{ - directive("@item"); - newline(); - content(s); - newline(); -} - -static void code(const char *s) -{ - directive("@code{"); - content(s); - directive("}"); -} static void begin_subsection(const char *name, const char *next, const char *prev, const char *up) { + (void) next; + (void) prev; + (void) up; + newline(); directive("@node "); @@ -102,13 +94,6 @@ static void begin_subsection(const char *name, newline(); } -static void begintable_asis() -{ - newline(); - directive("@table @asis"); - newline(); -} - static void begintable_markup(char const *markup) { newline(); @@ -144,7 +129,8 @@ static void newpara() } -static int describe_regex_syntax(int options) +static void +describe_regex_syntax(int options) { newpara(); content("The character @samp{.} matches any single character"); @@ -435,7 +421,8 @@ static int describe_regex_syntax(int options) -static int menu() +static void +menu(void) { int i, options; const char *name; @@ -456,7 +443,8 @@ static int menu() } -static int describe_all(const char *up) +static void +describe_all(const char *up) { const char *name, *next, *previous; int options; diff --git a/lib/regextype.c b/lib/regextype.c index 9aaa6c67..768a82b2 100644 --- a/lib/regextype.c +++ b/lib/regextype.c @@ -120,7 +120,7 @@ get_regex_type(const char *s) const char * -get_regex_type_name(int ix) +get_regex_type_name(unsigned int ix) { if (ix < N_REGEX_MAP_ENTRIES) return regex_map[ix].name; @@ -129,7 +129,7 @@ get_regex_type_name(int ix) } int -get_regex_type_flags(int ix) +get_regex_type_flags(unsigned int ix) { if (ix < N_REGEX_MAP_ENTRIES) return regex_map[ix].option_val; @@ -138,7 +138,7 @@ get_regex_type_flags(int ix) } -int get_regex_type_synonym(int ix) +int get_regex_type_synonym(unsigned int ix) { unsigned i; int flags; diff --git a/lib/regextype.h b/lib/regextype.h index e28815fd..3647bb82 100644 --- a/lib/regextype.h +++ b/lib/regextype.h @@ -23,6 +23,6 @@ int get_regex_type(const char *s); -const char * get_regex_type_name(int ix); -int get_regex_type_flags(int ix); -int get_regex_type_synonym(int ix); +const char * get_regex_type_name(unsigned int ix); +int get_regex_type_flags(unsigned int ix); +int get_regex_type_synonym(unsigned int ix); diff --git a/lib/savedirinfo.c b/lib/savedirinfo.c index 1d2f9967..7ef031cd 100644 --- a/lib/savedirinfo.c +++ b/lib/savedirinfo.c @@ -263,7 +263,7 @@ new_savedirinfo (const char *dir, struct savedir_extrainfo **extra) struct savedir_dirinfo *p = xsavedir(dir, SavedirSort); char *buf, *s; size_t bufbytes = 0; - int i; + unsigned int i; if (p) { diff --git a/locate/locate.c b/locate/locate.c index c94a826f..32f18877 100644 --- a/locate/locate.c +++ b/locate/locate.c @@ -229,14 +229,15 @@ locate_read_str(char **buf, size_t *siz, FILE *fp, int delimiter, int offs) { char * p = NULL; size_t sz = 0; - int needed, nread; + int nread; + size_t needed; nread = getdelim(&p, &sz, delimiter, fp); if (nread >= 0) { assert(p != NULL); - needed = offs + nread + 1; + needed = offs + nread + 1u; if (needed > (*siz)) { char *pnew = realloc(*buf, needed); diff --git a/xargs/xargs.c b/xargs/xargs.c index 3eba3662..87b760cf 100644 --- a/xargs/xargs.c +++ b/xargs/xargs.c @@ -223,9 +223,9 @@ static int pids_alloc = 0; /* Exit status; nonzero if any child process exited with a status of 1-125. */ -volatile static int child_error = 0; +static volatile int child_error = 0; -volatile static int original_exit_value; +static volatile int original_exit_value; /* If true, print each command on stderr before executing it. */ static boolean print_command = false; /* Option -t */ @@ -271,12 +271,12 @@ static void add_proc PARAMS ((pid_t pid)); static void wait_for_proc PARAMS ((boolean all)); static void wait_for_proc_all PARAMS ((void)); static long parse_num PARAMS ((char *str, int option, long min, long max, int fatal)); -static long env_size PARAMS ((char **envp)); +static size_t env_size PARAMS ((char **envp)); static void usage PARAMS ((FILE * stream)); -static long +static size_t get_line_max(void) { long val; @@ -371,8 +371,6 @@ get_char_oct_or_hex_escape(const char *s) static char get_input_delimiter(const char *s) { - char result = '\0'; - if (1 == strlen(s)) { return s[0]; @@ -409,6 +407,8 @@ get_input_delimiter(const char *s) error(1, 0, _("Invalid input delimiter specification %s: the delimiter must be either a single character or an escape sequence starting with \\."), s); + /*NOTREACHED*/ + return 0; } } } @@ -422,10 +422,10 @@ main (int argc, char **argv) int show_limits = 0; /* --show-limits */ int always_run_command = 1; char *input_file = "-"; /* "-" is stdin */ - long posix_arg_size_max; - long posix_arg_size_min; - long arg_size; - long size_of_environment = env_size(environ); + size_t posix_arg_size_max; + size_t posix_arg_size_min; + size_t arg_size; + size_t size_of_environment = env_size(environ); char *default_cmd = "/bin/echo"; int (*read_args) PARAMS ((void)) = read_line; int env_too_big = 0; @@ -458,12 +458,12 @@ main (int argc, char **argv) /* Start with a reasonable default size, though this can be * adjusted via the -s option. */ - arg_size = (128 * 1024) + size_of_environment; + arg_size = (128u * 1024u) + size_of_environment; /* Take the size of the environment into account. */ if (size_of_environment > posix_arg_size_max) { - bc_ctl.arg_max = 0; + bc_ctl.arg_max = 0u; env_too_big = 1; } else @@ -643,28 +643,30 @@ main (int argc, char **argv) { if (show_limits) { + /* XXX: this will silently go wrong if sizeof(size_t)>sizeof(unsigned long) */ fprintf(stderr, - _("Reducing arg_max (%ld) to arg_size (%ld)\n"), - bc_ctl.arg_max, arg_size); + _("Reducing arg_max (%lu) to arg_size (%lu)\n"), + (unsigned long)bc_ctl.arg_max, (unsigned long)arg_size); } bc_ctl.arg_max = arg_size; } if (show_limits) { + /* XXX: this will all silently go wrong if sizeof(size_t)>sizeof(unsigned long) */ fprintf(stderr, - _("Your environment variables take up %ld bytes\n"), - size_of_environment); + _("Your environment variables take up %lu bytes\n"), + (unsigned long)size_of_environment); fprintf(stderr, - _("POSIX lower and upper limits on argument length: %ld, %ld\n"), - posix_arg_size_min, - posix_arg_size_max); + _("POSIX lower and upper limits on argument length: %lu, %lu\n"), + (unsigned long)posix_arg_size_min, + (unsigned long)posix_arg_size_max); fprintf(stderr, _("Maximum length of command we could actually use: %ld\n"), - (posix_arg_size_max - size_of_environment)); + (unsigned long)(posix_arg_size_max - size_of_environment)); fprintf(stderr, - _("Size of command buffer we are actually using: %ld\n"), - bc_ctl.arg_max); + _("Size of command buffer we are actually using: %lu\n"), + (unsigned long)bc_ctl.arg_max); if (isatty(STDIN_FILENO)) { @@ -678,8 +680,8 @@ main (int argc, char **argv) } - linebuf = (char *) xmalloc (bc_ctl.arg_max + 1); - bc_state.argbuf = (char *) xmalloc (bc_ctl.arg_max + 1); + linebuf = (char *) xmalloc (bc_ctl.arg_max + 1u); + bc_state.argbuf = (char *) xmalloc (bc_ctl.arg_max + 1u); /* Make sure to listen for the kids. */ signal (SIGCHLD, SIG_DFL); @@ -712,7 +714,7 @@ main (int argc, char **argv) else { int i; - size_t len; + int len; size_t *arglen = (size_t *) xmalloc (sizeof (size_t) * argc); for (i = optind; i < argc; i++) @@ -766,7 +768,7 @@ read_line (void) int len; char *p = linebuf; /* Including the NUL, the args must not grow past this point. */ - char *endbuf = linebuf + bc_ctl.arg_max - bc_state.cmd_initial_argv_chars - 1; + char *endbuf = linebuf + bc_ctl.arg_max - bc_state.cmd_initial_argv_chars - 1u; if (eof) return -1; @@ -906,7 +908,7 @@ read_string (void) int len; char *p = linebuf; /* Including the NUL, the args must not grow past this point. */ - char *endbuf = linebuf + bc_ctl.arg_max - bc_state.cmd_initial_argv_chars - 1; + char *endbuf = linebuf + bc_ctl.arg_max - bc_state.cmd_initial_argv_chars - 1u; if (eof) return -1; @@ -1019,6 +1021,9 @@ xargs_do_exec (const struct buildcmd_control *ctl, struct buildcmd_state *state) { pid_t child; + (void) ctl; + (void) state; + bc_push_arg (&bc_ctl, &bc_state, (char *) NULL, 0, NULL, 0, @@ -1223,10 +1228,10 @@ parse_num (char *str, int option, long int min, long int max, int fatal) /* Return how much of ARG_MAX is used by the environment. */ -static long +static size_t env_size (char **envp) { - long len = 0; + size_t len = 0u; while (*envp) len += strlen (*envp++) + 1;