Commit 840f1310 authored by Alexander Barkov's avatar Alexander Barkov

Fixing a few -Wconversion warnings

parent b652430f
......@@ -212,7 +212,8 @@ class Value_source
CHARSET_INFO *cs, const char *str, size_t length,
my_decimal *buf)
{
m_error= str2my_decimal(mask, str, length, cs,
DBUG_ASSERT(length < UINT_MAX32);
m_error= str2my_decimal(mask, str, (uint) length, cs,
buf, (const char **) &m_end_of_num);
// E_DEC_TRUNCATED means a very minor truncation: '1e-100' -> 0
m_edom= m_error && m_error != E_DEC_TRUNCATED;
......@@ -661,7 +662,10 @@ class Field: public Value_source
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
static void *operator new(size_t size) throw ()
{ return thd_alloc(current_thd, size); }
{
DBUG_ASSERT(size < UINT_MAX32);
return thd_alloc(current_thd, (uint) size);
}
static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root)
{ DBUG_ASSERT(0); }
......@@ -815,11 +819,20 @@ class Field: public Value_source
int store(const char *to, uint length, CHARSET_INFO *cs,
enum_check_fields check_level);
int store(const LEX_STRING *ls, CHARSET_INFO *cs)
{ return store(ls->str, ls->length, cs); }
{
DBUG_ASSERT(ls->length < UINT_MAX32);
return store(ls->str, (uint) ls->length, cs);
}
int store(const LEX_CSTRING *ls, CHARSET_INFO *cs)
{ return store(ls->str, ls->length, cs); }
{
DBUG_ASSERT(ls->length < UINT_MAX32);
return store(ls->str, (uint) ls->length, cs);
}
int store(const LEX_CSTRING &ls, CHARSET_INFO *cs)
{ return store(ls.str, ls.length, cs); }
{
DBUG_ASSERT(ls.length < UINT_MAX32);
return store(ls.str, (uint) ls.length, cs);
}
virtual double val_real(void)=0;
virtual longlong val_int(void)=0;
virtual bool val_bool(void)= 0;
......@@ -2500,7 +2513,7 @@ class Field_timestamp_hires :public Field_timestamp_with_dec {
class Field_timestampf :public Field_timestamp_with_dec {
int do_save_field_metadata(uchar *metadata_ptr)
{
*metadata_ptr= decimals();
*metadata_ptr= (uchar) decimals();
return 1;
}
public:
......@@ -2768,7 +2781,7 @@ class Field_timef :public Field_time_with_dec {
void store_TIME(MYSQL_TIME *ltime);
int do_save_field_metadata(uchar *metadata_ptr)
{
*metadata_ptr= decimals();
*metadata_ptr= (uchar) decimals();
return 1;
}
public:
......@@ -2930,7 +2943,7 @@ class Field_datetimef :public Field_datetime_with_dec {
bool get_TIME(MYSQL_TIME *ltime, const uchar *pos, ulonglong fuzzydate) const;
int do_save_field_metadata(uchar *metadata_ptr)
{
*metadata_ptr= decimals();
*metadata_ptr= (uchar) decimals();
return 1;
}
public:
......@@ -3442,7 +3455,7 @@ class Field_geom :public Field_blob {
enum storage_type { GEOM_STORAGE_WKB= 0, GEOM_STORAGE_BINARY= 1};
enum storage_type storage;
Field_geom(uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg,
Field_geom(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg,
TABLE_SHARE *share, uint blob_pack_length,
enum geometry_type geom_type_arg, uint field_srid)
......@@ -3848,7 +3861,8 @@ class Column_definition: public Sql_alloc,
*pos ; pos++, len++)
{
size_t length= charset->cset->numchars(charset, *pos, *pos + *len);
*tot_length+= length;
DBUG_ASSERT(length < UINT_MAX32);
*tot_length+= (uint) length;
set_if_bigger(*max_length, (uint32)length);
}
}
......
......@@ -3549,7 +3549,7 @@ class Item_string :public Item_basic_constant
{
str_value.set_or_copy_aligned(str, length, cs);
fix_from_value(dv, Metadata(&str_value));
set_name(thd, name_par, safe_strlen(name_par), system_charset_info);
set_name(thd, name_par, (uint) safe_strlen(name_par), system_charset_info);
}
Item_string(THD *thd, const char *name_par, const char *str, uint length,
CHARSET_INFO *cs, Derivation dv, uint repertoire):
......@@ -3557,7 +3557,7 @@ class Item_string :public Item_basic_constant
{
str_value.set_or_copy_aligned(str, length, cs);
fix_from_value(dv, Metadata(&str_value, repertoire));
set_name(thd, name_par, safe_strlen(name_par), system_charset_info);
set_name(thd, name_par, (uint) safe_strlen(name_par), system_charset_info);
}
void print_value(String *to) const
{
......@@ -3679,7 +3679,7 @@ class Item_string_sys :public Item_string
Item_string(thd, str, length, system_charset_info)
{ }
Item_string_sys(THD *thd, const char *str):
Item_string(thd, str, strlen(str), system_charset_info)
Item_string(thd, str, (uint) strlen(str), system_charset_info)
{ }
};
......@@ -3692,7 +3692,7 @@ class Item_string_ascii :public Item_string
DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII)
{ }
Item_string_ascii(THD *thd, const char *str):
Item_string(thd, str, strlen(str), &my_charset_latin1,
Item_string(thd, str, (uint) strlen(str), &my_charset_latin1,
DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII)
{ }
};
......@@ -3769,7 +3769,8 @@ class Item_blob :public Item_partition_func_safe_string
{
public:
Item_blob(THD *thd, const char *name_arg, uint length):
Item_partition_func_safe_string(thd, name_arg, safe_strlen(name_arg), &my_charset_bin)
Item_partition_func_safe_string(thd, name_arg, (uint) safe_strlen(name_arg),
&my_charset_bin)
{ max_length= length; }
enum Type type() const { return TYPE_HOLDER; }
const Type_handler *type_handler() const
......
......@@ -928,7 +928,8 @@ class Item_decimal_typecast :public Item_func
{
my_decimal decimal_value;
public:
Item_decimal_typecast(THD *thd, Item *a, int len, int dec): Item_func(thd, a)
Item_decimal_typecast(THD *thd, Item *a, uint len, uint dec)
:Item_func(thd, a)
{
decimals= (uint8) dec;
collation.set_numeric();
......@@ -956,7 +957,7 @@ class Item_decimal_typecast :public Item_func
class Item_double_typecast :public Item_real_func
{
public:
Item_double_typecast(THD *thd, Item *a, int len, int dec):
Item_double_typecast(THD *thd, Item *a, uint len, uint dec):
Item_real_func(thd, a)
{
decimals= (uint8) dec;
......@@ -2398,7 +2399,10 @@ class Item_user_var_as_out_param :public Item
public:
Item_user_var_as_out_param(THD *thd, const LEX_CSTRING *a)
:Item(thd), name(*a)
{ set_name(thd, a->str, a->length, system_charset_info); }
{
DBUG_ASSERT(a->length < UINT_MAX32);
set_name(thd, a->str, (uint) a->length, system_charset_info);
}
/* We should return something different from FIELD_ITEM here */
enum Type type() const { return STRING_ITEM;}
double val_real();
......
......@@ -825,7 +825,7 @@ class Item_func_user :public Item_func_sysconst
bool fix_fields(THD *thd, Item **ref);
void fix_length_and_dec()
{
max_length= (username_char_length +
max_length= (uint32) (username_char_length +
HOSTNAME_LENGTH + 1) * SYSTEM_CHARSET_MBMAXLEN;
}
const char *func_name() const { return "user"; }
......@@ -867,7 +867,7 @@ class Item_func_current_role :public Item_func_sysconst
Item_func_sysconst(thd), context(context_arg) {}
bool fix_fields(THD *thd, Item **ref);
void fix_length_and_dec()
{ max_length= username_char_length * SYSTEM_CHARSET_MBMAXLEN; }
{ max_length= (uint32) username_char_length * SYSTEM_CHARSET_MBMAXLEN; }
int save_in_field(Field *field, bool no_conversions)
{ return save_str_value_in_field(field, &str_value); }
const char *func_name() const { return "current_role"; }
......
......@@ -837,7 +837,10 @@ class ErrConvString : public ErrConv
ErrConvString(const String *s)
: ErrConv(), str(s->ptr()), len(s->length()), cs(s->charset()) {}
const char *ptr() const
{ return err_conv(err_buffer, sizeof(err_buffer), str, len, cs); }
{
DBUG_ASSERT(len < UINT_MAX32);
return err_conv(err_buffer, (uint) sizeof(err_buffer), str, (uint) len, cs);
}
};
class ErrConvInteger : public ErrConv
......
......@@ -3443,9 +3443,13 @@ struct LEX: public Query_tables_list
Item_param *add_placeholder(THD *thd, const LEX_CSTRING *name,
uint pos_in_query, uint len_in_query);
Item_param *add_placeholder(THD *thd, const LEX_CSTRING *name,
const char *pos, const char *end)
const char *start, const char *end)
{
return add_placeholder(thd, name, pos - substatement_query(thd), end - pos);
size_t pos= start - substatement_query(thd);
size_t len= end - start;
DBUG_ASSERT(pos < UINT_MAX32);
DBUG_ASSERT(len < UINT_MAX32);
return add_placeholder(thd, name, (uint) pos, (uint) len);
}
/* Integer range FOR LOOP methods */
......
......@@ -32,11 +32,13 @@ class Sql_alloc
public:
static void *operator new(size_t size) throw ()
{
return thd_alloc(thd_get_current_thd(), size);
DBUG_ASSERT(size < UINT_MAX32);
return thd_alloc(thd_get_current_thd(), (uint) size);
}
static void *operator new[](size_t size) throw ()
{
return thd_alloc(thd_get_current_thd(), size);
DBUG_ASSERT(size < UINT_MAX32);
return thd_alloc(thd_get_current_thd(), (uint) size);
}
static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
......
......@@ -469,9 +469,21 @@ class String
}
bool append(const String &s);
bool append(const char *s);
bool append(const LEX_STRING *ls) { return append(ls->str, ls->length); }
bool append(const LEX_CSTRING *ls) { return append(ls->str, ls->length); }
bool append(const LEX_CSTRING &ls) { return append(ls.str, ls.length); }
bool append(const LEX_STRING *ls)
{
DBUG_ASSERT(ls->length < UINT_MAX32);
return append(ls->str, (uint32) ls->length);
}
bool append(const LEX_CSTRING *ls)
{
DBUG_ASSERT(ls->length < UINT_MAX32);
return append(ls->str, (uint32) ls->length);
}
bool append(const LEX_CSTRING &ls)
{
DBUG_ASSERT(ls.length < UINT_MAX32);
return append(ls.str, (uint32) ls.length);
}
bool append(const char *s, uint32 arg_length);
bool append(const char *s, uint32 arg_length, CHARSET_INFO *cs);
bool append_ulonglong(ulonglong val);
......@@ -563,7 +575,8 @@ class String
}
void q_append(const LEX_CSTRING *ls)
{
q_append(ls->str, ls->length);
DBUG_ASSERT(ls->length < UINT_MAX32);
q_append(ls->str, (uint32) ls->length);
}
void write_at_position(int position, uint32 value)
......@@ -643,7 +656,9 @@ class String
}
bool append_for_single_quote(const char *st)
{
return append_for_single_quote(st, strlen(st));
size_t len= strlen(st);
DBUG_ASSERT(len < UINT_MAX32);
return append_for_single_quote(st, (uint32) len);
}
/* Swap two string objects. Efficient way to exchange data without memcpy. */
......@@ -687,10 +702,11 @@ class String
}
void q_net_store_data(const uchar *from, size_t length)
{
DBUG_ASSERT(length < UINT_MAX32);
DBUG_ASSERT(Alloced_length >= (str_length + length +
net_length_size(length)));
q_net_store_length(length);
q_append((const char *)from, length);
q_append((const char *)from, (uint32) length);
}
};
......
......@@ -106,7 +106,7 @@ inline void datetime_to_date(MYSQL_TIME *ltime)
DBUG_ASSERT(ltime->time_type == MYSQL_TIMESTAMP_DATE ||
ltime->time_type == MYSQL_TIMESTAMP_DATETIME);
DBUG_ASSERT(ltime->neg == 0);
ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
ltime->second_part= ltime->hour= ltime->minute= ltime->second= 0;
ltime->time_type= MYSQL_TIMESTAMP_DATE;
}
inline void date_to_datetime(MYSQL_TIME *ltime)
......
......@@ -157,7 +157,7 @@ void Type_std_attributes::count_decimal_length(Item **item, uint nitems)
}
int precision= MY_MIN(max_int_part + decimals, DECIMAL_MAX_PRECISION);
fix_char_length(my_decimal_precision_to_length_no_truncation(precision,
decimals,
(uint8) decimals,
unsigned_flag));
}
......@@ -990,7 +990,8 @@ Type_handler::make_num_distinct_aggregator_field(MEM_ROOT *mem_root,
Field_double(NULL, item->max_length,
(uchar *) (item->maybe_null ? "" : 0),
item->maybe_null ? 1 : 0, Field::NONE,
&item->name, item->decimals, 0, item->unsigned_flag);
&item->name, (uint8) item->decimals,
0, item->unsigned_flag);
}
......@@ -1003,7 +1004,8 @@ Type_handler_float::make_num_distinct_aggregator_field(MEM_ROOT *mem_root,
Field_float(NULL, item->max_length,
(uchar *) (item->maybe_null ? "" : 0),
item->maybe_null ? 1 : 0, Field::NONE,
&item->name, item->decimals, 0, item->unsigned_flag);
&item->name, (uint8) item->decimals,
0, item->unsigned_flag);
}
......@@ -1018,7 +1020,8 @@ Type_handler_decimal_result::make_num_distinct_aggregator_field(
Field_new_decimal(NULL, item->max_length,
(uchar *) (item->maybe_null ? "" : 0),
item->maybe_null ? 1 : 0, Field::NONE,
&item->name, item->decimals, 0, item->unsigned_flag);
&item->name, (uint8) item->decimals,
0, item->unsigned_flag);
}
......@@ -1135,7 +1138,7 @@ Field *Type_handler_newdecimal::make_conversion_table_field(TABLE *table,
const
{
int precision= metadata >> 8;
uint decimals= metadata & 0x00ff;
uint8 decimals= metadata & 0x00ff;
uint32 max_length= my_decimal_precision_to_length(precision, decimals, false);
DBUG_ASSERT(decimals <= DECIMAL_MAX_SCALE);
return new (table->in_use->mem_root)
......@@ -2021,7 +2024,7 @@ Field *Type_handler_float::make_table_field(const LEX_CSTRING *name,
Field_float(addr.ptr, attr.max_char_length(),
addr.null_ptr, addr.null_bit,
Field::NONE, name,
attr.decimals, 0/*zerofill*/, attr.unsigned_flag);
(uint8) attr.decimals, 0/*zerofill*/, attr.unsigned_flag);
}
......@@ -2034,7 +2037,7 @@ Field *Type_handler_double::make_table_field(const LEX_CSTRING *name,
Field_double(addr.ptr, attr.max_char_length(),
addr.null_ptr, addr.null_bit,
Field::NONE, name,
attr.decimals, 0/*zerofill*/, attr.unsigned_flag);
(uint8) attr.decimals, 0/*zerofill*/, attr.unsigned_flag);
}
......@@ -2054,7 +2057,7 @@ Type_handler_olddecimal::make_table_field(const LEX_CSTRING *name,
DBUG_ASSERT(0);
return new (table->in_use->mem_root)
Field_decimal(addr.ptr, attr.max_length, addr.null_ptr, addr.null_bit,
Field::NONE, name, attr.decimals,
Field::NONE, name, (uint8) attr.decimals,
0/*zerofill*/,attr.unsigned_flag);
}
......@@ -2065,8 +2068,8 @@ Type_handler_newdecimal::make_table_field(const LEX_CSTRING *name,
const Type_all_attributes &attr,
TABLE *table) const
{
uint8 dec= attr.decimals;
uint8 intg= attr.decimal_precision() - dec;
uint8 dec= (uint8) attr.decimals;
uint8 intg= (uint8) (attr.decimal_precision() - dec);
uint32 len= attr.max_char_length();
/*
......@@ -5276,7 +5279,7 @@ static void wrong_precision_error(uint errcode, Item *a,
*/
bool get_length_and_scale(ulonglong length, ulonglong decimals,
ulong *out_length, uint *out_decimals,
uint *out_length, uint *out_decimals,
uint max_precision, uint max_scale,
Item *a)
{
......@@ -5293,7 +5296,7 @@ bool get_length_and_scale(ulonglong length, ulonglong decimals,
*out_decimals= (uint) decimals;
my_decimal_trim(&length, out_decimals);
*out_length= (ulong) length;
*out_length= (uint) length;
if (*out_length < *out_decimals)
{
......@@ -5359,8 +5362,7 @@ Item *Type_handler_decimal_result::
create_typecast_item(THD *thd, Item *item,
const Type_cast_attributes &attr) const
{
ulong len;
uint dec;
uint len, dec;
if (get_length_and_scale(attr.length(), attr.decimals(), &len, &dec,
DECIMAL_MAX_PRECISION, DECIMAL_MAX_SCALE, item))
return NULL;
......@@ -5372,8 +5374,7 @@ Item *Type_handler_double::
create_typecast_item(THD *thd, Item *item,
const Type_cast_attributes &attr) const
{
ulong len;
uint dec;
uint len, dec;
if (!attr.length_specified())
return new (thd->mem_root) Item_double_typecast(thd, item,
DBL_DIG + 7,
......
......@@ -227,7 +227,7 @@ static inline uint32
char_to_byte_length_safe(size_t char_length_arg, uint32 mbmaxlen_arg)
{
ulonglong tmp= ((ulonglong) char_length_arg) * mbmaxlen_arg;
return tmp > UINT_MAX32 ? UINT_MAX32 : static_cast<uint32>(tmp);
return tmp > UINT_MAX32 ? (uint32) UINT_MAX32 : static_cast<uint32>(tmp);
}
/**
......@@ -531,11 +531,12 @@ class Name: private LEX_CSTRING
public:
Name(const char *str_arg, uint length_arg)
{
DBUG_ASSERT(length_arg < UINT_MAX32);
LEX_CSTRING::str= str_arg;
LEX_CSTRING::length= length_arg;
}
const char *ptr() const { return LEX_CSTRING::str; }
uint length() const { return LEX_CSTRING::length; }
uint length() const { return (uint) LEX_CSTRING::length; }
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment