diff --git a/include/m_string.h b/include/m_string.h index 4a2424b3940..ef5ede189d3 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -341,8 +341,9 @@ static inline void human_readable_num_bytes(char *buf, int buf_len, unsigned int i; for (i = 0; dbl_val > 1024 && i < sizeof(size) - 1; i++) dbl_val /= 1024; const char mult = size[i]; - // 18446744073709551615 Yottabytes should be enough for most ... - if (dbl_val > ULLONG_MAX) + // ULLONG_MAX (18446744073709551615) should be enough for most ... + // static_cast(ULLONG_MAX) is equal 18446744073709551616.0 + if (dbl_val >= static_cast(ULLONG_MAX)) snprintf(buf, buf_len, "+INF"); else snprintf(buf, buf_len, "%llu%c", (unsigned long long)dbl_val, mult); diff --git a/libmysql/libmysql.cc b/libmysql/libmysql.cc index 59982ecc161..7d4f7f3266a 100644 --- a/libmysql/libmysql.cc +++ b/libmysql/libmysql.cc @@ -3117,8 +3117,8 @@ static void fetch_long_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, volatile double data; if (is_unsigned) { data = ulonglong2double(value); - *param->error = - data >= ULLONG_MAX || ((ulonglong)value) != ((ulonglong)data); + *param->error = data >= static_cast(ULLONG_MAX) || + ((ulonglong)value) != ((ulonglong)data); } else { data = (double)value; *param->error = value != ((longlong)data); diff --git a/plugin/x/client/xsession_impl.cc b/plugin/x/client/xsession_impl.cc index 1ff3b280130..8ff7aa95c30 100644 --- a/plugin/x/client/xsession_impl.cc +++ b/plugin/x/client/xsession_impl.cc @@ -459,7 +459,7 @@ XError Session_impl::set_mysql_option( ER_TEXT_OPTION_NOT_SUPPORTED_AFTER_CONNECTING}; Argument_array array; - for (const auto value : values_list) { + for (const auto &value : values_list) { array.push_back(Argument_value{value}); } diff --git a/router/src/router/src/config_generator.cc b/router/src/router/src/config_generator.cc index 9b183434718..87620dd01fb 100644 --- a/router/src/router/src/config_generator.cc +++ b/router/src/router/src/config_generator.cc @@ -2227,7 +2227,7 @@ void ConfigGenerator::throw_account_exists(const MySQLSession::Error &e, std::string msg = "Account(s) "; bool is_first{true}; - for (const std::string a : accounts) { + for (const std::string &a : accounts) { if (is_first) { is_first = false; } else { diff --git a/router/tests/component/test_bootstrap.cc b/router/tests/component/test_bootstrap.cc index 9ff77b0c9d1..91f0f22b267 100644 --- a/router/tests/component/test_bootstrap.cc +++ b/router/tests/component/test_bootstrap.cc @@ -1712,11 +1712,11 @@ class AccountReuseTestBase : public CommonBootstrapTest { } } - for (const std::string output : exp_output) { + for (const std::string &output : exp_output) { EXPECT_TRUE(router.expect_output(output)) << "-------- expected output:\n" << output << std::endl; } - for (const std::string output : unexp_output) { + for (const std::string &output : unexp_output) { EXPECT_FALSE(router.expect_output(output)) << "-------- unexpected output:\n" << output << std::endl; diff --git a/sql/auth/sql_authorization.cc b/sql/auth/sql_authorization.cc index a2cd9c31273..a644d13300c 100644 --- a/sql/auth/sql_authorization.cc +++ b/sql/auth/sql_authorization.cc @@ -1069,14 +1069,14 @@ void make_database_privilege_statement(THD *thd, ACL_USER *role, */ Mem_root_array> restrictions_array( thd->mem_root); - for (const auto rl_itr : restrictions.get()) { + for (const auto &rl_itr : restrictions.get()) { restrictions_array.push_back({rl_itr.first, rl_itr.second}); } std::sort(restrictions_array.begin(), restrictions_array.end(), [](const auto &p1, const auto &p2) -> bool { return (p1.first.compare(p2.first) <= 0); }); - for (const auto rl_itr : restrictions_array) { + for (const auto &rl_itr : restrictions_array) { String db; db.length(0); db.append(STRING_WITH_LEN("REVOKE ")); diff --git a/sql/item.h b/sql/item.h index f566636ee71..cec0da55f6d 100644 --- a/sql/item.h +++ b/sql/item.h @@ -4599,12 +4599,14 @@ class Item_result_field : public Item { } longlong llrint_with_overflow_check(double realval) { - if (realval < LLONG_MIN || realval > LLONG_MAX) { + if (realval < static_cast(LLONG_MIN) || + realval > static_cast(LLONG_MAX)) { raise_integer_overflow(); return error_int(); } // Rounding error, llrint() may return LLONG_MIN. - const longlong retval = realval == LLONG_MAX ? LLONG_MAX : llrint(realval); + const longlong retval = + realval == static_cast(LLONG_MAX) ? LLONG_MAX : llrint(realval); return retval; } diff --git a/sql/opt_explain.cc b/sql/opt_explain.cc index b0c7e481919..2400eb87860 100644 --- a/sql/opt_explain.cc +++ b/sql/opt_explain.cc @@ -1468,7 +1468,8 @@ bool Explain_join::explain_rows_and_filtered() { // Print cost-related info double prefix_rows = pos->prefix_rowcount; ulonglong prefix_rows_ull = - prefix_rows >= std::numeric_limits::max() + prefix_rows >= + static_cast(std::numeric_limits::max()) ? std::numeric_limits::max() : static_cast(prefix_rows); fmt->entry()->col_prefix_rows.set(prefix_rows_ull); diff --git a/sql/sql_db.cc b/sql/sql_db.cc index abe48b69903..f46a35d3cd6 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -876,7 +876,7 @@ static bool find_db_tables(THD *thd, const dd::Schema &schema, const char *db, &sch_tables)) return true; - for (const dd::String_type table_name : sch_tables) { + for (const dd::String_type &table_name : sch_tables) { TABLE_LIST *table_list = new (thd->mem_root) TABLE_LIST; if (table_list == nullptr) return true; /* purecov: inspected */ diff --git a/sql/sql_planner.cc b/sql/sql_planner.cc index f99de05f7a8..5a34d25cce9 100644 --- a/sql/sql_planner.cc +++ b/sql/sql_planner.cc @@ -878,10 +878,11 @@ double Optimize_table_order::calculate_scan_cost( tab->records() - *rows_after_filtering)); trace_access_scan->add("using_join_cache", true); - trace_access_scan->add("buffers_needed", - buffer_count >= std::numeric_limits::max() - ? std::numeric_limits::max() - : static_cast(buffer_count)); + trace_access_scan->add( + "buffers_needed", + buffer_count >= static_cast(std::numeric_limits::max()) + ? std::numeric_limits::max() + : static_cast(buffer_count)); } } @@ -2549,10 +2550,11 @@ bool Optimize_table_order::consider_plan(uint idx, (Similar code in best_extension_by_li...) */ join->best_read = cost - 0.001; - join->best_rowcount = join->positions[idx].prefix_rowcount >= - std::numeric_limits::max() - ? std::numeric_limits::max() - : (ha_rows)join->positions[idx].prefix_rowcount; + join->best_rowcount = + join->positions[idx].prefix_rowcount >= + static_cast(std::numeric_limits::max()) + ? std::numeric_limits::max() + : (ha_rows)join->positions[idx].prefix_rowcount; join->sort_cost = sort_cost; join->windowing_cost = windowing_cost; found_plan_with_allowed_sj = plan_uses_allowed_sj; diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index 5e6cfe3148c..7af92780295 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -2330,7 +2330,7 @@ static void lock_grant_cats(hash_table_t *hash, lock_t *in_lock, const auto trx = lock->trx; int32_t age_compensate = 0; - for (const auto new_granted_lock : new_granted) { + for (const auto &new_granted_lock : new_granted) { if (lock->trx == new_granted_lock.first->trx) { age_compensate += trx->age + 1; } @@ -2346,7 +2346,7 @@ static void lock_grant_cats(hash_table_t *hash, lock_t *in_lock, const auto trx = lock->trx; int32_t age_compensate = 0; - for (const auto wait_lock : waiting) { + for (const auto &wait_lock : waiting) { if (wait_lock.first->is_waiting() && lock->trx == wait_lock.first->trx) { age_compensate -= trx->age + 1; } diff --git a/unittest/gunit/m_string-t.cc b/unittest/gunit/m_string-t.cc index fb5c613e6b3..773f1f193e4 100644 --- a/unittest/gunit/m_string-t.cc +++ b/unittest/gunit/m_string-t.cc @@ -88,7 +88,8 @@ TEST(MString, HumanReadableSize) { human_readable_num_bytes(data_size_str, 32, data_size); EXPECT_STREQ("1025000000Y", data_size_str); - data_size *= std::numeric_limits::max(); + data_size *= + static_cast(std::numeric_limits::max()); human_readable_num_bytes(data_size_str, 32, data_size); EXPECT_STREQ("+INF", data_size_str); } diff --git a/unittest/gunit/xplugin/xpl/sql_statement_builder_t.cc b/unittest/gunit/xplugin/xpl/sql_statement_builder_t.cc index 8fba7c9e182..406e0477a50 100644 --- a/unittest/gunit/xplugin/xpl/sql_statement_builder_t.cc +++ b/unittest/gunit/xplugin/xpl/sql_statement_builder_t.cc @@ -40,7 +40,7 @@ template class Sql_statement_builder_test_base : public testing::TestWithParam { public: Query_string_builder m_qb; - Sql_statement_builder m_builder{{&m_qb}}; + Sql_statement_builder m_builder{&m_qb}; }; struct Param_sql_statement_builder {