summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-03-12 19:44:52 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2020-03-12 19:44:52 +0200
commitd82ac8d374241b100f9e019400b23a5d905f622c (patch)
tree8b38b91c6963bc14ca3044bd179f19fe44aedf82
parentc7920fa8ff0a29958cfd337bcb3f3fac8703256a (diff)
downloadmariadb-git-d82ac8d374241b100f9e019400b23a5d905f622c.tar.gz
MDEV-21907: Fix some -Wconversion outside InnoDB
Some .c and .cc files are compiled as part of Mariabackup. Enabling -Wconversion for InnoDB would also enable it for Mariabackup. The .h files are being included during InnoDB or Mariabackup compilation. Notably, GCC 5 (but not GCC 4 or 6 or later versions) would report -Wconversion for x|=y when the type is unsigned char. So, we will either write x=(uchar)(x|y) or disable the -Wconversion warning for GCC 5. bitmap_set_bit(), bitmap_flip_bit(), bitmap_clear_bit(), bitmap_is_set(): Always implement as inline functions.
-rw-r--r--include/my_bit.h9
-rw-r--r--include/my_bitmap.h49
-rw-r--r--include/my_compare.h11
-rw-r--r--include/my_pthread.h8
-rw-r--r--include/my_sys.h4
-rw-r--r--libmysqld/libmysql.c41
-rw-r--r--sql/field.h11
-rw-r--r--sql/handler.h20
-rw-r--r--sql/net_serv.cc5
-rw-r--r--sql/sql_analyze_stmt.h72
-rw-r--r--sql/sql_class.h7
-rw-r--r--sql/sql_type.h9
-rw-r--r--sql/table.h43
13 files changed, 135 insertions, 154 deletions
diff --git a/include/my_bit.h b/include/my_bit.h
index ca51c9825b6..863ad30fd7e 100644
--- a/include/my_bit.h
+++ b/include/my_bit.h
@@ -1,5 +1,5 @@
/* Copyright (c) 2007, 2011, Oracle and/or its affiliates.
- Copyright (c) 2009, 2017, MariaDB Corporation.
+ Copyright (c) 2009, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -50,7 +50,7 @@ static inline CONSTEXPR uint my_bit_log2_hex_digit(uint8 value)
}
static inline CONSTEXPR uint my_bit_log2_uint8(uint8 value)
{
- return value & 0xF0 ? my_bit_log2_hex_digit(value >> 4) + 4:
+ return value & 0xF0 ? my_bit_log2_hex_digit((uint8) (value >> 4)) + 4:
my_bit_log2_hex_digit(value);
}
static inline CONSTEXPR uint my_bit_log2_uint16(uint16 value)
@@ -162,14 +162,13 @@ static inline uchar last_byte_mask(uint bits)
/* Get the number of used bits-1 (0..7) in the last byte */
unsigned int const used = (bits - 1U) & 7U;
/* Return bitmask for the significant bits */
- return ((2U << used) - 1);
+ return (uchar) ((2U << used) - 1);
}
#ifdef _MSC_VER
#include <intrin.h>
#endif
-#define MY_FIND_FIRST_BIT_END sizeof(ulonglong)*8
/*
Find the position of the first(least significant) bit set in
the argument. Returns 64 if the argument was 0.
@@ -177,7 +176,7 @@ static inline uchar last_byte_mask(uint bits)
static inline uint my_find_first_bit(ulonglong n)
{
if(!n)
- return MY_FIND_FIRST_BIT_END;
+ return 64;
#if defined(__GNUC__)
return __builtin_ctzll(n);
#elif defined(_MSC_VER)
diff --git a/include/my_bitmap.h b/include/my_bitmap.h
index 1b0fbe40d2e..f19254404c1 100644
--- a/include/my_bitmap.h
+++ b/include/my_bitmap.h
@@ -1,5 +1,5 @@
/* Copyright (c) 2001, 2011, Oracle and/or its affiliates.
- Copyright (c) 2009-2011, Monty Program Ab
+ Copyright (c) 2009, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -89,56 +89,35 @@ extern void bitmap_lock_clear_bit(MY_BITMAP *map, uint bitmap_bit);
#define no_bytes_in_map(map) (((map)->n_bits + 7)/8)
#define no_words_in_map(map) (((map)->n_bits + 31)/32)
#define bytes_word_aligned(bytes) (4*((bytes + 3)/4))
-#define _bitmap_set_bit(MAP, BIT) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \
- |= (1 << ((BIT) & 7)))
-#define _bitmap_flip_bit(MAP, BIT) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \
- ^= (1 << ((BIT) & 7)))
-#define _bitmap_clear_bit(MAP, BIT) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \
- &= ~ (1 << ((BIT) & 7)))
-#define _bitmap_is_set(MAP, BIT) (uint) (((uchar*)(MAP)->bitmap)[(BIT) / 8] \
- & (1 << ((BIT) & 7)))
-/*
- WARNING!
-
- The below symbols are inline functions in DEBUG builds and macros in
- non-DEBUG builds. The latter evaluate their 'bit' argument twice.
-
- NEVER use an increment/decrement operator with the 'bit' argument.
- It would work with DEBUG builds, but fails later in production builds!
-
- FORBIDDEN: bitmap_set_bit($my_bitmap, (field++)->field_index);
-*/
-#ifndef DBUG_OFF
+/* The following functions must be compatible with create_last_word_mask()! */
static inline void
bitmap_set_bit(MY_BITMAP *map,uint bit)
{
- DBUG_ASSERT(bit < (map)->n_bits);
- _bitmap_set_bit(map,bit);
+ uchar *b= (uchar*) map->bitmap + bit / 8;
+ DBUG_ASSERT(bit < map->n_bits);
+ *b= (uchar) (*b | 1U << (bit & 7));
}
static inline void
bitmap_flip_bit(MY_BITMAP *map,uint bit)
{
- DBUG_ASSERT(bit < (map)->n_bits);
- _bitmap_flip_bit(map,bit);
+ uchar *b= (uchar*) map->bitmap + bit / 8;
+ DBUG_ASSERT(bit < map->n_bits);
+ *b= (uchar) (*b ^ 1U << (bit & 7));
}
static inline void
bitmap_clear_bit(MY_BITMAP *map,uint bit)
{
- DBUG_ASSERT(bit < (map)->n_bits);
- _bitmap_clear_bit(map,bit);
+ uchar *b= (uchar*) map->bitmap + bit / 8;
+ DBUG_ASSERT(bit < map->n_bits);
+ *b= (uchar) (*b & ~(1U << (bit & 7)));
}
static inline uint
bitmap_is_set(const MY_BITMAP *map,uint bit)
{
- DBUG_ASSERT(bit < (map)->n_bits);
- return _bitmap_is_set(map,bit);
+ const uchar *b= (const uchar*) map->bitmap + bit / 8;
+ DBUG_ASSERT(bit < map->n_bits);
+ return !!(*b & (1U << (bit & 7)));
}
-#else
-#define bitmap_set_bit(MAP, BIT) _bitmap_set_bit(MAP, BIT)
-#define bitmap_flip_bit(MAP, BIT) _bitmap_flip_bit(MAP, BIT)
-#define bitmap_clear_bit(MAP, BIT) _bitmap_clear_bit(MAP, BIT)
-#define bitmap_is_set(MAP, BIT) _bitmap_is_set(MAP, BIT)
-#endif
static inline my_bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2)
{
diff --git a/include/my_compare.h b/include/my_compare.h
index 6568e5f2f27..32a909b5aa3 100644
--- a/include/my_compare.h
+++ b/include/my_compare.h
@@ -1,5 +1,5 @@
/* Copyright (c) 2011, Oracle and/or its affiliates.
- Copyright (c) Monty Program Ab; 1991-2011
+ Copyright (c) 1991, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -95,15 +95,16 @@ static inline uchar get_rec_bits(const uchar *ptr, uchar ofs, uint len)
{
uint16 val= ptr[0];
if (ofs + len > 8)
- val|= (uint16)(ptr[1]) << 8;
- return (val >> ofs) & ((1 << len) - 1);
+ val|= (uint16)((uint16)(ptr[1]) << 8);
+ return (uchar) ((val >> ofs) & ((1 << len) - 1));
}
static inline void set_rec_bits(uint16 bits, uchar *ptr, uchar ofs, uint len)
{
- ptr[0]= (ptr[0] & ~(((1 << len) - 1) << ofs)) | (bits << ofs);
+ ptr[0]= (uchar) ((ptr[0] & ~(((1 << len) - 1) << ofs)) | (bits << ofs));
if (ofs + len > 8)
- ptr[1]= (ptr[1] & ~((1 << (len - 8 + ofs)) - 1)) | (bits >> (8 - ofs));
+ ptr[1]= (uchar) ((ptr[1] & ~((1 << (len - 8 + ofs)) - 1)) |
+ bits >> (8 - ofs));
}
#define clr_rec_bits(bit_ptr, bit_ofs, bit_len) \
diff --git a/include/my_pthread.h b/include/my_pthread.h
index 0c67dc95765..0d9b9d61616 100644
--- a/include/my_pthread.h
+++ b/include/my_pthread.h
@@ -353,10 +353,10 @@ size_t my_setstacksize(pthread_attr_t *attr, size_t stacksize);
#endif /* !cmp_timespec */
#ifndef set_timespec_time_nsec
-#define set_timespec_time_nsec(ABSTIME,NSEC) do { \
- ulonglong _now_= (NSEC); \
- (ABSTIME).MY_tv_sec= (_now_ / 1000000000ULL); \
- (ABSTIME).MY_tv_nsec= (_now_ % 1000000000ULL); \
+#define set_timespec_time_nsec(ABSTIME,NSEC) do { \
+ ulonglong _now_= (NSEC); \
+ (ABSTIME).MY_tv_sec= (time_t) (_now_ / 1000000000ULL); \
+ (ABSTIME).MY_tv_nsec= (ulong) (_now_ % 1000000000UL); \
} while(0)
#endif /* !set_timespec_time_nsec */
diff --git a/include/my_sys.h b/include/my_sys.h
index 3d271c93a17..19c007c63dd 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates.
- Copyright (c) 2010, 2019, MariaDB Corporation.
+ Copyright (c) 2010, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -959,7 +959,7 @@ extern ulonglong my_interval_timer(void);
extern ulonglong my_getcputime(void);
#define microsecond_interval_timer() (my_interval_timer()/1000)
-#define hrtime_to_time(X) ((X).val/HRTIME_RESOLUTION)
+#define hrtime_to_time(X) ((time_t)((X).val/HRTIME_RESOLUTION))
#define hrtime_from_time(X) ((ulonglong)((X)*HRTIME_RESOLUTION))
#define hrtime_to_double(X) ((X).val/(double)HRTIME_RESOLUTION)
#define hrtime_sec_part(X) ((ulong)((X).val % HRTIME_RESOLUTION))
diff --git a/libmysqld/libmysql.c b/libmysqld/libmysql.c
index dce7a000c0c..22514acf3f0 100644
--- a/libmysqld/libmysql.c
+++ b/libmysqld/libmysql.c
@@ -411,7 +411,7 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
mysql->db= saved_db;
}
- DBUG_RETURN(rc);
+ DBUG_RETURN(rc != 0);
}
#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL)
@@ -839,7 +839,8 @@ MYSQL_FIELD *cli_list_fields(MYSQL *mysql)
mysql->field_count= (uint) query->rows;
return unpack_fields(mysql, query,&mysql->field_alloc,
- mysql->field_count, 1, mysql->server_capabilities);
+ mysql->field_count, 1,
+ (uint) mysql->server_capabilities);
}
@@ -898,7 +899,7 @@ mysql_list_processes(MYSQL *mysql)
protocol_41(mysql) ? 7 : 5)))
DBUG_RETURN(NULL);
if (!(mysql->fields=unpack_fields(mysql, fields,&mysql->field_alloc,field_count,0,
- mysql->server_capabilities)))
+ (uint) mysql->server_capabilities)))
DBUG_RETURN(0);
mysql->status=MYSQL_STATUS_GET_RESULT;
mysql->field_count=field_count;
@@ -1488,12 +1489,12 @@ my_bool cli_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt)
if (!(fields_data= (*mysql->methods->read_rows)(mysql,(MYSQL_FIELD*)0,7)))
DBUG_RETURN(1);
if (!(stmt->fields= unpack_fields(mysql, fields_data,&stmt->mem_root,
- field_count,0,
- mysql->server_capabilities)))
+ field_count,0,
+ (uint) mysql->server_capabilities)))
DBUG_RETURN(1);
}
stmt->field_count= field_count;
- stmt->param_count= (ulong) param_count;
+ stmt->param_count= (uint) param_count;
DBUG_PRINT("exit",("field_count: %u param_count: %u warning_count: %u",
field_count, param_count, (uint) mysql->warning_count));
@@ -2024,7 +2025,10 @@ static void net_store_datetime(NET *net, MYSQL_TIME *tm)
static void store_param_date(NET *net, MYSQL_BIND *param)
{
MYSQL_TIME tm= *((MYSQL_TIME *) param->buffer);
- tm.hour= tm.minute= tm.second= tm.second_part= 0;
+ tm.hour= 0;
+ tm.minute= 0;
+ tm.second= 0;
+ tm.second_part= 0;
net_store_datetime(net, &tm);
}
@@ -2061,7 +2065,14 @@ static void store_param_str(NET *net, MYSQL_BIND *param)
static void store_param_null(NET *net, MYSQL_BIND *param)
{
uint pos= param->param_number;
+#if defined __GNUC__ && !defined __clang__ && __GNUC__ == 5
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wconversion" /* GCC 5 needs this */
+#endif
net->buff[pos/8]|= (uchar) (1 << (pos & 7));
+#if defined __GNUC__ && !defined __clang__ && __GNUC__ == 5
+# pragma GCC diagnostic pop
+#endif
}
@@ -3082,14 +3093,14 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number,
static void read_binary_time(MYSQL_TIME *tm, uchar **pos)
{
/* net_field_length will set pos to the first byte of data */
- uint length= net_field_length(pos);
+ ulong length= net_field_length(pos);
if (length)
{
uchar *to= *pos;
tm->neg= to[0];
- tm->day= (ulong) sint4korr(to+1);
+ tm->day= (uint) sint4korr(to+1);
tm->hour= (uint) to[5];
tm->minute= (uint) to[6];
tm->second= (uint) to[7];
@@ -3111,7 +3122,7 @@ static void read_binary_time(MYSQL_TIME *tm, uchar **pos)
static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos)
{
- uint length= net_field_length(pos);
+ ulong length= net_field_length(pos);
if (length)
{
@@ -3141,7 +3152,7 @@ static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos)
static void read_binary_date(MYSQL_TIME *tm, uchar **pos)
{
- uint length= net_field_length(pos);
+ ulong length= net_field_length(pos);
if (length)
{
@@ -3382,7 +3393,7 @@ static void fetch_long_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
uchar *end= (uchar*) longlong10_to_str(value, (char*) buff,
is_unsigned ? 10: -10);
/* Resort to string conversion which supports all typecodes */
- uint length= (uint) (end-buff);
+ size_t length= end-buff;
if (field->flags & ZEROFILL_FLAG && length < field->length &&
field->length < 21)
@@ -3906,8 +3917,10 @@ static my_bool is_binary_compatible(enum enum_field_types type1,
my_bool type1_found= FALSE, type2_found= FALSE;
for (type= *range; *type != MYSQL_TYPE_NULL; type++)
{
- type1_found|= type1 == *type;
- type2_found|= type2 == *type;
+ if (type1 == *type)
+ type1_found= TRUE;
+ if (type2 == *type)
+ type2_found= TRUE;
}
if (type1_found || type2_found)
return type1_found && type2_found;
diff --git a/sql/field.h b/sql/field.h
index 425f9f5292c..49e82766af3 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1369,7 +1369,7 @@ public:
void set_null_ptr(uchar *p_null_ptr, uint p_null_bit)
{
null_ptr= p_null_ptr;
- null_bit= p_null_bit;
+ null_bit= static_cast<uchar>(p_null_bit);
}
bool stored_in_db() const { return !vcol_info || vcol_info->stored_in_db; }
@@ -4921,7 +4921,8 @@ public:
explicitly using the field_length.
*/
return Binlog_type_info(type(),
- field_length % 8 + ((field_length / 8) << 8), 2);
+ static_cast<uint16>((field_length & 7) |
+ ((field_length / 8) << 8)), 2);
}
private:
@@ -5558,9 +5559,9 @@ public:
uint32 max_char_length(CHARSET_INFO *cs) const
{
return type_handler()->field_type() >= MYSQL_TYPE_TINY_BLOB &&
- type_handler()->field_type() <= MYSQL_TYPE_BLOB ?
- length / cs->mbminlen :
- length / cs->mbmaxlen;
+ type_handler()->field_type() <= MYSQL_TYPE_BLOB
+ ? static_cast<uint32>(length / cs->mbminlen)
+ : static_cast<uint32>(length / cs->mbmaxlen);
}
uint32 max_octet_length(CHARSET_INFO *from, CHARSET_INFO *to) const
{
diff --git a/sql/handler.h b/sql/handler.h
index f17c303571f..ebddb659977 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -2,7 +2,7 @@
#define HANDLER_INCLUDED
/*
Copyright (c) 2000, 2019, Oracle and/or its affiliates.
- Copyright (c) 2009, 2019, MariaDB
+ Copyright (c) 2009, 2020, MariaDB
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -2664,18 +2664,18 @@ public:
double idx_cpu_cost; /* cost of operations in CPU for index */
double import_cost; /* cost of remote operations */
double mem_cost; /* cost of used memory */
-
- enum { IO_COEFF=1 };
- enum { CPU_COEFF=1 };
- enum { MEM_COEFF=1 };
- enum { IMPORT_COEFF=1 };
+
+ static constexpr double IO_COEFF= 1;
+ static constexpr double CPU_COEFF= 1;
+ static constexpr double MEM_COEFF= 1;
+ static constexpr double IMPORT_COEFF= 1;
Cost_estimate()
{
reset();
}
- double total_cost()
+ double total_cost() const
{
return IO_COEFF*io_count*avg_io_cost +
IO_COEFF*idx_io_count*idx_avg_io_cost +
@@ -2696,7 +2696,7 @@ public:
*/
bool is_zero() const
{
- return io_count == 0.0 && idx_io_count && cpu_cost == 0.0 &&
+ return io_count == 0.0 && idx_io_count == 0.0 && cpu_cost == 0.0 &&
import_cost == 0.0 && mem_cost == 0.0;
}
@@ -2719,7 +2719,7 @@ public:
void add(const Cost_estimate* cost)
{
- if (cost->io_count)
+ if (cost->io_count != 0.0)
{
double io_count_sum= io_count + cost->io_count;
avg_io_cost= (io_count * avg_io_cost +
@@ -2727,7 +2727,7 @@ public:
/io_count_sum;
io_count= io_count_sum;
}
- if (cost->idx_io_count)
+ if (cost->idx_io_count != 0.0)
{
double idx_io_count_sum= idx_io_count + cost->idx_io_count;
idx_avg_io_cost= (idx_io_count * idx_avg_io_cost +
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index 840593cd2db..55ae19237ac 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -411,7 +411,6 @@ my_bool net_flush(NET *net)
my_bool my_net_write(NET *net, const uchar *packet, size_t len)
{
uchar buff[NET_HEADER_SIZE];
- int rc;
if (unlikely(!net->vio)) /* nowhere to write */
return 0;
@@ -448,7 +447,7 @@ my_bool my_net_write(NET *net, const uchar *packet, size_t len)
#ifndef DEBUG_DATA_PACKETS
DBUG_DUMP("packet_header", buff, NET_HEADER_SIZE);
#endif
- rc= MY_TEST(net_write_buff(net, packet, len));
+ my_bool rc= MY_TEST(net_write_buff(net, packet, len));
MYSQL_NET_WRITE_DONE(rc);
return rc;
}
@@ -489,7 +488,7 @@ net_write_command(NET *net,uchar command,
size_t length=len+1+head_len; /* 1 extra byte for command */
uchar buff[NET_HEADER_SIZE+1];
uint header_size=NET_HEADER_SIZE+1;
- int rc;
+ my_bool rc;
DBUG_ENTER("net_write_command");
DBUG_PRINT("enter",("length: %lu", (ulong) len));
diff --git a/sql/sql_analyze_stmt.h b/sql/sql_analyze_stmt.h
index bc7c60a318b..990c79fb9ad 100644
--- a/sql/sql_analyze_stmt.h
+++ b/sql/sql_analyze_stmt.h
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2015 MariaDB Corporation Ab
+ Copyright (c) 2015, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -90,7 +90,8 @@ public:
double get_time_ms() const
{
// convert 'cycles' to milliseconds.
- return 1000 * ((double)cycles) / sys_timer_info.cycles.frequency;
+ return 1000.0 * static_cast<double>(cycles) /
+ static_cast<double>(sys_timer_info.cycles.frequency);
}
};
@@ -114,7 +115,8 @@ public:
double get_time_ms() const
{
// convert 'cycles' to milliseconds.
- return 1000 * ((double)cycles) / sys_timer_info.cycles.frequency;
+ return 1000.0 * static_cast<double>(cycles) /
+ static_cast<double>(sys_timer_info.cycles.frequency);
}
};
@@ -178,24 +180,23 @@ public:
ha_rows r_rows; /* How many rows we've got after that */
ha_rows r_rows_after_where; /* Rows after applying attached part of WHERE */
- bool has_scans() { return (r_scans != 0); }
- ha_rows get_loops() { return r_scans; }
- double get_avg_rows()
+ bool has_scans() const { return (r_scans != 0); }
+ ha_rows get_loops() const { return r_scans; }
+ double get_avg_rows() const
{
- return r_scans ? ((double)r_rows / r_scans): 0;
+ return r_scans
+ ? static_cast<double>(r_rows) / static_cast<double>(r_scans)
+ : 0;
}
- double get_filtered_after_where()
+ double get_filtered_after_where() const
{
- double r_filtered;
- if (r_rows > 0)
- r_filtered= (double)r_rows_after_where / r_rows;
- else
- r_filtered= 1.0;
-
- return r_filtered;
+ return r_rows > 0
+ ? static_cast<double>(r_rows_after_where) /
+ static_cast<double>(r_rows)
+ : 1.0;
}
-
+
inline void on_scan_init() { r_scans++; }
inline void on_record_read() { r_rows++; }
inline void on_record_after_where() { r_rows_after_where++; }
@@ -278,25 +279,27 @@ public:
}
void get_data_format(String *str);
-
+
/* Functions to get the statistics */
void print_json_members(Json_writer *writer);
-
+
ulonglong get_r_loops() const { return time_tracker.get_loops(); }
- double get_avg_examined_rows()
- {
- return ((double)r_examined_rows) / get_r_loops();
+ double get_avg_examined_rows() const
+ {
+ return static_cast<double>(r_examined_rows) /
+ static_cast<double>(get_r_loops());
}
- double get_avg_returned_rows()
- {
- return ((double)r_output_rows) / get_r_loops();
+ double get_avg_returned_rows() const
+ {
+ return static_cast<double>(r_output_rows) /
+ static_cast<double>(get_r_loops());
}
- double get_r_filtered()
+ double get_r_filtered() const
{
- if (r_examined_rows > 0)
- return ((double)r_sorted_rows / r_examined_rows);
- else
- return 1.0;
+ return r_examined_rows > 0
+ ? static_cast<double>(r_sorted_rows) /
+ static_cast<double>(r_examined_rows)
+ : 1.0;
}
private:
Time_and_counter_tracker time_tracker;
@@ -397,7 +400,7 @@ public:
return &time_tracker;
}
- double get_time_fill_container_ms()
+ double get_time_fill_container_ms() const
{
return time_tracker.get_time_ms();
}
@@ -411,13 +414,14 @@ public:
inline void increment_container_elements_count() { container_elements++; }
- uint get_container_elements() { return container_elements; }
+ uint get_container_elements() const { return container_elements; }
- double get_r_selectivity_pct()
+ double get_r_selectivity_pct() const
{
- return (double)n_positive_checks/(double)n_checks;
+ return static_cast<double>(n_positive_checks) /
+ static_cast<double>(n_checks);
}
- size_t get_container_buff_size() { return container_buff_size; }
+ size_t get_container_buff_size() const { return container_buff_size; }
};
diff --git a/sql/sql_class.h b/sql/sql_class.h
index acd304e24ea..1096ab0b29c 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -960,9 +960,10 @@ typedef struct system_status_var
#define last_system_status_var questions
#define last_cleared_system_status_var local_memory_used
-/* Number of contiguous global status variables. */
-const int COUNT_GLOBAL_STATUS_VARS= (offsetof(STATUS_VAR, last_system_status_var) /
- sizeof(ulong)) + 1;
+/** Number of contiguous global status variables */
+constexpr int COUNT_GLOBAL_STATUS_VARS= int(offsetof(STATUS_VAR,
+ last_system_status_var) /
+ sizeof(ulong)) + 1;
/*
Global status variables
diff --git a/sql/sql_type.h b/sql/sql_type.h
index f87e398bd71..c3a6a5f4ff5 100644
--- a/sql/sql_type.h
+++ b/sql/sql_type.h
@@ -721,7 +721,7 @@ public:
if (m_error)
return true;
to_hh24mmssff(ltime, MYSQL_TIMESTAMP_TIME);
- ltime->hour+= to_days_abs() * 24;
+ ltime->hour+= static_cast<unsigned>(to_days_abs() * 24);
return adjust_time_range_with_warn(thd, ltime, decimals);
}
bool to_datetime(MYSQL_TIME *ltime) const
@@ -906,7 +906,8 @@ protected:
my_decimal *to_decimal(my_decimal *to) const;
static double to_double(bool negate, ulonglong num, ulong frac)
{
- double d= (double) num + frac / (double) TIME_SECOND_PART_FACTOR;
+ double d= static_cast<double>(num) + static_cast<double>(frac) /
+ TIME_SECOND_PART_FACTOR;
return negate ? -d : d;
}
longlong to_packed() const { return ::pack_time(this); }
@@ -1034,7 +1035,7 @@ protected:
{
return ::check_date(this, flags, warn);
}
- void time_hhmmssff_set_max(ulong max_hour)
+ void time_hhmmssff_set_max(uint max_hour)
{
hour= max_hour;
minute= TIME_MAX_MINUTE;
@@ -3201,7 +3202,7 @@ public:
{ }
uchar *ptr() const { return m_ptr; }
uchar offs() const { return m_offs; }
- uchar bit() const { return m_ptr ? ((uchar) 1) << m_offs : 0; }
+ uchar bit() const { return static_cast<uchar>(m_ptr ? 1U << m_offs : 0); }
void inc()
{
DBUG_ASSERT(m_ptr);
diff --git a/sql/table.h b/sql/table.h
index ad3336b9bd9..9430ceb5fe3 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -1,7 +1,7 @@
#ifndef TABLE_INCLUDED
#define TABLE_INCLUDED
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates.
- Copyright (c) 2009, 2019, MariaDB
+ Copyright (c) 2009, 2020, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -2564,22 +2564,10 @@ struct TABLE_LIST
}
/* Set of functions returning/setting state of a derived table/view. */
- inline bool is_non_derived()
- {
- return (!derived_type);
- }
- inline bool is_view_or_derived()
- {
- return (derived_type);
- }
- inline bool is_view()
- {
- return (derived_type & DTYPE_VIEW);
- }
- inline bool is_derived()
- {
- return (derived_type & DTYPE_TABLE);
- }
+ bool is_non_derived() const { return (!derived_type); }
+ bool is_view_or_derived() const { return derived_type; }
+ bool is_view() const { return (derived_type & DTYPE_VIEW); }
+ bool is_derived() const { return (derived_type & DTYPE_TABLE); }
bool is_with_table();
bool is_recursive_with_table();
bool is_with_table_recursive_reference();
@@ -2595,22 +2583,19 @@ struct TABLE_LIST
{
derived_type= DTYPE_TABLE;
}
- inline bool is_merged_derived()
- {
- return (derived_type & DTYPE_MERGE);
- }
+ bool is_merged_derived() const { return (derived_type & DTYPE_MERGE); }
inline void set_merged_derived()
{
DBUG_ENTER("set_merged_derived");
DBUG_PRINT("enter", ("Alias: '%s' Unit: %p",
(alias.str ? alias.str : "<NULL>"),
get_unit()));
- derived_type= ((derived_type & DTYPE_MASK) |
- DTYPE_TABLE | DTYPE_MERGE);
+ derived_type= static_cast<uint8>((derived_type & DTYPE_MASK) |
+ DTYPE_TABLE | DTYPE_MERGE);
set_check_merged();
DBUG_VOID_RETURN;
}
- inline bool is_materialized_derived()
+ bool is_materialized_derived() const
{
return (derived_type & DTYPE_MATERIALIZE);
}
@@ -2621,15 +2606,13 @@ struct TABLE_LIST
(alias.str ? alias.str : "<NULL>"),
get_unit()));
derived= get_unit();
- derived_type= ((derived_type & (derived ? DTYPE_MASK : DTYPE_VIEW)) |
- DTYPE_TABLE | DTYPE_MATERIALIZE);
+ derived_type= static_cast<uint8>((derived_type &
+ (derived ? DTYPE_MASK : DTYPE_VIEW)) |
+ DTYPE_TABLE | DTYPE_MATERIALIZE);
set_check_materialized();
DBUG_VOID_RETURN;
}
- inline bool is_multitable()
- {
- return (derived_type & DTYPE_MULTITABLE);
- }
+ bool is_multitable() const { return (derived_type & DTYPE_MULTITABLE); }
inline void set_multitable()
{
derived_type|= DTYPE_MULTITABLE;