Skip to content

Commit fa5f3b2

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 client code only, configured with -DWITHOUT_SERVER=1. Change-Id: Ife5021a951294ac1d187fe169ffc8996bffdc52d
1 parent b1c3e73 commit fa5f3b2

27 files changed

+148
-147
lines changed

client/check/mysqlcheck.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2001, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2001, 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,
@@ -126,14 +126,14 @@ static struct my_option my_long_options[] = {
126126
&opt_databases, &opt_databases, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
127127
nullptr, 0, nullptr},
128128
#ifdef NDEBUG
129-
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
130-
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
129+
{"debug", '#', "This is a non-debug version. Catch this and exit.", nullptr,
130+
nullptr, nullptr, GET_DISABLED, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
131131
{"debug-check", OPT_DEBUG_CHECK,
132-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
133-
NO_ARG, 0, 0, 0, 0, 0, 0},
132+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
133+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
134134
{"debug-info", OPT_DEBUG_INFO,
135-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
136-
NO_ARG, 0, 0, 0, 0, 0, 0},
135+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
136+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
137137
#else
138138
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.", nullptr,
139139
nullptr, nullptr, GET_STR, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},

client/client_query_attributes.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2020, 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,
@@ -52,12 +52,12 @@ int client_query_attributes::set_params(MYSQL *mysql) {
5252
}
5353

5454
void client_query_attributes::clear(MYSQL *mysql) {
55-
if (mysql != nullptr) mysql_bind_param(mysql, 0, NULL, NULL);
55+
if (mysql != nullptr) mysql_bind_param(mysql, 0, nullptr, nullptr);
5656
while (count) {
5757
count--;
5858
my_free(const_cast<char *>(names[count]));
5959
my_free(values[count].buffer);
6060
}
6161
memset(&names, 0, sizeof(names));
6262
memset(&values, 0, sizeof(values));
63-
}
63+
}

client/migrate_keyring/components.cc

Lines changed: 3 additions & 3 deletions
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,
@@ -43,7 +43,7 @@ registry_type_t *components_registry = nullptr;
4343
dynamic_loader_type_t *components_dynamic_loader = nullptr;
4444

