diff options
author | Staale Smedseng <staale.smedseng@sun.com> | 2009-08-28 17:51:31 +0200 |
---|---|---|
committer | Staale Smedseng <staale.smedseng@sun.com> | 2009-08-28 17:51:31 +0200 |
commit | 1ba25ae47caace207cda0be2b7994a1a845e6cce (patch) | |
tree | 4278d9f3353d5c86ca327f6ac2680c001e809843 /sql | |
parent | 5edd807a7ab72fc16472293fc94a7eb8e762e2b7 (diff) | |
download | mariadb-git-1ba25ae47caace207cda0be2b7994a1a845e6cce.tar.gz |
Bug #43414 Parenthesis (and other) warnings compiling MySQL
with gcc 4.3.2
This patch fixes a number of GCC warnings about variables used
before initialized. A new macro UNINIT_VAR() is introduced for
use in the variable declaration, and LINT_INIT() usage will be
gradually deprecated. (A workaround is used for g++, pending a
patch for a g++ bug.)
GCC warnings for unused results (attribute warn_unused_result)
for a number of system calls (present at least in later
Ubuntus, where the usual void cast trick doesn't work) are
also fixed.
client/mysqlmanager-pwgen.c:
A fix for warn_unused_result, adding fallback to use of
srand()/rand() if /dev/random cannot be used. Also actually
adds calls to rand() in the second branch so that it actually
creates a random password.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 19 | ||||
-rw-r--r-- | sql/ha_myisammrg.cc | 2 | ||||
-rw-r--r-- | sql/item.cc | 7 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 17 | ||||
-rw-r--r-- | sql/item_create.cc | 6 | ||||
-rw-r--r-- | sql/item_func.cc | 12 | ||||
-rw-r--r-- | sql/lock.cc | 3 | ||||
-rw-r--r-- | sql/log.cc | 3 | ||||
-rw-r--r-- | sql/opt_range.cc | 8 | ||||
-rw-r--r-- | sql/spatial.cc | 13 | ||||
-rw-r--r-- | sql/sql_acl.cc | 10 | ||||
-rw-r--r-- | sql/sql_base.cc | 6 | ||||
-rw-r--r-- | sql/sql_parse.cc | 4 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 3 | ||||
-rw-r--r-- | sql/sql_show.cc | 7 | ||||
-rw-r--r-- | sql/sql_update.cc | 4 | ||||
-rw-r--r-- | sql/sql_view.cc | 3 |
17 files changed, 44 insertions, 83 deletions
diff --git a/sql/field.cc b/sql/field.cc index 2322c5d7b9d..b61e5fd2d79 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1736,16 +1736,16 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) Pointers used when digits move from the left of the '.' to the right of the '.' (explained below) */ - const char *int_digits_tail_from; + const char *UNINIT_VAR(int_digits_tail_from); /* Number of 0 that need to be added at the left of the '.' (1E3: 3 zeros) */ - uint int_digits_added_zeros; + uint UNINIT_VAR(int_digits_added_zeros); /* Pointer used when digits move from the right of the '.' to the left of the '.' */ - const char *frac_digits_head_end; + const char *UNINIT_VAR(frac_digits_head_end); /* Number of 0 that need to be added at the right of the '.' (for 1E-3) */ - uint frac_digits_added_zeros; + uint UNINIT_VAR(frac_digits_added_zeros); char *pos,*tmp_left_pos,*tmp_right_pos; /* Pointers that are used as limits (begin and end of the field buffer) */ char *left_wall,*right_wall; @@ -1756,11 +1756,6 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) */ bool is_cuted_fields_incr=0; - LINT_INIT(int_digits_tail_from); - LINT_INIT(int_digits_added_zeros); - LINT_INIT(frac_digits_head_end); - LINT_INIT(frac_digits_added_zeros); - /* There are three steps in this function : - parse the input string @@ -8854,10 +8849,8 @@ Field *make_field(char *ptr, uint32 field_length, const char *field_name, struct st_table *table) { - uchar *bit_ptr; - uchar bit_offset; - LINT_INIT(bit_ptr); - LINT_INIT(bit_offset); + uchar *UNINIT_VAR(bit_ptr); + uchar UNINIT_VAR(bit_offset); if (field_type == FIELD_TYPE_BIT && !f_bit_as_char(pack_flag)) { bit_ptr= null_pos; diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index fef2e21d271..7983ffbc6c8 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -78,7 +78,7 @@ static void split_file_name(const char *file_name, extern "C" void myrg_print_wrong_table(const char *table_name) { - LEX_STRING db, name; + LEX_STRING db= {NULL, 0}, name; char buf[FN_REFLEN]; split_file_name(table_name, &db, &name); memcpy(buf, db.str, db.length); diff --git a/sql/item.cc b/sql/item.cc index eecb48aa16f..03d752a85d9 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1635,7 +1635,7 @@ bool agg_item_collations_for_comparison(DTCollation &c, const char *fname, bool agg_item_set_converter(DTCollation &coll, const char *fname, Item **args, uint nargs, uint flags, int item_sep) { - Item **arg, *safe_args[2]; + Item **arg, *safe_args[2]= {NULL, NULL}; /* For better error reporting: save the first and the second argument. @@ -1644,8 +1644,6 @@ bool agg_item_set_converter(DTCollation &coll, const char *fname, doesn't display each argument's characteristics. - if nargs is 1, then this error cannot happen. */ - LINT_INIT(safe_args[0]); - LINT_INIT(safe_args[1]); if (nargs >=2 && nargs <= 3) { safe_args[0]= args[0]; @@ -5122,9 +5120,8 @@ bool Item_null::send(Protocol *protocol, String *packet) bool Item::send(Protocol *protocol, String *buffer) { - bool result; + bool UNINIT_VAR(result); // Will be set if null_value == 0 enum_field_types f_type; - LINT_INIT(result); // Will be set if null_value == 0 switch ((f_type=field_type())) { default: diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index c940c4ab3c0..8c655cdc369 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -352,8 +352,7 @@ static bool convert_constant_item(THD *thd, Item_field *field_item, /* For comparison purposes allow invalid dates like 2000-01-32 */ ulong orig_sql_mode= thd->variables.sql_mode; enum_check_fields orig_count_cuted_fields= thd->count_cuted_fields; - ulonglong orig_field_val; /* original field value if valid */ - LINT_INIT(orig_field_val); + ulonglong UNINIT_VAR(orig_field_val); /* original field value if valid */ thd->variables.sql_mode= (orig_sql_mode & ~MODE_NO_ZERO_DATE) | MODE_INVALID_DATES; thd->count_cuted_fields= CHECK_FIELD_IGNORE; @@ -2453,19 +2452,13 @@ Item_func_nullif::is_null() Item *Item_func_case::find_item(String *str) { - String *first_expr_str, *tmp; - my_decimal *first_expr_dec, first_expr_dec_val; - longlong first_expr_int; - double first_expr_real; + String *UNINIT_VAR(first_expr_str), *tmp; + my_decimal *UNINIT_VAR(first_expr_dec), first_expr_dec_val; + longlong UNINIT_VAR(first_expr_int); + double UNINIT_VAR(first_expr_real); char buff[MAX_FIELD_WIDTH]; String buff_str(buff,sizeof(buff),default_charset()); - /* These will be initialized later */ - LINT_INIT(first_expr_str); - LINT_INIT(first_expr_int); - LINT_INIT(first_expr_real); - LINT_INIT(first_expr_dec); - if (first_expr_num != -1) { switch (cmp_type) diff --git a/sql/item_create.cc b/sql/item_create.cc index c897b7aef79..cbd015f300b 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -451,10 +451,9 @@ Item *create_func_cast(Item *a, Cast_target cast_type, const char *c_len, const char *c_dec, CHARSET_INFO *cs) { - Item *res; + Item *UNINIT_VAR(res); ulong len; uint dec; - LINT_INIT(res); switch (cast_type) { case ITEM_CAST_BINARY: res= new Item_func_binary(a); break; @@ -542,6 +541,9 @@ Item *create_func_cast(Item *a, Cast_target cast_type, res= new Item_char_typecast(a, len, cs ? cs : current_thd->variables.collation_connection); break; + + default: + DBUG_ASSERT(0); } return res; } diff --git a/sql/item_func.cc b/sql/item_func.cc index 6193ab285f2..3c1e2126008 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2275,9 +2275,8 @@ void Item_func_min_max::fix_length_and_dec() uint Item_func_min_max::cmp_datetimes(ulonglong *value) { - longlong min_max; + longlong UNINIT_VAR(min_max); uint min_max_idx= 0; - LINT_INIT(min_max); for (uint i=0; i < arg_count ; i++) { @@ -2345,8 +2344,7 @@ String *Item_func_min_max::val_str(String *str) } case STRING_RESULT: { - String *res; - LINT_INIT(res); + String *UNINIT_VAR(res); for (uint i=0; i < arg_count ; i++) { if (i == 0) @@ -2435,8 +2433,7 @@ longlong Item_func_min_max::val_int() my_decimal *Item_func_min_max::val_decimal(my_decimal *dec) { DBUG_ASSERT(fixed == 1); - my_decimal tmp_buf, *tmp, *res; - LINT_INIT(res); + my_decimal tmp_buf, *tmp, *UNINIT_VAR(res); if (compare_as_dates) { @@ -4974,8 +4971,7 @@ void Item_func_match::init_search(bool no_order) bool Item_func_match::fix_fields(THD *thd, Item **ref) { DBUG_ASSERT(fixed == 0); - Item *item; - LINT_INIT(item); // Safe as arg_count is > 1 + Item *UNINIT_VAR(item); // Safe as arg_count is > 1 maybe_null=1; join_key=0; diff --git a/sql/lock.cc b/sql/lock.cc index 3102497576f..97abd76b7c2 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -1216,11 +1216,10 @@ void unlock_global_read_lock(THD *thd) bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh, bool is_not_commit) { - const char *old_message; + const char *UNINIT_VAR(old_message); bool result= 0, need_exit_cond; DBUG_ENTER("wait_if_global_read_lock"); - LINT_INIT(old_message); /* Assert that we do not own LOCK_open. If we would own it, other threads could not close their tables. This would make a pretty diff --git a/sql/log.cc b/sql/log.cc index ec8f5fe820b..c042651216c 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -2635,9 +2635,10 @@ bool flush_error_log() else result= 1; #else + FILE *reopen; my_rename(log_error_file,err_renamed,MYF(0)); if (freopen(log_error_file,"a+",stdout)) - freopen(log_error_file,"a+",stderr); + reopen= freopen(log_error_file,"a+",stderr); else result= 1; #endif diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 778fc418392..fdf6cc03a44 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -3514,11 +3514,10 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree, { int idx; SEL_ARG **key,**end, **key_to_read= NULL; - ha_rows best_records; + ha_rows UNINIT_VAR(best_records); /* protected by key_to_read */ TRP_RANGE* read_plan= NULL; bool pk_is_clustered= param->table->file->primary_key_is_clustered(); DBUG_ENTER("get_key_scans_params"); - LINT_INIT(best_records); /* protected by key_to_read */ /* Note that there may be trees that have type SEL_TREE::KEY but contain no key reads at all, e.g. tree for expression "key1 is not null" where key1 @@ -5370,8 +5369,7 @@ static bool eq_tree(SEL_ARG* a,SEL_ARG *b) SEL_ARG * SEL_ARG::insert(SEL_ARG *key) { - SEL_ARG *element,**par,*last_element; - LINT_INIT(par); LINT_INIT(last_element); + SEL_ARG *element,**UNINIT_VAR(par),*UNINIT_VAR(last_element); for (element= this; element != &null_element ; ) { @@ -7918,7 +7916,9 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree) goto next_index; } else + { DBUG_ASSERT(FALSE); + } /* Check (SA2). */ if (min_max_arg_item) diff --git a/sql/spatial.cc b/sql/spatial.cc index 80506f16d0f..6e1da589527 100644 --- a/sql/spatial.cc +++ b/sql/spatial.cc @@ -935,13 +935,10 @@ int Gis_polygon::interior_ring_n(uint32 num, String *result) const int Gis_polygon::centroid_xy(double *x, double *y) const { uint32 n_linear_rings; - double res_area; - double res_cx, res_cy; + double UNINIT_VAR(res_area); + double UNINIT_VAR(res_cx), UNINIT_VAR(res_cy); const char *data= m_data; bool first_loop= 1; - LINT_INIT(res_area); - LINT_INIT(res_cx); - LINT_INIT(res_cy); if (no_data(data, 4)) return 1; @@ -1634,14 +1631,10 @@ int Gis_multi_polygon::centroid(String *result) const uint32 n_polygons; bool first_loop= 1; Gis_polygon p; - double res_area, res_cx, res_cy; + double UNINIT_VAR(res_area), UNINIT_VAR(res_cx), UNINIT_VAR(res_cy); double cur_area, cur_cx, cur_cy; const char *data= m_data; - LINT_INIT(res_area); - LINT_INIT(res_cx); - LINT_INIT(res_cy); - if (no_data(data, 4)) return 1; n_polygons= uint4korr(data); diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index ab4e518d5dd..ea17a4227ef 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -5067,17 +5067,13 @@ static int handle_grant_struct(uint struct_no, bool drop, uint elements; const char *user; const char *host; - ACL_USER *acl_user; - ACL_DB *acl_db; - GRANT_NAME *grant_name; + ACL_USER *UNINIT_VAR(acl_user); + ACL_DB *UNINIT_VAR(acl_db); + GRANT_NAME *UNINIT_VAR(grant_name); DBUG_ENTER("handle_grant_struct"); DBUG_PRINT("info",("scan struct: %u search: '%s'@'%s'", struct_no, user_from->user.str, user_from->host.str)); - LINT_INIT(acl_user); - LINT_INIT(acl_db); - LINT_INIT(grant_name); - safe_mutex_assert_owner(&acl_cache->lock); /* Get the number of elements in the in-memory structure. */ diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 6a99d5d1541..db4ab29d6de 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -706,7 +706,7 @@ void close_temporary_tables(THD *thd) return; } - TABLE *next, + TABLE *UNINIT_VAR(next), *prev_table /* prev link is not maintained in TABLE's double-linked list */; bool was_quote_show= true; /* to assume thd->options has OPTION_QUOTE_SHOW_CREATE */ // Better add "if exists", in case a RESET MASTER has been done @@ -716,7 +716,6 @@ void close_temporary_tables(THD *thd) memcpy(buf, stub, stub_len); String s_query= String(buf, sizeof(buf), system_charset_info); bool found_user_tables= false; - LINT_INIT(next); /* insertion sort of temp tables by pseudo_thread_id to build ordered list @@ -4142,8 +4141,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter, (and not an item that happens to have a name). */ bool is_ref_by_name= 0; - uint unaliased_counter; - LINT_INIT(unaliased_counter); // Dependent on found_unaliased + uint UNINIT_VAR(unaliased_counter); // Dependent on found_unaliased *resolution= NOT_RESOLVED; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 45f70964f50..65b2a9d60b0 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1325,7 +1325,7 @@ pthread_handler_t handle_bootstrap(void *arg) thd->init_for_queries(); while (fgets(buff, thd->net.max_packet, file)) { - char *query; + char *query, *res; ulong length= (ulong) strlen(buff); while (buff[length-1] != '\n' && !feof(file)) { @@ -1340,7 +1340,7 @@ pthread_handler_t handle_bootstrap(void *arg) break; } buff= (char*) thd->net.buff; - fgets(buff + length, thd->net.max_packet - length, file); + res= fgets(buff + length, thd->net.max_packet - length, file); length+= (ulong) strlen(buff + length); } if (thd->is_fatal_error) diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index d14f14b526e..06f77f9689c 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2072,10 +2072,9 @@ void mysql_sql_stmt_prepare(THD *thd) LEX_STRING *name= &lex->prepared_stmt_name; Prepared_statement *stmt; const char *query; - uint query_len; + uint UNINIT_VAR(query_len); DBUG_ENTER("mysql_sql_stmt_prepare"); DBUG_ASSERT(thd->protocol == &thd->protocol_simple); - LINT_INIT(query_len); if ((stmt= (Prepared_statement*) thd->stmt_map.find_by_name(name))) { diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 9eac750c22e..13045280c5f 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2172,8 +2172,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) ST_SCHEMA_TABLE *schema_table= tables->schema_table; SELECT_LEX sel; INDEX_FIELD_VALUES idx_field_vals; - char path[FN_REFLEN], *end, *base_name, *orig_base_name, *file_name; - uint len; + char path[FN_REFLEN], *UNINIT_VAR(end), *base_name, *orig_base_name, *file_name; + uint UNINIT_VAR(len); bool with_i_schema; enum enum_schema_tables schema_table_idx; List<char> bases; @@ -2190,9 +2190,6 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) #endif DBUG_ENTER("get_all_tables"); - LINT_INIT(end); - LINT_INIT(len); - lex->view_prepare_mode= TRUE; lex->reset_n_backup_query_tables_list(&query_tables_list_backup); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index c18c34fc1d1..06d1bcaa8fb 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -125,7 +125,7 @@ int mysql_update(THD *thd, uint want_privilege; #endif uint table_count= 0; - query_id_t query_id=thd->query_id, timestamp_query_id; + query_id_t query_id=thd->query_id, UNINIT_VAR(timestamp_query_id); ha_rows updated, found; key_map old_used_keys; TABLE *table; @@ -137,8 +137,6 @@ int mysql_update(THD *thd, THD::killed_state killed_status= THD::NOT_KILLED; DBUG_ENTER("mysql_update"); - LINT_INIT(timestamp_query_id); - for ( ; ; ) { if (open_tables(thd, &table_list, &table_count, 0)) diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 96077aeeb12..8cf25e9d88c 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -955,7 +955,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, TABLE_LIST *top_view= table->top_table(); int res; bool result, view_is_mergeable; - TABLE_LIST *view_main_select_tables; + TABLE_LIST *UNINIT_VAR(view_main_select_tables); DBUG_ENTER("mysql_make_view"); DBUG_PRINT("info", ("table: 0x%lx (%s)", (ulong) table, table->table_name)); @@ -1218,7 +1218,6 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, view_is_mergeable= (table->algorithm != VIEW_ALGORITHM_TMPTABLE && lex->can_be_merged()); - LINT_INIT(view_main_select_tables); if (view_is_mergeable) { |