Skip to content

Commit

Permalink
Bug #30199590: RUN CLANG-TIDY MODERNIZE-USE-NULLPTR
Browse files Browse the repository at this point in the history
Another cross-cutting, large-scale clang-tidy fix. It runs the
“modernize-use-nullptr” fixit over all source code compiled in a fairly
full-featured MySQL build, changing 0 literals (in pointer context)
and NULL to nullptr. A typical example would be:

-  mysql_options(connection, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
+  mysql_options(connection, MYSQL_OPT_CONNECT_ATTR_RESET, nullptr);

as the third argument to mysql_options() is a void *.

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.

Change-Id: Ic863d0a52a78b46f6345e3b69b60bd3dab317e9a
  • Loading branch information
Steinar H. Gunderson committed Oct 11, 2019
1 parent 593c148 commit 08f46b3
Show file tree
Hide file tree
Showing 1,337 changed files with 29,760 additions and 28,934 deletions.
12 changes: 6 additions & 6 deletions client/base/abstract_option.h
Expand Up @@ -126,7 +126,7 @@ T_type *Abstract_option<T_type>::set_short_character(char code) {
this->m_option_structure.id = (int)code;

// Inform that it has changed
if (this->m_option_changed_listener != NULL) {
if (this->m_option_changed_listener != nullptr) {
this->m_option_changed_listener->notify_option_optid_changed(this,
old_optid);
}
Expand All @@ -139,12 +139,12 @@ Abstract_option<T_type>::Abstract_option(void *value, ulong var_type,
std::string name,
std::string description,
longlong default_value)
: m_option_changed_listener(NULL) {
: m_option_changed_listener(nullptr) {
this->m_option_structure.block_size = 0;
this->m_option_structure.max_value = 0;
this->m_option_structure.min_value = 0;
this->m_option_structure.typelib = NULL;
this->m_option_structure.u_max_value = NULL;
this->m_option_structure.typelib = nullptr;
this->m_option_structure.u_max_value = nullptr;

this->m_option_structure.app_type = this;
this->m_option_structure.arg_type = REQUIRED_ARG;
Expand All @@ -166,7 +166,7 @@ Abstract_option<T_type>::Abstract_option(void *value, ulong var_type,

this->m_option_structure.value = value;
this->m_option_structure.var_type = var_type;
this->m_option_structure.arg_source = 0;
this->m_option_structure.arg_source = nullptr;
}

template <typename T_type>
Expand All @@ -177,7 +177,7 @@ my_option Abstract_option<T_type>::get_my_option() {
template <typename T_type>
void Abstract_option<T_type>::set_option_changed_listener(
I_option_changed_listener *listener) {
DBUG_ASSERT(this->m_option_changed_listener == NULL);
DBUG_ASSERT(this->m_option_changed_listener == nullptr);

this->m_option_changed_listener = listener;
}
Expand Down
10 changes: 5 additions & 5 deletions client/base/abstract_options_provider.cc
@@ -1,5 +1,5 @@
/*
Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -122,7 +122,7 @@ vector<my_option> Abstract_options_provider::generate_options() {
void Abstract_options_provider::options_parsed() {}

Abstract_options_provider::Abstract_options_provider()
: m_are_options_created(false), m_option_changed_listener(NULL) {}
: m_are_options_created(false), m_option_changed_listener(nullptr) {}

Abstract_options_provider::~Abstract_options_provider() {
for (vector<I_option *>::iterator it = this->m_options_created.begin();
Expand All @@ -133,7 +133,7 @@ Abstract_options_provider::~Abstract_options_provider() {

void Abstract_options_provider::set_option_changed_listener(
I_option_changed_listener *listener) {
DBUG_ASSERT(this->m_option_changed_listener == NULL);
DBUG_ASSERT(this->m_option_changed_listener == nullptr);
this->m_option_changed_listener = listener;
}

Expand Down Expand Up @@ -163,7 +163,7 @@ void Abstract_options_provider::notify_option_name_changed(I_option *source,
this->m_name_usage.insert(std::make_pair(new_name, source));

// If we have listener we should inform it too.
if (this->m_option_changed_listener != NULL) {
if (this->m_option_changed_listener != nullptr) {
this->m_option_changed_listener->notify_option_name_changed(source,
old_name);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ void Abstract_options_provider::notify_option_optid_changed(I_option *source,
this->m_optid_usage.insert(std::make_pair(new_optid, source));

// If we have listener we should inform it too.
if (this->m_option_changed_listener != NULL) {
if (this->m_option_changed_listener != nullptr) {
this->m_option_changed_listener->notify_option_optid_changed(source,
old_optid);
}
Expand Down
6 changes: 4 additions & 2 deletions client/base/abstract_program.cc
Expand Up @@ -41,7 +41,7 @@ bool Abstract_program::callback_option_parsed(int, const struct my_option *opt,
// Check if option uses My::Tools::Base::Options, and it should.
Options::I_option *app_type = (Options::I_option *)opt->app_type;
Options::I_option *option = dynamic_cast<Options::I_option *>(app_type);
if (option != NULL) {
if (option != nullptr) {
option->call_callbacks(argument);
}
return false;
Expand Down Expand Up @@ -127,7 +127,9 @@ void Abstract_program::aggregate_options() {
&Abstract_program::options_by_name_comparer);

// Adding sentinel, handle_options assume input as array with sentinel.
my_option sentinel = {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0};
my_option sentinel = {nullptr, 0, nullptr, nullptr, nullptr,
nullptr, GET_NO_ARG, NO_ARG, 0, 0,
0, nullptr, 0, nullptr};
this->m_options.push_back(sentinel);
}

Expand Down
6 changes: 3 additions & 3 deletions client/base/abstract_string_option.h
@@ -1,5 +1,5 @@
/*
Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -77,7 +77,7 @@ Abstract_string_option<T_type>::Abstract_string_option(
description, (uint64)NULL),
m_destination_value(value) {
*value = Nullable<std::string>();
this->m_original_value = NULL;
this->m_original_value = nullptr;

this->add_callback(new std::function<void(char *)>(
std::bind(&Abstract_string_option<T_type>::string_callback, this,
Expand All @@ -95,7 +95,7 @@ T_type *Abstract_string_option<T_type>::set_value(std::string value) {

template <typename T_type>
void Abstract_string_option<T_type>::string_callback(char *argument) {
if (argument != NULL) {
if (argument != nullptr) {
// Copy argument value from char* to destination string.
*this->m_destination_value = Nullable<std::string>(this->m_original_value);
} else {
Expand Down
4 changes: 2 additions & 2 deletions client/base/char_array_option.cc
@@ -1,5 +1,5 @@
/*
Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -33,7 +33,7 @@ Char_array_option::Char_array_option(char **value, bool allocated, string name,
string description)
: Abstract_value_option<char *>(value, allocated ? GET_STR_ALLOC : GET_STR,
name, description, (uint64)NULL) {
*value = NULL;
*value = nullptr;
}

Char_array_option *Char_array_option::set_value(char *value) {
Expand Down
4 changes: 2 additions & 2 deletions client/base/composite_options_provider.cc
@@ -1,5 +1,5 @@
/*
Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -45,7 +45,7 @@ void Composite_options_provider::add_providers(I_options_provider *first, ...) {
for (;;) {
Options::I_options_provider *options_provider =
va_arg(options_to_add, I_options_provider *);
if (options_provider == NULL) {
if (options_provider == nullptr) {
break;
}

Expand Down
4 changes: 2 additions & 2 deletions client/base/debug_options.cc
Expand Up @@ -36,13 +36,13 @@ using namespace Mysql::Tools::Base::Options;
using Mysql::Tools::Base::Abstract_program;
using std::placeholders::_1;

static Debug_options *primary_debug_options = NULL;
static Debug_options *primary_debug_options = nullptr;
static uint my_end_arg;

static void debug_do_exit() { my_end(::my_end_arg); }

Debug_options::Debug_options(Abstract_program *program) : m_program(program) {
if (::primary_debug_options == NULL) {
if (::primary_debug_options == nullptr) {
primary_debug_options = this;
/*
We don't want to call this routine in destructor, as we want it being
Expand Down
4 changes: 2 additions & 2 deletions client/base/disabled_option.cc
@@ -1,5 +1,5 @@
/*
Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -30,7 +30,7 @@ using std::string;
using namespace Mysql::Tools::Base::Options;

Disabled_option::Disabled_option(string name, string description)
: Abstract_option<Disabled_option>(NULL, GET_DISABLED, name, description,
: Abstract_option<Disabled_option>(nullptr, GET_DISABLED, name, description,
0) {
this->m_option_structure.arg_type = OPT_ARG;
}
27 changes: 14 additions & 13 deletions client/base/mysql_connection_options.cc
Expand Up @@ -52,7 +52,7 @@ Mysql_connection_options::Mysql_connection_options(Abstract_program *program)
: m_ssl_options_provider(), m_program(program), m_protocol(0) {
if (Mysql_connection_options::mysql_inited == false) {
Mysql_connection_options::mysql_inited = true;
mysql_library_init(0, NULL, NULL);
mysql_library_init(0, nullptr, nullptr);
atexit(atexit_mysql_library_end);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ void Mysql_connection_options::create_options() {
}

MYSQL *Mysql_connection_options::create_connection() {
MYSQL *connection = mysql_init(NULL);
MYSQL *connection = mysql_init(nullptr);
if (this->m_compress) mysql_options(connection, MYSQL_OPT_COMPRESS, NullS);

if (this->m_compress_algorithm.has_value())
Expand All @@ -152,7 +152,7 @@ MYSQL *Mysql_connection_options::create_connection() {
&this->m_zstd_compress_level);

if (this->m_ssl_options_provider.apply_for_connection(connection))
return NULL;
return nullptr;

if (this->m_protocol)
mysql_options(connection, MYSQL_OPT_PROTOCOL, (char *)&this->m_protocol);
Expand All @@ -178,7 +178,7 @@ MYSQL *Mysql_connection_options::create_connection() {
mysql_options(connection, MYSQL_DEFAULT_AUTH,
this->m_default_auth.value().c_str());

mysql_options(connection, MYSQL_OPT_CONNECT_ATTR_RESET, 0);
mysql_options(connection, MYSQL_OPT_CONNECT_ATTR_RESET, nullptr);
mysql_options4(connection, MYSQL_OPT_CONNECT_ATTR_ADD, "program_name",
this->m_program->get_name().c_str());

Expand All @@ -190,21 +190,22 @@ MYSQL *Mysql_connection_options::create_connection() {
set_get_server_public_key_option(connection,
&this->m_get_server_public_key);

if (!mysql_real_connect(
connection, this->get_null_or_string(this->m_host),
this->get_null_or_string(this->m_user),
this->get_null_or_string(this->m_password), NULL, this->m_mysql_port,
this->get_null_or_string(this->m_mysql_unix_port), 0)) {
if (!mysql_real_connect(connection, this->get_null_or_string(this->m_host),
this->get_null_or_string(this->m_user),
this->get_null_or_string(this->m_password), nullptr,
this->m_mysql_port,
this->get_null_or_string(this->m_mysql_unix_port),
0)) {
this->db_error(connection, "while connecting to the MySQL server");
mysql_close(connection);
return NULL;
return nullptr;
}

/* Reset auto-commit to the default */
if (mysql_autocommit(connection, true)) {
this->db_error(connection, "while resetting auto-commit");
mysql_close(connection);
return NULL;
return nullptr;
}

return connection;
Expand All @@ -214,7 +215,7 @@ CHARSET_INFO *Mysql_connection_options::get_current_charset() const {
return m_default_charset.has_value()
? get_charset_by_csname(m_default_charset.value().c_str(),
MY_CS_PRIMARY, MYF(MY_WME))
: NULL;
: nullptr;
}

void Mysql_connection_options::set_current_charset(CHARSET_INFO *charset) {
Expand All @@ -226,7 +227,7 @@ const char *Mysql_connection_options::get_null_or_string(
if (maybe_string.has_value()) {
return maybe_string.value().c_str();
} else {
return NULL;
return nullptr;
}
}

Expand Down
16 changes: 8 additions & 8 deletions client/base/mysql_query_runner.cc
@@ -1,5 +1,5 @@
/*
Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -125,12 +125,12 @@ int64 Mysql_query_runner::run_query_unguarded(string query) {

MYSQL_RES *results = mysql_use_result(m_connection);

if (results != NULL) {
if (results != nullptr) {
for (;;) {
// Feed result callbacks with results.
MYSQL_ROW row = mysql_fetch_row(results);

if (row == NULL) {
if (row == nullptr) {
// NULL row indicates end of rows or error
if (mysql_errno(m_connection) == 0)
break;
Expand Down Expand Up @@ -160,7 +160,7 @@ int64 Mysql_query_runner::run_query_unguarded(string query) {

// Get all notes, warnings and errors of last query.
if (0 != mysql_query(m_connection, "SHOW WARNINGS") ||
NULL == (results = mysql_use_result(m_connection))) {
nullptr == (results = mysql_use_result(m_connection))) {
this->report_mysql_error();
return 0;
}
Expand All @@ -170,7 +170,7 @@ int64 Mysql_query_runner::run_query_unguarded(string query) {
// Feed message callbacks with results.
MYSQL_ROW row = mysql_fetch_row(results);

if (row == NULL) {
if (row == nullptr) {
// End of rows or an error.
if (mysql_errno(m_connection) != 0) this->report_mysql_error();
break;
Expand Down Expand Up @@ -297,7 +297,7 @@ void Mysql_query_runner::cleanup_result(

Mysql_query_runner::Row::Row(MYSQL_RES *mysql_result_info,
unsigned int column_count, MYSQL_ROW row)
: m_buffer(NULL),
: m_buffer(nullptr),
m_buffer_capacity(0),
m_buffer_size(0),
m_mysql_result_info(mysql_result_info) {
Expand All @@ -315,7 +315,7 @@ Mysql_query_runner::Row::Row(MYSQL_RES *mysql_result_info,
}

Mysql_query_runner::Row::~Row() {
if (m_buffer != NULL) free(m_buffer);
if (m_buffer != nullptr) free(m_buffer);
}

std::string Mysql_query_runner::Row::operator[](std::size_t index) const {
Expand All @@ -325,7 +325,7 @@ std::string Mysql_query_runner::Row::operator[](std::size_t index) const {
}

void Mysql_query_runner::Row::push_back(char *buff, std::size_t length) {
if (buff != NULL) {
if (buff != nullptr) {
// Prepare buffer to be able to contain new data.
this->reserve(m_buffer_starts.size(), m_buffer_size + length + 1);
// Copy data.
Expand Down
4 changes: 2 additions & 2 deletions client/base/password_option.cc
Expand Up @@ -49,7 +49,7 @@ void Password_option::password_callback(char *argument) {
argument = const_cast<char *>("");
}

if (argument != NULL) {
if (argument != nullptr) {
/*
Destroy argument value, this modifies part of argv passed to main
routine. This makes command line on linux changed, so no user can see
Expand All @@ -66,7 +66,7 @@ void Password_option::password_callback(char *argument) {
*/
if (*argument) argument[1] = 0;
} else {
char *password = ::get_tty_password(NULL);
char *password = ::get_tty_password(nullptr);
*this->m_destination_value = Nullable<string>(password);
my_free(password);
}
Expand Down
5 changes: 3 additions & 2 deletions client/base/simple_option.cc
@@ -1,5 +1,5 @@
/*
Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -30,6 +30,7 @@ using namespace Mysql::Tools::Base::Options;
using std::string;

Simple_option::Simple_option(string name, string description)
: Abstract_option<Simple_option>(NULL, GET_NO_ARG, name, description, 0) {
: Abstract_option<Simple_option>(nullptr, GET_NO_ARG, name, description,
0) {
this->m_option_structure.arg_type = NO_ARG;
}

0 comments on commit 08f46b3

Please sign in to comment.