Bug #53445 Build with -Wall and fix warnings that it generates

Add -Wall to gcc/g++
Fix most warnings reported in dbg and opt mode.
This commit is contained in:
Tor Didriksen 2010-05-26 16:12:23 +02:00
parent 33e9d05c08
commit d8536dfbdd
22 changed files with 83 additions and 75 deletions

View File

@ -95,10 +95,9 @@ static char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', '$',
char *
fn_tilde_expand(const char *txt)
{
struct passwd pwres, *pass;
struct passwd *pass;
char *temp;
size_t len = 0;
char pwbuf[1024];
if (txt[0] != '~')
return (strdup(txt));

View File

@ -54,6 +54,15 @@ IF(NOT SYSTEM_TYPE)
ENDIF()
# Always enable -Wall for gnu C/C++
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
# MySQL "canonical" GCC flags. At least -fno-rtti flag affects
# ABI and cannot be simply removed.

View File

@ -686,7 +686,7 @@ static ha_checksum checksum_format_specifier(const char* msg)
case 'u':
case 'x':
case 's':
chksum= my_checksum(chksum, start, (uint) (p + 1 - start));
chksum= my_checksum(chksum, (uchar*) start, (uint) (p + 1 - start));
start= 0; /* Not in format specifier anymore */
break;

View File

@ -269,7 +269,7 @@ int main(int argc,char *argv[])
HA_ERRORS *ha_err_ptr;
for (code=1 ; code < sys_nerr ; code++)
{
if (sys_errlist[code][0])
if (sys_errlist[code] && sys_errlist[code][0])
{ /* Skip if no error-text */
printf("%3d = %s\n",code,sys_errlist[code]);
}

View File

@ -60,7 +60,7 @@ static int __cxa_pure_virtual() __attribute__((noinline, used));
static int __cxa_pure_virtual()
{
// oops, pure virtual called!
assert("Pure virtual method called." == "Aborted");
assert(!"Pure virtual method called. Aborted");
return 0;
}

View File

@ -1070,6 +1070,17 @@ typedef long long my_ptrdiff_t;
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
#ifdef __cplusplus
template <size_t sz> struct Aligned_char_array
{
union {
void *v; // Ensures alignment.
char arr[sz]; // The actual buffer.
} u;
void* arr() { return &u.arr[0]; }
};
#endif /* __cplusplus */
/*
Custom version of standard offsetof() macro which can be used to get
offsets of members in class for non-POD types (according to the current

View File

@ -329,10 +329,9 @@ static void _lf_pinbox_real_free(LF_PINS *pins)
{
int npins, alloca_size;
void *list, **addr;
void *first, *last= NULL;
void *first= NULL, *last= NULL;
LF_PINBOX *pinbox= pins->pinbox;
LINT_INIT(first);
npins= pinbox->pins_in_array+1;
#ifdef HAVE_ALLOCA

View File

@ -4181,10 +4181,9 @@ int ha_partition::index_read_map(uchar *buf, const uchar *key,
int ha_partition::common_index_read(uchar *buf, bool have_start_key)
{
int error;
uint key_len;
uint UNINIT_VAR(key_len); /* used if have_start_key==TRUE */
bool reverse_order= FALSE;
DBUG_ENTER("ha_partition::common_index_read");
LINT_INIT(key_len); /* used if have_start_key==TRUE */
DBUG_PRINT("info", ("m_ordered %u m_ordered_scan_ong %u have_start_key %u",
m_ordered, m_ordered_scan_ongoing, have_start_key));

View File

@ -5343,11 +5343,11 @@ inline void kill_broken_server()
void handle_connections_sockets()
{
my_socket sock,new_sock;
my_socket UNINIT_VAR(sock), UNINIT_VAR(new_sock);
uint error_count=0;
THD *thd;
struct sockaddr_storage cAddr;
int ip_flags=0,socket_flags=0,flags,retval;
int ip_flags=0,socket_flags=0,flags=0,retval;
st_vio *vio_tmp;
#ifdef HAVE_POLL
int socket_count= 0;
@ -5359,8 +5359,6 @@ void handle_connections_sockets()
DBUG_ENTER("handle_connections_sockets");
LINT_INIT(new_sock);
#ifndef HAVE_POLL
FD_ZERO(&clientFDs);
#endif

View File

@ -701,12 +701,11 @@ bool partition_info::check_range_constants(THD *thd)
if (column_list)
{
part_column_list_val *loc_range_col_array;
part_column_list_val *current_largest_col_val;
part_column_list_val *UNINIT_VAR(current_largest_col_val);
uint num_column_values= part_field_list.elements;
uint size_entries= sizeof(part_column_list_val) * num_column_values;
range_col_array= (part_column_list_val*)sql_calloc(num_parts *
size_entries);
LINT_INIT(current_largest_col_val);
if (unlikely(range_col_array == NULL))
{
mem_alloc_error(num_parts * size_entries);
@ -739,12 +738,10 @@ bool partition_info::check_range_constants(THD *thd)
}
else
{
longlong current_largest;
longlong UNINIT_VAR(current_largest);
longlong part_range_value;
bool signed_flag= !part_expr->unsigned_flag;
LINT_INIT(current_largest);
part_result_type= INT_RESULT;
range_int_array= (longlong*)sql_alloc(num_parts * sizeof(longlong));
if (unlikely(range_int_array == NULL))
@ -894,7 +891,8 @@ bool partition_info::check_list_constants(THD *thd)
part_elem_value *list_value;
bool result= TRUE;
longlong type_add, calc_value;
void *curr_value, *prev_value;
void *curr_value;
void *UNINIT_VAR(prev_value);
partition_element* part_def;
bool found_null= FALSE;
int (*compare_func)(const void *, const void*);
@ -1009,7 +1007,6 @@ bool partition_info::check_list_constants(THD *thd)
compare_func);
i= 0;
LINT_INIT(prev_value);
do
{
DBUG_ASSERT(i < num_list_values);

View File

@ -89,21 +89,24 @@ int get_user_var_str(const char *name, char *value,
int delegates_init()
{
static unsigned long trans_mem[sizeof(Trans_delegate) / sizeof(unsigned long) + 1];
static unsigned long storage_mem[sizeof(Binlog_storage_delegate) / sizeof(unsigned long) + 1];
static Aligned_char_array<sizeof(Trans_delegate)> trans_mem;
static Aligned_char_array<sizeof(Binlog_storage_delegate)> storage_mem;
#ifdef HAVE_REPLICATION
static unsigned long transmit_mem[sizeof(Binlog_transmit_delegate) / sizeof(unsigned long) + 1];
static unsigned long relay_io_mem[sizeof(Binlog_relay_IO_delegate)/ sizeof(unsigned long) + 1];
static Aligned_char_array<sizeof(Binlog_transmit_delegate)> transmit_mem;
static Aligned_char_array<sizeof(Binlog_relay_IO_delegate)> relay_io_mem;
#endif
if (!(transaction_delegate= new (trans_mem) Trans_delegate)
if (!(transaction_delegate= new (trans_mem.arr()) Trans_delegate)
|| (!transaction_delegate->is_inited())
|| !(binlog_storage_delegate= new (storage_mem) Binlog_storage_delegate)
|| !(binlog_storage_delegate=
new (storage_mem.arr()) Binlog_storage_delegate)
|| (!binlog_storage_delegate->is_inited())
#ifdef HAVE_REPLICATION
|| !(binlog_transmit_delegate= new (transmit_mem) Binlog_transmit_delegate)
|| !(binlog_transmit_delegate=
new (transmit_mem.arr()) Binlog_transmit_delegate)
|| (!binlog_transmit_delegate->is_inited())
|| !(binlog_relay_io_delegate= new (relay_io_mem) Binlog_relay_IO_delegate)
|| !(binlog_relay_io_delegate=
new (relay_io_mem.arr()) Binlog_relay_IO_delegate)
|| (!binlog_relay_io_delegate->is_inited())
#endif /* HAVE_REPLICATION */
)

View File

@ -128,6 +128,16 @@ Geometry::Class_info *Geometry::find_class(const char *name, uint32 len)
}
Geometry *Geometry::create_by_typeid(Geometry_buffer *buffer, int type_id)
{
Class_info *ci;
if (!(ci= find_class((int) type_id)))
return NULL;
(*ci->m_create_func)(buffer->buf.arr());
return my_reinterpret_cast(Geometry *)(buffer->buf.arr());
}
Geometry *Geometry::construct(Geometry_buffer *buffer,
const char *data, uint32 data_len)
{

View File

@ -267,14 +267,7 @@ public:
virtual int geometry_n(uint32 num, String *result) const { return -1; }
public:
static Geometry *create_by_typeid(Geometry_buffer *buffer, int type_id)
{
Class_info *ci;
if (!(ci= find_class((int) type_id)))
return NULL;
(*ci->m_create_func)((void *)buffer);
return my_reinterpret_cast(Geometry *)(buffer);
}
static Geometry *create_by_typeid(Geometry_buffer *buffer, int type_id);
static Geometry *construct(Geometry_buffer *buffer,
const char *data, uint32 data_len);
@ -532,10 +525,9 @@ public:
const Class_info *get_class_info() const;
};
const int geometry_buffer_size= sizeof(Gis_point);
struct Geometry_buffer
{
void *arr[(geometry_buffer_size - 1)/sizeof(void *) + 1];
Aligned_char_array<sizeof(Gis_point)> buf;
};
#endif /*HAVE_SPATAIAL*/

View File

@ -4584,7 +4584,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
partition_info *tab_part_info= table->part_info;
partition_info *alt_part_info= thd->work_part_info;
uint flags= 0;
bool is_last_partition_reorged;
bool is_last_partition_reorged= FALSE;
part_elem_value *tab_max_elem_val= NULL;
part_elem_value *alt_max_elem_val= NULL;
longlong tab_max_range= 0, alt_max_range= 0;

View File

@ -1899,8 +1899,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
bool dont_log_query)
{
TABLE_LIST *table;
char path[FN_REFLEN + 1], *alias;
uint path_length;
char path[FN_REFLEN + 1], *alias= NULL;
uint path_length= 0;
String wrong_tables;
int error= 0;
int non_temp_tables_count= 0;
@ -1909,9 +1909,6 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
String built_tmp_query;
DBUG_ENTER("mysql_rm_table_part2");
LINT_INIT(alias);
LINT_INIT(path_length);
if (thd->is_current_stmt_binlog_format_row() && !dont_log_query)
{
built_query.set_charset(system_charset_info);

View File

@ -2723,8 +2723,8 @@ static Sys_var_mybool Sys_log_slow(
static bool fix_log_state(sys_var *self, THD *thd, enum_var_type type)
{
bool res;
my_bool *newvalptr, newval, oldval;
uint log_type;
my_bool *UNINIT_VAR(newvalptr), newval, UNINIT_VAR(oldval);
uint UNINIT_VAR(log_type);
if (self == &Sys_general_log || self == &Sys_log)
{

View File

@ -3923,6 +3923,7 @@ os_aio_simulated_handle(
ulint n;
ulint i;
consecutive_ios[0]= NULL;
segment = os_aio_get_array_and_local_segment(&array, global_segment);
restart:

View File

@ -38,7 +38,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
MI_CREATE_INFO *ci,uint flags)
{
register uint i,j;
File UNINIT_VAR(dfile),file;
File UNINIT_VAR(dfile), UNINIT_VAR(file);
int errpos,save_errno, create_mode= O_RDWR | O_TRUNC;
myf create_flag;
uint fields,length,max_key_length,packed,pointer,real_length_diff,
@ -73,8 +73,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
{
DBUG_RETURN(my_errno=HA_WRONG_CREATE_OPTION);
}
LINT_INIT(dfile);
LINT_INIT(file);
errpos=0;
options=0;
bzero((uchar*) &share,sizeof(share));

View File

@ -143,7 +143,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
(uchar*) myisam_file_magic, 4))
{
DBUG_PRINT("error",("Wrong header in %s",name_buff));
DBUG_DUMP("error_dump",(char*) share->state.header.file_version,
DBUG_DUMP("error_dump", share->state.header.file_version,
head_length);
my_errno=HA_ERR_NOT_A_TABLE;
goto err;

View File

@ -49,7 +49,7 @@ uchar *_mi_fetch_keypage(register MI_INFO *info, MI_KEYDEF *keyinfo,
{
DBUG_PRINT("error",("page %lu had wrong page length: %u",
(ulong) page, page_size));
DBUG_DUMP("page", (char*) tmp, keyinfo->block_length);
DBUG_DUMP("page", tmp, keyinfo->block_length);
info->last_keypage = HA_OFFSET_ERROR;
mi_print_error(info->s, HA_ERR_CRASHED);
my_errno = HA_ERR_CRASHED;

View File

@ -819,7 +819,7 @@ uint _mi_get_pack_key(register MI_KEYDEF *keyinfo, uint nod_flag,
DBUG_PRINT("error",
("Found too long null packed key: %u of %u at 0x%lx",
length, keyseg->length, (long) *page_pos));
DBUG_DUMP("key",(char*) *page_pos,16);
DBUG_DUMP("key",(uchar*) *page_pos,16);
mi_print_error(keyinfo->share, HA_ERR_CRASHED);
my_errno=HA_ERR_CRASHED;
return 0;
@ -876,7 +876,7 @@ uint _mi_get_pack_key(register MI_KEYDEF *keyinfo, uint nod_flag,
{
DBUG_PRINT("error",("Found too long packed key: %u of %u at 0x%lx",
length, keyseg->length, (long) *page_pos));
DBUG_DUMP("key",(char*) *page_pos,16);
DBUG_DUMP("key",(uchar*) *page_pos,16);
mi_print_error(keyinfo->share, HA_ERR_CRASHED);
my_errno=HA_ERR_CRASHED;
return 0; /* Error */
@ -948,7 +948,7 @@ uint _mi_get_binary_pack_key(register MI_KEYDEF *keyinfo, uint nod_flag,
DBUG_PRINT("error",
("Found too long binary packed key: %u of %u at 0x%lx",
length, keyinfo->maxlength, (long) *page_pos));
DBUG_DUMP("key",(char*) *page_pos,16);
DBUG_DUMP("key",(uchar*) *page_pos,16);
mi_print_error(keyinfo->share, HA_ERR_CRASHED);
my_errno=HA_ERR_CRASHED;
DBUG_RETURN(0); /* Wrong key */

View File

@ -1961,12 +1961,10 @@ my_strnncoll_utf32(CHARSET_INFO *cs,
const uchar *t, size_t tlen,
my_bool t_is_prefix)
{
my_wc_t s_wc,t_wc;
my_wc_t UNINIT_VAR(s_wc),UNINIT_VAR(t_wc);
const uchar *se= s + slen;
const uchar *te= t + tlen;
MY_UNICASE_INFO **uni_plane= cs->caseinfo;
LINT_INIT(s_wc);
LINT_INIT(t_wc);
while (s < se && t < te)
{
@ -2028,11 +2026,9 @@ my_strnncollsp_utf32(CHARSET_INFO *cs,
my_bool diff_if_only_endspace_difference)
{
int res;
my_wc_t s_wc, t_wc;
my_wc_t UNINIT_VAR(s_wc), UNINIT_VAR(t_wc);
const uchar *se= s + slen, *te= t + tlen;
MY_UNICASE_INFO **uni_plane= cs->caseinfo;
LINT_INIT(s_wc);
LINT_INIT(t_wc);
DBUG_ASSERT((slen % 4) == 0);
DBUG_ASSERT((tlen % 4) == 0);
@ -2498,11 +2494,9 @@ my_strnncoll_utf32_bin(CHARSET_INFO *cs,
const uchar *t, size_t tlen,
my_bool t_is_prefix)
{
my_wc_t s_wc, t_wc;
my_wc_t UNINIT_VAR(s_wc), UNINIT_VAR(t_wc);
const uchar *se= s + slen;
const uchar *te= t + tlen;
LINT_INIT(s_wc);
LINT_INIT(t_wc);
while (s < se && t < te)
{
@ -2624,7 +2618,7 @@ my_like_range_utf32(CHARSET_INFO *cs,
{
my_wc_t wc;
int res;
if ((res= my_utf32_uni(cs, &wc, ptr, end)) < 0)
if ((res= my_utf32_uni(cs, &wc, (uchar*) ptr, (uchar*) end)) < 0)
{
my_fill_utf32(cs, min_str, min_end - min_str, cs->min_sort_char);
my_fill_utf32(cs, max_str, min_end - min_str, cs->max_sort_char);
@ -2635,15 +2629,15 @@ my_like_range_utf32(CHARSET_INFO *cs,
if (wc == (my_wc_t) escape)
{
ptr+= 4; /* Skip escape */
if ((res= my_utf32_uni(cs, &wc, ptr, end)) < 0)
if ((res= my_utf32_uni(cs, &wc, (uchar*) ptr, (uchar*) end)) < 0)
{
my_fill_utf32(cs, min_str, min_end - min_str, cs->min_sort_char);
my_fill_utf32(cs, max_str, max_end - min_str, cs->max_sort_char);
/* min_length and max_length are not important */
return TRUE;
}
if (my_uni_utf32(cs, wc, min_str, min_end) != 4 ||
my_uni_utf32(cs, wc, max_str, max_end) != 4)
if (my_uni_utf32(cs, wc, (uchar*) min_str, (uchar*) min_end) != 4 ||
my_uni_utf32(cs, wc, (uchar*) max_str, (uchar*) max_end) != 4)
goto pad_set_lengths;
*min_str++= 4;
*max_str++= 4;
@ -2652,8 +2646,8 @@ my_like_range_utf32(CHARSET_INFO *cs,
if (wc == (my_wc_t) w_one)
{
if (my_uni_utf32(cs, cs->min_sort_char, min_str, min_end) != 4 ||
my_uni_utf32(cs, cs->max_sort_char, max_str, max_end) != 4)
if (my_uni_utf32(cs, cs->min_sort_char, (uchar*) min_str, (uchar*) min_end) != 4 ||
my_uni_utf32(cs, cs->max_sort_char, (uchar*) max_str, (uchar*) max_end) != 4)
goto pad_set_lengths;
min_str+= 4;
max_str+= 4;
@ -2675,8 +2669,8 @@ my_like_range_utf32(CHARSET_INFO *cs,
}
/* Normal character */
if (my_uni_utf32(cs, wc, min_str, min_end) != 4 ||
my_uni_utf32(cs, wc, max_str, max_end) != 4)
if (my_uni_utf32(cs, wc, (uchar*) min_str, (uchar*) min_end) != 4 ||
my_uni_utf32(cs, wc, (uchar*) max_str, (uchar*) max_end) != 4)
goto pad_set_lengths;
min_str+= 4;
max_str+= 4;
@ -2704,7 +2698,7 @@ my_scan_utf32(CHARSET_INFO *cs,
for ( ; str < end; )
{
my_wc_t wc;
int res= my_utf32_uni(cs, &wc, str, end);
int res= my_utf32_uni(cs, &wc, (uchar*) str, (uchar*) end);
if (res < 0 || wc != ' ')
break;
str+= res;
@ -3008,7 +3002,7 @@ static int my_strnncoll_ucs2(CHARSET_INFO *cs,
my_bool t_is_prefix)
{
int s_res,t_res;
my_wc_t UNINIT_VAR(s_wc),t_wc;
my_wc_t UNINIT_VAR(s_wc),UNINIT_VAR(t_wc);
const uchar *se=s+slen;
const uchar *te=t+tlen;
MY_UNICASE_INFO **uni_plane= cs->caseinfo;
@ -3195,7 +3189,7 @@ int my_strnncoll_ucs2_bin(CHARSET_INFO *cs,
my_bool t_is_prefix)
{
int s_res,t_res;
my_wc_t UNINIT_VAR(s_wc),t_wc;
my_wc_t UNINIT_VAR(s_wc),UNINIT_VAR(t_wc);
const uchar *se=s+slen;
const uchar *te=t+tlen;