From 991f57a515c5c7631888937617681f859c4d0cb3 Mon Sep 17 00:00:00 2001 From: jay Date: Sun, 25 Feb 2007 12:05:51 +0000 Subject: [PATCH] Eliminated a few compiler warnings --- ChangeLog | 42 ++++++++++++++++++++++++++++++ find/find.c | 12 ++++++++- find/parser.c | 4 --- find/pred.c | 1 + find/tree.c | 81 ++++++++++++++++++++++++++++++++------------------------- find/util.c | 2 -- lib/buildcmd.c | 2 +- locate/locate.c | 14 ++++++---- xargs/xargs.c | 2 +- 9 files changed, 110 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3aed91b..4ba8f28 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,45 @@ +2007-02-25 James Youngman + + * find/find.c (process_dir): Removed duplicated (shadow) + declaration of did_stat. Assert that we did not use subdirs_left + if subdirs_unreliable is true. + + * find/parser.c (parse_size): Removed unused variable rate. + (parse_time): Removed unused variable num_days_approx. + (get_num): Removed unused variables ok and suffixes. + + * find/pred.c (do_fprintf): Indicate that the function needs a + return value (referring to Savannah bug #19146). + + * find/tree.c (predlist_dump): Commented out unused function + (predlist_merge_nosort): Commented out unused function + (getrate): Returns type is float, so return 1.0f not 1.0. + (calculate_derived_rates): Removed unused variable rate. Use a + switch statement rater than ifs. + + * find/util.c (usage): Removed unused variale i. + + * lib/buildcmd.c (bc_do_insert): Removed unused variable + need_prefix. + (bc_init_controlinfo): annotate a line (with #warning) which is + probably a bug. + + * locate/locate.c: #include for the benefit of the + setgroups() call in drop_privs. + (slocate_db_pathname): Commented out unused variable. + (set_max_db_age): error command has no format directive, so + remove the unused extra argument. + (looking_at_slocate_db): Removed unused variables magic and + lenwanted. Fix bug where result is indeterminate (due to falling + off the end of the function) if the first character is a nondigit. + (search_one_database): Eliminate (spurious) compiler warning + rlating to possible use before initialisation of slocate_seclevel. + + * xargs/xargs.c (get_char_oct_or_hex_escape): Eliminate spurious + compiler warning on variable p. + (main): Removed unused varible env_too_big + + 2007-02-24 James Youngman * find/parser.c (pred_sanity_check): define this function even for diff --git a/find/find.c b/find/find.c index 6c2a949..fcfc756 100644 --- a/find/find.c +++ b/find/find.c @@ -1219,6 +1219,7 @@ process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char * if (statp->st_nlink < 2) { subdirs_unreliable = true; + subdirs_left = 0; } else { @@ -1354,6 +1355,7 @@ process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char * state.exit_status = 1; /* We know the result is wrong, now */ options.no_leaf_check = true; /* Don't make same mistake again */ + subdirs_unreliable = 1; subdirs_left = 1; /* band-aid for this iteration. */ } @@ -1391,7 +1393,6 @@ process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char * { enum SafeChdirStatus status; struct dir_id did; - boolean did_stat = false; /* We could go back and do the next command-line arg instead, maybe using longjmp. */ @@ -1406,6 +1407,7 @@ process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char * dir = parent; } + did_stat = false; status = safely_chdir (dir, TraversingUp, &stat_buf, SymlinkHandleDefault, &did_stat); switch (status) { @@ -1441,4 +1443,12 @@ process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char * free (cur_path); free_dirinfo(dirinfo); } + + if (subdirs_unreliable) + { + /* Make sure we hasn't used the variable subdirs_left if we knew + * we shouldn't do so. + */ + assert(0 == subdirs_left || options.no_leaf_check); + } } diff --git a/find/parser.c b/find/parser.c index 6c15449..583b964 100644 --- a/find/parser.c +++ b/find/parser.c @@ -1651,7 +1651,6 @@ parse_size (const struct parser_table* entry, char **argv, int *arg_ptr) enum comparison_type c_type; int blksize = 512; int len; - float rate = 1.0; if ((argv == NULL) || (argv[*arg_ptr] == NULL)) return false; @@ -2690,7 +2689,6 @@ get_relative_timestamp (char *str, static boolean parse_time (const struct parser_table* entry, char *argv[], int *arg_ptr) { - float num_days_approx; struct predicate *our_pred; struct time_val tval; enum comparison_type comp; @@ -2800,8 +2798,6 @@ get_num (char *str, enum comparison_type *comp_type) { char *pend; - boolean ok; - const char *suffixes; if (str == NULL) return false; diff --git a/find/pred.c b/find/pred.c index e2adf8a..49a338c 100644 --- a/find/pred.c +++ b/find/pred.c @@ -904,6 +904,7 @@ do_fprintf(FILE *fp, } break; } + #warning this function needs a return statement. See Savannah bug#19146. } boolean diff --git a/find/tree.c b/find/tree.c index 414cad2..413e963 100644 --- a/find/tree.c +++ b/find/tree.c @@ -309,6 +309,7 @@ predlist_insert(struct predlist *list, list->tail = list->head; } +#if 0 static void predlist_dump(FILE *fp, const char *label, const struct predlist *list) { @@ -334,6 +335,7 @@ predlist_merge_nosort(struct predlist *list, } } +#endif static int pred_cost_compare(const struct predicate *p1, const struct predicate *p2, boolean wantfailure) { @@ -1181,15 +1183,13 @@ getrate(const struct predicate *p) if (p) return p->est_success_rate; else - return 1.0; + return 1.0f; } float calculate_derived_rates(struct predicate *p) { - float rate; - assert(NULL != p); if (p->pred_right) @@ -1199,48 +1199,57 @@ calculate_derived_rates(struct predicate *p) assert(p->p_type != CLOSE_PAREN); assert(p->p_type != OPEN_PAREN); - - if (p->p_type == PRIMARY_TYPE) + + switch (p->p_type) { + case NO_TYPE: assert(NULL == p->pred_right); assert(NULL == p->pred_left); return p->est_success_rate; - } - else if (p->p_type == UNI_OP) - { + + case PRIMARY_TYPE: + assert(NULL == p->pred_right); + assert(NULL == p->pred_left); + return p->est_success_rate; + + case UNI_OP: /* Unary operators must have exactly one operand */ assert(pred_negate == p->pred_func); assert(NULL == p->pred_left); - rate = 1.0 - p->pred_right->est_success_rate; - } - else if (p->p_type == BI_OP) - { - /* Binary operators must have two operands */ - if (pred_and == p->pred_func) - { - rate = getrate(p->pred_right) * getrate(p->pred_left); - } - else if (pred_comma == p->pred_func) - { - rate = 1.0; - } - else if (pred_or == p->pred_func) - { - rate = getrate(p->pred_right) + getrate(p->pred_left); - } - } - else if (p->p_type == CLOSE_PAREN || p->p_type == OPEN_PAREN) - { - rate = 1.0; - } - else if (p->p_type == NO_TYPE) - { - assert(NULL == p->pred_right); - assert(NULL == p->pred_left); + p->est_success_rate = (1.0 - p->pred_right->est_success_rate); + return p->est_success_rate; + + case BI_OP: + { + float rate; + /* Binary operators must have two operands */ + if (pred_and == p->pred_func) + { + rate = getrate(p->pred_right) * getrate(p->pred_left); + } + else if (pred_comma == p->pred_func) + { + rate = 1.0f; + } + else if (pred_or == p->pred_func) + { + rate = getrate(p->pred_right) + getrate(p->pred_left); + } + else + { + /* only and, or and comma are BI_OP. */ + assert(0); + rate = 0.0f; + } + p->est_success_rate = constrain_rate(rate); + } + return p->est_success_rate; + + case OPEN_PAREN: + case CLOSE_PAREN: + p->est_success_rate = 1.0; return p->est_success_rate; } - p->est_success_rate = constrain_rate(rate); - return p->est_success_rate; } /* opt_expr() rearranges predicates such that each left subtree is diff --git a/find/util.c b/find/util.c index 11b1003..c84dae8 100644 --- a/find/util.c +++ b/find/util.c @@ -150,8 +150,6 @@ show_valid_debug_options(FILE *fp, int full) void usage (FILE *fp, int status, char *msg) { - size_t i; - if (msg) fprintf (fp, "%s: %s\n", program_name, msg); diff --git a/lib/buildcmd.c b/lib/buildcmd.c index c90081f..05f54e1 100644 --- a/lib/buildcmd.c +++ b/lib/buildcmd.c @@ -123,7 +123,6 @@ bc_do_insert (const struct buildcmd_control *ctl, static char *insertbuf; char *p; 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 * may have been set to LONG_MAX (see bc_get_arg_max()). Hence @@ -443,6 +442,7 @@ bc_init_controlinfo(struct buildcmd_control *ctl) } else { +#warning the next line is probably a bug. ctl->posix_arg_size_max - size_of_environment; } diff --git a/locate/locate.c b/locate/locate.c index 8c99272..0249cde 100644 --- a/locate/locate.c +++ b/locate/locate.c @@ -65,6 +65,7 @@ #include #include #include +#include /* for setgroups() */ #include #include #include @@ -189,7 +190,7 @@ static bool stdout_is_a_tty; static bool print_quoted_filename; static bool results_were_filtered; -static char* slocate_db_pathname = "/var/lib/slocate/slocate.db"; +/* static char* slocate_db_pathname = "/var/lib/slocate/slocate.db"; */ static const char *selected_secure_db = NULL; @@ -207,8 +208,7 @@ set_max_db_age(const char *s) if (0 == *s) { error(1, 0, - _("The argument argument for option --max-database-age must not be empty"), - s); + _("The argument argument for option --max-database-age must not be empty")); } @@ -957,8 +957,6 @@ looking_at_slocate_locatedb (const char *filename, size_t len, int *seclevel) { - char slocate_magic[] = "1"; - size_t lenwanted = sizeof(slocate_magic); assert(len <= 2); if (len < 2) @@ -993,6 +991,11 @@ looking_at_slocate_locatedb (const char *filename, return 1; } } + else + { + /* Not a digit. */ + return 0; + } } else { @@ -1063,6 +1066,7 @@ search_one_database (int argc, nread = fread (procdata.original_filename, 1, SLOCATE_DB_MAGIC_LEN, procdata.fp); + slocate_seclevel = 0; if (looking_at_slocate_locatedb(procdata.dbfile, procdata.original_filename, nread, diff --git a/xargs/xargs.c b/xargs/xargs.c index b0eb260..e8d7edf 100644 --- a/xargs/xargs.c +++ b/xargs/xargs.c @@ -295,6 +295,7 @@ get_char_oct_or_hex_escape(const char *s) } else { + p = NULL; /* Silence compiler warning. */ error(1, 0, _("Invalid escape sequence %s in input delimiter specification."), s); @@ -405,7 +406,6 @@ main (int argc, char **argv) char *default_cmd = "/bin/echo"; int (*read_args) PARAMS ((void)) = read_line; void (*act_on_init_result)(void) = noop; - int env_too_big = 0; enum BC_INIT_STATUS bcstatus; program_name = argv[0]; -- 2.11.4.GIT