Skip to content

Commit b02a690

Browse files
author
Tor Didriksen
committed
Bug #33809262 Run clang-tidy modernize-use-nullptr (again) [noclose]
Another cross-cutting, large-scale clang-tidy fix. It runs the modernize-use-nullptr fixit over the source code, changing 0 literals (in pointer context) and NULL to nullptr. Converting 0 and NULL literals to nullptr makes code easier to read by increasing self-documentation, makes type and argument order mistakes more difficult, enable compiler warnings when nonsensical operations are attempted (such as adding pointers), enable perfect forwarding in more cases (NULL cannot be perfect forwarded, nullptr can) and reduces noise from IDEs and other tools that check clang-tidy warnings. This patch fixes the server code, and most of the plugins. Configured with: -DWITH_MEB=0 -DWITH_MYSQLX=0 -DWITHOUT_GROUP_REPLICATION=1 Change-Id: I8e8ae3180a6effa293d5a17f644b15706512e7f0
1 parent 513073d commit b02a690

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+163
-160
lines changed

components/keyrings/common/encryption/aes.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -113,11 +113,11 @@ bool aes_create_key(const unsigned char *key, unsigned int key_length,
113113
switch (*rkey_size) {
114114
case 32: /* 256 bit key */ {
115115
EVP_MD_CTX *md_ctx = EVP_MD_CTX_create();
116-
EVP_DigestInit_ex(md_ctx, EVP_sha256(), NULL);
116+
EVP_DigestInit_ex(md_ctx, EVP_sha256(), nullptr);
117117
EVP_DigestUpdate(
118118
md_ctx, reinterpret_cast<void *>(const_cast<unsigned char *>(key)),
119119
(size_t)key_length);
120-
EVP_DigestFinal_ex(md_ctx, rkey.get(), NULL);
120+
EVP_DigestFinal_ex(md_ctx, rkey.get(), nullptr);
121121
EVP_MD_CTX_destroy(md_ctx);
122122
break;
123123
}

components/reference_cache/channel.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2020, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2020, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -101,7 +101,7 @@ bool channel_imp::factory_init() {
101101
"A mutex to guard access to the channels list"}};
102102

103103
mysql_mutex_register(PSI_category, all_mutex, 1);
104-
mysql_mutex_init(key_LOCK_channels, &LOCK_channels, NULL);
104+
mysql_mutex_init(key_LOCK_channels, &LOCK_channels, nullptr);
105105
return false;
106106
}
107107

components/test/keyring_encryption_test/components.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2021, 2022, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -42,7 +42,7 @@ registry_type_t *components_registry = nullptr;
4242
dynamic_loader_type_t *components_dynamic_loader = nullptr;
4343