4545
void init_components_subsystem() {
46-
minimal_chassis_init((&components_registry), NULL);
46+
minimal_chassis_init((&components_registry), nullptr);
4747
components_registry->acquire(
4848
"dynamic_loader",
4949
reinterpret_cast<my_h_service *>(&components_dynamic_loader));
@@ -52,7 +52,7 @@ void init_components_subsystem() {
5252
void deinit_components_subsystem() {
5353
components_registry->release(
5454
reinterpret_cast<my_h_service>(components_dynamic_loader));
55-
minimal_chassis_deinit(components_registry, NULL);
55+
minimal_chassis_deinit(components_registry, nullptr);
5656
}
5757

5858
Keyring_component_load::Keyring_component_load(const std::string component_name,

client/multi_factor_passwordopt-vars.cc

Lines changed: 3 additions & 3 deletions
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,
@@ -29,7 +29,7 @@
2929
#include "mysql.h"
3030
#include "mysql/service_mysql_alloc.h" // my_free, my_strdup
3131

32-
char *opt_password[MAX_AUTH_FACTORS] = {0};
32+
char *opt_password[MAX_AUTH_FACTORS] = {nullptr};
3333
bool tty_password[MAX_AUTH_FACTORS] = {false};
3434

3535
/**
@@ -99,4 +99,4 @@ void free_passwords() {
9999
opt_password[factor - 1] = nullptr;
100100
}
101101
}
102-
}
102+
}

client/mysql.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,13 +1692,14 @@ static struct my_option my_long_options[] = {
16921692
&opt_compress, &opt_compress, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr,
16931693
0, nullptr},
16941694
#ifdef NDEBUG
1695-
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
1696-
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
1695+
{"debug", '#', "This is a non-debug version. Catch this and exit.", nullptr,
1696+
nullptr, nullptr, GET_DISABLED, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
16971697
{"debug-check", OPT_DEBUG_CHECK,
1698-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
1699-
NO_ARG, 0, 0, 0, 0, 0, 0},
1700-
{"debug-info", 'T', "This is a non-debug version. Catch this and exit.", 0,
1701-
0, 0, GET_DISABLED, NO_ARG, 0, 0, 0, 0, 0, 0},
1698+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
1699+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
1700+
{"debug-info", 'T', "This is a non-debug version. Catch this and exit.",
1701+
nullptr, nullptr, nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0,
1702+
nullptr},
17021703
#else
17031704
{"debug", '#', "Output debug log.", &default_dbug_option,
17041705
&default_dbug_option, nullptr, GET_STR, OPT_ARG, 0, 0, 0, nullptr, 0,
@@ -2677,15 +2678,12 @@ static char **new_mysql_completion(const char *text, int start, int end);
26772678
*/
26782679

26792680
#if defined(EDITLINE_HAVE_COMPLETION_CHAR)
2680-
char *no_completion(const char *, int)
2681+
char *no_completion(const char *, int) { return nullptr; }
26812682
#elif defined(EDITLINE_HAVE_COMPLETION_INT)
2682-
int no_completion(const char *, int)
2683+
int no_completion(const char *, int) { return 0; }
26832684
#else
2684-
char *no_completion()
2685+
char *no_completion() { return nullptr; }
26852686
#endif
2686-
{
2687-
return 0; /* No filename completion */
2688-
}
26892687

26902688
/*
26912689
returns 0 if line matches the previous history entry
@@ -4412,7 +4410,7 @@ static int com_query_attributes(String *buffer [[maybe_unused]], char *line) {
44124410

44134411
if (global_attrs->push_param(name, param))
44144412
return put_info("Failed to push a parameter", INFO_ERROR, 0);
4415-
} while (param != 0);
4413+
} while (param != nullptr);
44164414
return 0;
44174415
}
44184416

client/mysql_config_editor.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2012, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2012, 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,
@@ -134,8 +134,8 @@ struct my_command_data {
134134
/* mysql_config_editor utility options. */
135135
static struct my_option my_program_long_options[] = {
136136
#ifdef NDEBUG
137-
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
138-
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
137+
{"debug", '#', "This is a non-debug version. Catch this and exit.", nullptr,
138+
nullptr, nullptr, GET_DISABLED, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
139139
#else
140140
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.", nullptr,
141141
nullptr, nullptr, GET_STR, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},

client/mysqladmin.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,14 @@ static struct my_option my_long_options[] = {
190190
&nr_iterations, &nr_iterations, nullptr, GET_UINT, REQUIRED_ARG, 0, 0, 0,
191191
nullptr, 0, nullptr},
192192
#ifdef NDEBUG
193-
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
194-
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
193+
{"debug", '#', "This is a non-debug version. Catch this and exit.", nullptr,
194+
nullptr, nullptr, GET_DISABLED, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
195195
{"debug-check", OPT_DEBUG_CHECK,
196-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
197-
NO_ARG, 0, 0, 0, 0, 0, 0},
196+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
197+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
198198
{"debug-info", OPT_DEBUG_INFO,
199-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
200-
NO_ARG, 0, 0, 0, 0, 0, 0},
199+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
200+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
201201
#else
202202
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.", nullptr,
203203
nullptr, nullptr, GET_STR, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},

client/mysqlbinlog.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,14 +1816,14 @@ static struct my_option my_long_options[] = {
18161816
&rewrite, &rewrite, nullptr, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, nullptr,
18171817
0, nullptr},
18181818
#ifdef NDEBUG
1819-
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
1820-
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
1819+
{"debug", '#', "This is a non-debug version. Catch this and exit.", nullptr,
1820+
nullptr, nullptr, GET_DISABLED, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
18211821
{"debug-check", OPT_DEBUG_CHECK,
1822-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
1823-
NO_ARG, 0, 0, 0, 0, 0, 0},
1822+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
1823+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
18241824
{"debug-info", OPT_DEBUG_INFO,
1825-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
1826-
NO_ARG, 0, 0, 0, 0, 0, 0},
1825+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
1826+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
18271827
#else
18281828
{"debug", '#', "Output debug log.", &default_dbug_option,
18291829
&default_dbug_option, nullptr, GET_STR, OPT_ARG, 0, 0, 0, nullptr, 0,

client/mysqldump.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,14 @@ static struct my_option my_long_options[] = {
292292
&opt_databases, &opt_databases, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
293293
nullptr, 0, nullptr},
294294
#ifdef NDEBUG
295-
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
296-
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
295+
{"debug", '#', "This is a non-debug version. Catch this and exit.", nullptr,
296+
nullptr, nullptr, GET_DISABLED, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
297297
{"debug-check", OPT_DEBUG_CHECK,
298-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
299-
NO_ARG, 0, 0, 0, 0, 0, 0},
298+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
299+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
300300
{"debug-info", OPT_DEBUG_INFO,
301-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
302-
NO_ARG, 0, 0, 0, 0, 0, 0},
301+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
302+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
303303
#else
304304
{"debug", '#', "Output debug log.", &default_dbug_option,
305305
&default_dbug_option, nullptr, GET_STR, OPT_ARG, 0, 0, 0, nullptr, 0,

client/mysqlimport.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ static struct my_option my_long_options[] = {
108108
&opt_compress, &opt_compress, nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr,
109109
0, nullptr},
110110
#ifdef NDEBUG
111-
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0,
112-
GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
111+
{"debug", '#', "This is a non-debug version. Catch this and exit.", nullptr,
112+
nullptr, nullptr, GET_DISABLED, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
113113
{"debug-check", OPT_DEBUG_CHECK,
114-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
115-
NO_ARG, 0, 0, 0, 0, 0, 0},
114+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
115+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
116116
{"debug-info", OPT_DEBUG_INFO,
117-
"This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED,
118-
NO_ARG, 0, 0, 0, 0, 0, 0},
117+
"This is a non-debug version. Catch this and exit.", nullptr, nullptr,
118+
nullptr, GET_DISABLED, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
119119
#else
120120
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.", nullptr,
121121
nullptr, nullptr, GET_STR, OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},

0 commit comments

Comments
 (0)