* xargs/xargs.c: Remove definition of the unused macro VOID. Include error.h instead of declaring error (incorrectly). Change the type of lineno from int to size_t. (get_char_oct_or_hex_escape): Don't point endp unnecessarily at p, because they have different constness. There's no need for this, just initialise it to NULL. (main): Make input_file const. Make the default arglist non-const, to avoid a constness warning. (main): Pass the option name as the argument to error's %s format, as opposed to the whole struct (this was a bug, but since the name member was the first in the struct, there were probably no symptoms). (main): read_args returns an int, but the only negative value it can return is -1. Once we know that didn't happen, assign the value to a size_t variable to avoid signed/unsigned warnings elsewhere. (xargs_do_exec): Manually inhibit some unused-parameters warnings. (print_args): Use size_t as the type of a loop variable. (wait_for_proc): Since procs_executing is an unsigned long, use a %lu format specifier to print it. (increment_proc_max): Inhibit an unused-parameter warning (the signal number). (decrement_proc_max): Likewise. * lib/buildcmd.h (struct buildcmd_control): Make member replace_pat const. Change the type of lines_per_exec to unsigned long. --- ChangeLog | 30 ++++++++++++++++++++++++++++++ lib/buildcmd.h | 4 ++-- xargs/xargs.c | 40 ++++++++++++++++++++-------------------- 3 files changed, 52 insertions(+), 22 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 0fdcf46..6993129 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2011-06-18 James Youngman <[email protected]> + + Fix some compiler warnings in xargs. + * xargs/xargs.c: Remove definition of the unused macro VOID. + Include error.h instead of declaring error (incorrectly). + Change the type of lineno from int to size_t. + (get_char_oct_or_hex_escape): Don't point endp unnecessarily at p, + because they have different constness. There's no need for this, + just initialise it to NULL. + (main): Make input_file const. Make the default arglist + non-const, to avoid a constness warning. + (main): Pass the option name as the argument to error's %s format, + as opposed to the whole struct (this was a bug, but since the name + member was the first in the struct, there were probably no + symptoms). + (main): read_args returns an int, but the only negative value it + can return is -1. Once we know that didn't happen, assign the + value to a size_t variable to avoid signed/unsigned warnings + elsewhere. + (xargs_do_exec): Manually inhibit some unused-parameters warnings. + (print_args): Use size_t as the type of a loop variable. + (wait_for_proc): Since procs_executing is an unsigned long, use a + %lu format specifier to print it. + (increment_proc_max): Inhibit an unused-parameter warning (the + signal number). + (decrement_proc_max): Likewise. + * lib/buildcmd.h (struct buildcmd_control): Make member + replace_pat const. Change the type of lines_per_exec to unsigned + long. + 2011-06-15 James Youngman <[email protected]> Fix compiler warnings in lib/regextype.c and find/parser.c. diff --git a/lib/buildcmd.h b/lib/buildcmd.h index 860a747..dd8f3fc 100644 --- a/lib/buildcmd.h +++ b/lib/buildcmd.h @@ -87,7 +87,7 @@ struct buildcmd_control the end of the command argument list, they are each stuck into the initial args, replacing each occurrence of the `replace_pat' in the initial args. */ - char *replace_pat; + const char *replace_pat; /* Number of initial arguments given on the command line. */ size_t initial_argc; /* 0 */ @@ -97,7 +97,7 @@ struct buildcmd_control /* If nonzero, the maximum number of nonblank lines from stdin to use per command line. */ - size_t lines_per_exec; /* 0 */ + unsigned long lines_per_exec; /* 0 */ /* The maximum number of arguments to use per command line. */ size_t args_per_exec; diff --git a/xargs/xargs.c b/xargs/xargs.c index eaa33e0..0352faf 100644 --- a/xargs/xargs.c +++ b/xargs/xargs.c @@ -84,16 +84,9 @@ /* Return nonzero if S is the EOF string. */ #define EOF_STR(s) (eof_str && *eof_str == *s && !strcmp (eof_str, s)) -#if __STDC__ -#define VOID void -#else -#define VOID char -#endif - #include <xalloc.h> #include "closein.h" - -void error (int status, int errnum, char *message,...); +#include "error.h" extern char *version_string; @@ -105,7 +98,7 @@ static char *linebuf; static int keep_stdin = 0; /* Line number in stdin since the last command was executed. */ -static int lineno = 0; +static size_t lineno = 0; static struct buildcmd_state bc_state; static struct buildcmd_control bc_ctl; @@ -263,7 +256,7 @@ get_char_oct_or_hex_escape (const char *s) s); } errno = 0; - endp = (char*)p; + endp = NULL; val = strtoul (p, &endp, base); /* This if condition is carefully constructed to do @@ -374,8 +367,9 @@ main (int argc, char **argv) int optc, option_index; int show_limits = 0; /* --show-limits */ int always_run_command = 1; - char *input_file = "-"; /* "-" is stdin */ - char *default_cmd = "echo"; + const char *input_file = "-"; /* "-" is stdin */ + char default_cmd[] = "echo"; + char *default_arglist[1]; int (*read_args) (void) = read_line; void (*act_on_init_result)(void) = noop; enum BC_INIT_STATUS bcstatus; @@ -610,7 +604,7 @@ main (int argc, char **argv) { error (EXIT_FAILURE, 0, _("option --%s may not be set to a value which includes `='"), - longopts[option_index]); + longopts[option_index].name); } slot_var_name = optarg; if (0 != unsetenv (slot_var_name)) @@ -685,7 +679,8 @@ main (int argc, char **argv) { optind = 0; argc = 1; - argv = &default_cmd; + default_arglist[0] = default_cmd; + argv = default_arglist; } if (show_limits) @@ -760,15 +755,15 @@ main (int argc, char **argv) } else { - int i; - size_t len; + int i, args; size_t *arglen = xmalloc (sizeof (size_t) * argc); for (i = optind; i < argc; i++) arglen[i] = strlen (argv[i]); bc_ctl.rplen = strlen (bc_ctl.replace_pat); - while ((len = (*read_args) ()) != -1) + while ((args = (*read_args) ()) != -1) { + size_t len = (size_t) args; /* Don't do insert on the command name. */ bc_clear_args (&bc_ctl, &bc_state); bc_state.cmd_argv_chars = 0; /* begin at start of buffer */ @@ -1039,7 +1034,7 @@ read_string (void) static bool print_args (bool ask) { - int i; + size_t i; for (i = 0; i < bc_state.cmd_argc - 1; i++) fprintf (stderr, "%s ", bc_state.cmd_argv[i]); @@ -1146,7 +1141,8 @@ prep_child_for_exec (void) * stdin is almost as good as executing it * with its stdin attached to /dev/null. */ - error (0, errno, "%s", quotearg_n_style (0, locale_quoting_style, inputfile)); + error (0, errno, "%s", + quotearg_n_style (0, locale_quoting_style, inputfile)); } } } @@ -1169,6 +1165,8 @@ xargs_do_exec (struct buildcmd_control *ctl, void *usercontext, int argc, char * int r; (void) ctl; + (void) argc; + (void) usercontext; if (!query_before_executing || print_args (true)) { @@ -1442,7 +1440,7 @@ wait_for_proc (bool all, unsigned int minreap) * number of child processes still executing, so the * loop should have terminated. */ - error (0, 0, _("WARNING: Lost track of %d child processes"), + error (0, 0, _("WARNING: Lost track of %lu child processes"), procs_executing); } else @@ -1519,6 +1517,7 @@ wait_for_proc_all (void) static void increment_proc_max (int ignore) { + (void) ignore; /* If user increments from 0 to 1, we'll take it and serialize. */ proc_max++; /* If we're waiting for a process to die before doing something, @@ -1529,6 +1528,7 @@ increment_proc_max (int ignore) static void decrement_proc_max (int ignore) { + (void) ignore; if (proc_max > 1) proc_max--; } -- 1.7.2.5