4444
void init_components_subsystem() {
45-
minimal_chassis_init((&components_registry), NULL);
45+
minimal_chassis_init((&components_registry), nullptr);
4646
components_registry->acquire(
4747
"dynamic_loader",
4848
reinterpret_cast<my_h_service *>(&components_dynamic_loader));
@@ -51,7 +51,7 @@ void init_components_subsystem() {
5151
void deinit_components_subsystem() {
5252
components_registry->release(
5353
reinterpret_cast<my_h_service>(components_dynamic_loader));
54-
minimal_chassis_deinit(components_registry, NULL);
54+
minimal_chassis_deinit(components_registry, nullptr);
5555
}
5656

5757
Keyring_component_load::Keyring_component_load(const std::string component_name)

components/test/test_mysql_system_variable_set.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -94,7 +94,7 @@ long long test_set_system_variable_string(UDF_INIT * /*initd*/, UDF_ARGS *args,
9494
unsigned char *error) {
9595
bool make_new_thread = *((long long *)args->args[0]) > 0;
9696

97-
MYSQL_THD thd = NULL;
97+
MYSQL_THD thd = nullptr;
9898

9999
*error = 0;
100100

plugin/keyring_udf/keyring_udf.cc

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2016, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -459,11 +459,11 @@ char *keyring_key_fetch(UDF_INIT *initid, UDF_ARGS *args, char *,
459459

460460
if (validate_run_time(args, VALIDATE_KEY_ID)) {
461461
*error = 1;
462-
return 0;
462+
return nullptr;
463463
}
464464

465-
if (fetch("keyring_key_fetch", args->args[0], &key, NULL, &key_len)) {
466-
if (key != NULL) my_free(key);
465+
if (fetch("keyring_key_fetch", args->args[0], &key, nullptr, &key_len)) {
466+
if (key != nullptr) my_free(key);
467467
*error = 1;
468468
return nullptr;
469469
}
@@ -509,12 +509,13 @@ char *keyring_key_type_fetch(UDF_INIT *initid, UDF_ARGS *args, char *,
509509
unsigned char *error) {
510510
if (validate_run_time(args, VALIDATE_KEY_ID)) {
511511
*error = 1;
512-
return 0;
512+
return nullptr;
513513
}
514514

515-
char *key_type = NULL;
516-
if (fetch("keyring_key_type_fetch", args->args[0], NULL, &key_type, NULL)) {
517-
if (key_type != NULL) my_free(key_type);
515+
char *key_type = nullptr;
516+
if (fetch("keyring_key_type_fetch", args->args[0], nullptr, &key_type,
517+
nullptr)) {
518+
if (key_type != nullptr) my_free(key_type);
518519
*error = 1;
519520
return nullptr;
520521
}
@@ -571,7 +572,7 @@ long long keyring_key_length_fetch(UDF_INIT *, UDF_ARGS *args,
571572

572573
if (*error == 0 && key == nullptr) *is_null = 1;
573574

574-
if (key != NULL) my_free(key);
575+
if (key != nullptr) my_free(key);
575576

576577
// For the UDF 0 == failure.
577578
return (*error) ? 0 : key_len;

plugin/replication_observers_example/replication_observers_example.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2014, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -1033,7 +1033,7 @@ bool test_server_count_transactions() {
10331033

10341034
assert(service.is_valid());
10351035

1036-
unsigned long *ids = NULL;
1036+
unsigned long *ids = nullptr;
10371037
unsigned long size = 0;
10381038
bool error = service->get_ongoing_server_transactions(&ids, &size);
10391039
assert(!error);

plugin/test_service_sql_api/test_sql_sleep_is_connected.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void ensure_api_ok(const char *function, int result) {
5252
}
5353

5454
static void ensure_api_ok(const char *function, MYSQL_SESSION result) {
55-
if (result == 0) {
55+
if (result == nullptr) {
5656
test_context->log_test_line("ERROR calling ", function, ": returned ",
5757
reinterpret_cast<uintptr_t>(result), "\n");
5858
}
@@ -404,11 +404,11 @@ mysql_declare_plugin(test_daemon){
404404
"Test sql service commands",
405405
PLUGIN_LICENSE_GPL,
406406
test_session_plugin_init, /* Plugin Init */
407-
NULL, /* Plugin Check uninstall */
407+
nullptr, /* Plugin Check uninstall */
408408
test_session_plugin_deinit, /* Plugin Deinit */
409409
0x0100 /* 1.0 */,
410-
NULL, /* status variables */
411-
NULL, /* system variables */
412-
NULL, /* config options */
413-
0, /* flags */
410+
nullptr, /* status variables */
411+
nullptr, /* system variables */
412+
nullptr, /* config options */
413+
0, /* flags */
414414
} mysql_declare_plugin_end;

router/src/router/tests/test_utils.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2015, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2015, 2022, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -245,7 +245,7 @@ TEST_F(UtilsTests, uint64_conversion) {
245245
const uint64_t kDefault{66};
246246

247247
EXPECT_EQ(kDefault, strtoull_checked(nullptr, kDefault));
248-
EXPECT_EQ(kDefault, strtoull_checked(0, kDefault));
248+
EXPECT_EQ(kDefault, strtoull_checked(nullptr, kDefault));
249249
EXPECT_EQ(kDefault, strtoull_checked("18446744073709551617", kDefault));
250250

251251
EXPECT_EQ(static_cast<uint64_t>(0), strtoull_checked("0", kDefault));

sql/binlog.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7391,7 +7391,7 @@ bool MYSQL_BIN_LOG::write_incident(Incident_log_event *ev, THD *thd,
73917391
create one, so that a GTID is generated and is written prior to flushing
73927392
the stmt_cache.
73937393
*/
7394-
if (cache_mngr == NULL ||
7394+
if (cache_mngr == nullptr ||
73957395
DBUG_EVALUATE_IF("simulate_cache_creation_failure", 1, 0)) {
73967396
if (thd->binlog_setup_trx_data() ||
73977397
DBUG_EVALUATE_IF("simulate_cache_creation_failure", 1, 0)) {

sql/daemon_proxy_keyring/daemon_proxy_keyring.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -130,13 +130,13 @@ class Callback {
130130
@return This function always returns true.
131131
*/
132132
static bool key_plugin_cb_fn(THD *, plugin_ref plugin, void *arg) {
133-
plugin = my_plugin_lock(NULL, &plugin);
133+
plugin = my_plugin_lock(nullptr, &plugin);
134134
if (plugin) {
135135
Callback *callback = reinterpret_cast<Callback *>(arg);
136136
callback->invoke(
137137
reinterpret_cast<st_mysql_keyring *>(plugin_decl(plugin)->info));
138138
}
139-
plugin_unlock(NULL, plugin);
139+
plugin_unlock(nullptr, plugin);
140140
// this function should get executed only for the first plugin. This is why
141141
// it always returns error. plugin_foreach will stop after first iteration.
142142
return true;
@@ -786,11 +786,11 @@ mysql_declare_plugin(daemon_keyring_proxy){
786786
"services atop of the keyring plugin",
787787
PLUGIN_LICENSE_GPL,
788788
daemon_keyring_proxy_plugin_init, /* Plugin Init */
789-
NULL, /* Plugin Check uninstall */
789+
nullptr, /* Plugin Check uninstall */
790790
daemon_keyring_proxy_plugin_deinit, /* Plugin Deinit */
791791
0x0100, /* 1.0 */
792-
NULL, /* Status Variables */
793-
NULL, /* System Variables */
794-
NULL, /* Config options */
792+
nullptr, /* Status Variables */
793+
nullptr, /* System Variables */
794+
nullptr, /* Config options */
795795
0, /* Flags */
796796
} mysql_declare_plugin_end;

sql/handler.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -7818,8 +7818,8 @@ int binlog_log_row(TABLE *table, const uchar *before_record,
78187818
try {
78197819
MY_BITMAP save_read_set;
78207820
MY_BITMAP save_write_set;
7821-
if (bitmap_init(&save_read_set, NULL, table->s->fields) ||
7822-
bitmap_init(&save_write_set, NULL, table->s->fields)) {
7821+
if (bitmap_init(&save_read_set, nullptr, table->s->fields) ||
7822+
bitmap_init(&save_write_set, nullptr, table->s->fields)) {
78237823
my_error(ER_OUT_OF_RESOURCES, MYF(0));
78247824
return HA_ERR_RBR_LOGGING_FAILED;
78257825
}

sql/log_event.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -13826,7 +13826,7 @@ uint8 Transaction_payload_log_event::get_mts_dbs(Mts_db_names *arg,
1382613826
[[maybe_unused]]) {
1382713827
Mts_db_names &mts_dbs = m_applier_ctx.get_mts_db_names();
1382813828
if (mts_dbs.num == OVER_MAX_DBS_IN_EVENT_MTS) {
13829-
arg->name[0] = 0;
13829+
arg->name[0] = nullptr;
1383013830
arg->num = OVER_MAX_DBS_IN_EVENT_MTS;
1383113831
} else {
1383213832
for (int i = 0; i < mts_dbs.num; i++) arg->name[i] = mts_dbs.name[i];
@@ -13956,7 +13956,7 @@ bool Transaction_payload_log_event::apply_payload_event(
1395613956
thd->server_id = ev->server_id; // use the original server id for logging
1395713957
thd->unmasked_server_id = ev->common_header->unmasked_server_id;
1395813958
thd->set_time(); // time the query
13959-
thd->lex->set_current_query_block(0);
13959+
thd->lex->set_current_query_block(nullptr);
1396013960
if (!ev->common_header->when.tv_sec)
1396113961
my_micro_time_to_timeval(my_micro_time(), &ev->common_header->when);
1396213962
ev->thd = thd; // because up to this point, ev->thd == 0

sql/mysqld.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10658,7 +10658,7 @@ bool mysqld_get_one_option(int optid,
1065810658
break;
1065910659
case OPT_REPLICA_PARALLEL_WORKERS:
1066010660
if (opt_mts_replica_parallel_workers == 0) {
10661-
push_deprecated_warn(NULL, "--replica-parallel-workers=0",
10661+
push_deprecated_warn(nullptr, "--replica-parallel-workers=0",
1066210662
"'--replica-parallel-workers=1'");
1066310663
}
1066410664
}

sql/opt_hints.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
22

33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -584,7 +584,7 @@ PT_hint *Opt_hints_table::get_complex_hints(opt_hints_enum type) {
584584

585585
bool Opt_hints_table::is_hint_conflicting(Opt_hints_key *key_hint,
586586
opt_hints_enum type) {
587-
if ((key_hint == NULL) && is_specified(type)) return true;
587+
if ((key_hint == nullptr) && is_specified(type)) return true;
588588
return (key_hint && key_hint->is_specified(type));
589589
}
590590

sql/parse_tree_hints.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
22

33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -415,7 +415,8 @@ bool PT_key_level_hint::contextualize(Parse_context *pc) {
415415
if (key_list.empty()) // Table level hint
416416
{
417417
if ((is_compound_hint(type()) &&
418-
tab->get_compound_key_hint(type())->is_hint_conflicting(tab, NULL)) ||
418+
tab->get_compound_key_hint(type())->is_hint_conflicting(tab,
419+
nullptr)) ||
419420
tab->set_switch(switch_on(), type(), false)) {
420421
print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, &table_name.opt_query_block,
421422
&table_name.table, nullptr, this);
@@ -453,7 +454,7 @@ bool PT_key_level_hint::contextualize(Parse_context *pc) {
453454
tab->get_compound_key_hint(type())->is_hint_conflicting(tab, key))) {
454455
is_conflicting = true;
455456
print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, &table_name.opt_query_block,
456-
&table_name.table, NULL, this);
457+
&table_name.table, nullptr, this);
457458
break;
458459
}
459460
key_hints.push_back(key);

sql/parse_tree_nodes.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,7 @@ Sql_cmd *PT_show_engines::make_cmd(THD *thd) {
23372337
LEX *lex = thd->lex;
23382338
lex->sql_command = m_sql_command;
23392339

2340-
if (prepare_schema_table(thd, lex, 0, SCH_ENGINES)) return nullptr;
2340+
if (prepare_schema_table(thd, lex, nullptr, SCH_ENGINES)) return nullptr;
23412341

23422342
return &m_sql_cmd;
23432343
}
@@ -2410,7 +2410,7 @@ Sql_cmd *PT_show_open_tables::make_cmd(THD *thd) {
24102410
}
24112411
lex->query_block->db = m_opt_db;
24122412

2413-
if (prepare_schema_table(thd, lex, 0, SCH_OPEN_TABLES)) return nullptr;
2413+
if (prepare_schema_table(thd, lex, nullptr, SCH_OPEN_TABLES)) return nullptr;
24142414

24152415
return &m_sql_cmd;
24162416
}
@@ -2419,7 +2419,7 @@ Sql_cmd *PT_show_plugins::make_cmd(THD *thd) {
24192419
LEX *lex = thd->lex;
24202420
lex->sql_command = m_sql_command;
24212421

2422-
if (prepare_schema_table(thd, lex, 0, SCH_PLUGINS)) return nullptr;
2422+
if (prepare_schema_table(thd, lex, nullptr, SCH_PLUGINS)) return nullptr;
24232423

24242424
return &m_sql_cmd;
24252425
}
@@ -2464,7 +2464,7 @@ Sql_cmd *PT_show_profile::make_cmd(THD *thd) {
24642464
Parse_context pc(thd, thd->lex->current_query_block());
24652465
if (contextualize_safe(&pc, m_opt_limit_clause)) return nullptr; // OOM
24662466

2467-
if (prepare_schema_table(thd, lex, 0, SCH_PROFILES)) return nullptr;
2467+
if (prepare_schema_table(thd, lex, nullptr, SCH_PROFILES)) return nullptr;
24682468

24692469
return &m_sql_cmd;
24702470
}

sql/persisted_variable.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ int Persisted_variables_cache::init(int *argc, char ***argv) {
256256
MEM_ROOT alloc{key_memory_persisted_variables, 512};
257257
char *ptr, **res, *datadir = nullptr;
258258
char dir[FN_REFLEN] = {0}, local_datadir_buffer[FN_REFLEN] = {0};
259-
const char *dirs = NULL;
259+
const char *dirs = nullptr;
260260
bool persist_load = true;
261261

262262
my_option persist_options[] = {

sql/rpl_handler.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void Delegate::update_plugin_ref_count() {
205205
if (intern_value == DELEGATE_SPIN_LOCK && opt_value == DELEGATE_OS_LOCK) {
206206
for (auto ref : m_acquired_references) {
207207
for (size_t count = ref.second; count != 0; --count)
208-
plugin_unlock(NULL, ref.first);
208+
plugin_unlock(nullptr, ref.first);
209209
}
210210
m_acquired_references.clear();
211211
} else if (intern_value == DELEGATE_OS_LOCK &&
@@ -242,7 +242,7 @@ bool Delegate::use_spin_lock_type() {
242242
}
243243

244244
void Delegate::acquire_plugin_ref_count(Observer_info *info) {
245-
plugin_ref internal_ref = plugin_lock(NULL, &info->plugin);
245+
plugin_ref internal_ref = plugin_lock(nullptr, &info->plugin);
246246
++(m_acquired_references[internal_ref]);
247247
}
248248

sql/rwlock_scoped_lock.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2016, 2022, Oracle and/or its affiliates.
22

33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -46,12 +46,12 @@ rwlock_scoped_lock::rwlock_scoped_lock(mysql_rwlock_t *lock,
4646
if (!mysql_rwlock_wrlock_with_src(lock, file, line)) {
4747
m_lock = lock;
4848
} else
49-
m_lock = NULL;
49+
m_lock = nullptr;
5050
} else {
5151
if (!mysql_rwlock_rdlock_with_src(lock, file, line)) {
5252
m_lock = lock;
5353
} else
54-
m_lock = NULL;
54+
m_lock = nullptr;
5555
}
5656
}
5757

0 commit comments

Comments
 (0)