Skip to content

Commit 51c1e05

Browse files
author
Tor Didriksen
committed
Bug#35599395 Change literal 0 to nullptr where appropriate
We have run several rounds of clang-tidy modernize-use-nullptr. There are however some usage of 0 rather than nullptr left, notably in macros. Build with gcc -Wzero-as-null-pointer-constant to find them. Disable -Wzero-as-null-pointer-constant for 3rd party code. Change-Id: I20b129571441d0628ff94ae6e43bb5674fb741ea
1 parent 4ffe64f commit 51c1e05

File tree

34 files changed

+251
-232
lines changed

34 files changed

+251
-232
lines changed

client/mysqldump.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@ static struct my_option my_long_options[] = {
524524
0, 0, nullptr, 0, nullptr},
525525
#include "multi_factor_passwordopt-longopts.h"
526526
#ifdef _WIN32
527-
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
528-
NO_ARG, 0, 0, 0, 0, 0, 0},
527+
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, nullptr,
528+
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
529529
#endif
530530
{"port", 'P', "Port number to use for connection.", &opt_mysql_port,
531531
&opt_mysql_port, nullptr, GET_UINT, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
@@ -568,8 +568,8 @@ static struct my_option my_long_options[] = {
568568
#if defined(_WIN32)
569569
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
570570
"Base name of shared memory.", &shared_memory_base_name,
571-
&shared_memory_base_name, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0,
572-
0},
571+
&shared_memory_base_name, nullptr, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0,
572+
0, 0},
573573
#endif
574574
/*
575575
Note that the combination --single-transaction --master-data
@@ -681,7 +681,8 @@ static struct my_option my_long_options[] = {
681681
nullptr, nullptr, nullptr, GET_STR, REQUIRED_ARG, 0, 0, 0, nullptr, 0,
682682
nullptr},
683683
{"ignore-views", 0, "Skip dumping table views.", &opt_ignore_views,
684-
&opt_ignore_views, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
684+
&opt_ignore_views, nullptr, GET_BOOL, OPT_ARG, 0, 0, 0, nullptr, 0,
685+
nullptr},
685686
#include "authentication_kerberos_clientopt-longopts.h"
686687
{nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0,
687688
0, nullptr, 0, nullptr}};

components/test/event_tracking_test/event_tracking_producer_a.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ bool Event_producer::generate_events() {
358358
{
359359
mysql_event_tracking_parse_data parse_data;
360360
parse_data.connection_id = 1;
361-
parse_data.flags = 0;
361+
parse_data.flags = nullptr;
362362
parse_data.query = CSTRING_WITH_LENGTH("SELECT * FROM demodb.demo_table");
363363

364364
my_service<SERVICE_TYPE(event_tracking_parse)> parse_service(

extra/icu/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ IF(APPLE)
6262
LIST(APPEND ICU_LINUX_COMPILE_OPTIONS "-Wno-deprecated-declarations")
6363
ENDIF()
6464

65+
MY_CHECK_CXX_COMPILER_WARNING("-Wzero-as-null-pointer-constant" HAS_WARN_FLAG)
66+
IF(HAS_WARN_FLAG)
67+
LIST(APPEND ICU_LINUX_COMPILE_OPTIONS "${HAS_WARN_FLAG}")
68+
ENDIF()
69+
6570
MY_CHECK_CXX_COMPILER_WARNING("-Wreturn-local-addr" HAS_WARN_FLAG)
6671
IF(HAS_WARN_FLAG)
6772
LIST(APPEND ICU_LINUX_COMPILE_OPTIONS "${HAS_WARN_FLAG}")

extra/protobuf/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ ELSE()
4343
STRING_APPEND(CMAKE_CXX_FLAGS " -Wno-unused-function")
4444
ENDIF()
4545

46+
MY_CHECK_CXX_COMPILER_WARNING("-Wzero-as-null-pointer-constant" HAS_WARN_FLAG)
47+
IF(HAS_WARN_FLAG)
48+
LIST(APPEND ICU_LINUX_COMPILE_OPTIONS "${HAS_WARN_FLAG}")
49+
ENDIF()
50+
4651
MY_CHECK_CXX_COMPILER_WARNING("-Wmissing-profile" HAS_MISSING_PROFILE)
4752
IF(HAS_MISSING_PROFILE)
4853
STRING_APPEND(CMAKE_CXX_FLAGS " ${HAS_MISSING_PROFILE}")

extra/rapidjson/include/rapidjson/pointer.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1206,22 +1206,22 @@ typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document, c
12061206
//////////////////////////////////////////////////////////////////////////////
12071207

12081208
template <typename T>
1209-
typename T::ValueType* GetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, size_t* unresolvedTokenIndex = 0) {
1209+
typename T::ValueType* GetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, size_t* unresolvedTokenIndex = nullptr) {
12101210
return pointer.Get(root, unresolvedTokenIndex);
12111211
}
12121212

12131213
template <typename T>
1214-
const typename T::ValueType* GetValueByPointer(const T& root, const GenericPointer<typename T::ValueType>& pointer, size_t* unresolvedTokenIndex = 0) {
1214+
const typename T::ValueType* GetValueByPointer(const T& root, const GenericPointer<typename T::ValueType>& pointer, size_t* unresolvedTokenIndex = nullptr) {
12151215
return pointer.Get(root, unresolvedTokenIndex);
12161216
}
12171217

12181218
template <typename T, typename CharType, size_t N>
1219-
typename T::ValueType* GetValueByPointer(T& root, const CharType (&source)[N], size_t* unresolvedTokenIndex = 0) {
1219+
typename T::ValueType* GetValueByPointer(T& root, const CharType (&source)[N], size_t* unresolvedTokenIndex = nullptr) {
12201220
return GenericPointer<typename T::ValueType>(source, N - 1).Get(root, unresolvedTokenIndex);
12211221
}
12221222

12231223
template <typename T, typename CharType, size_t N>
1224-
const typename T::ValueType* GetValueByPointer(const T& root, const CharType(&source)[N], size_t* unresolvedTokenIndex = 0) {
1224+
const typename T::ValueType* GetValueByPointer(const T& root, const CharType(&source)[N], size_t* unresolvedTokenIndex = nullptr) {
12251225
return GenericPointer<typename T::ValueType>(source, N - 1).Get(root, unresolvedTokenIndex);
12261226
}
12271227

include/my_dbug.h

+13-13
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,22 @@ class AutoDebugTrace {
161161
_db_return_(__LINE__, &_db_stack_frame_); \
162162
return; \
163163
} while (0)
164-
#define DBUG_EXECUTE(keyword, a1) \
165-
do { \
166-
if (_db_keyword_(0, (keyword), 0)) { \
167-
a1 \
168-
} \
164+
#define DBUG_EXECUTE(keyword, a1) \
165+
do { \
166+
if (_db_keyword_(nullptr, (keyword), 0)) { \
167+
a1 \
168+
} \
169169
} while (0)
170-
#define DBUG_EXECUTE_IF(keyword, a1) \
171-
do { \
172-
if (_db_keyword_(0, (keyword), 1)) { \
173-
a1 \
174-
} \
170+
#define DBUG_EXECUTE_IF(keyword, a1) \
171+
do { \
172+
if (_db_keyword_(nullptr, (keyword), 1)) { \
173+
a1 \
174+
} \
175175
} while (0)
176176
#define DBUG_EVALUATE(keyword, a1, a2) \
177-
(_db_keyword_(0, (keyword), 0) ? (a1) : (a2))
177+
(_db_keyword_(nullptr, (keyword), 0) ? (a1) : (a2))
178178
#define DBUG_EVALUATE_IF(keyword, a1, a2) \
179-
(_db_keyword_(0, (keyword), 1) ? (a1) : (a2))
179+
(_db_keyword_(nullptr, (keyword), 1) ? (a1) : (a2))
180180
#define DBUG_PRINT(keyword, arglist) \
181181
do { \
182182
_db_pargs_(__LINE__, keyword); \
@@ -195,7 +195,7 @@ class AutoDebugTrace {
195195
#define DBUG_END() _db_end_()
196196
#define DBUG_LOCK_FILE _db_lock_file_()
197197
#define DBUG_UNLOCK_FILE _db_unlock_file_()
198-
#define DBUG_EXPLAIN(buf, len) _db_explain_(0, (buf), (len))
198+
#define DBUG_EXPLAIN(buf, len) _db_explain_(nullptr, (buf), (len))
199199
#define DBUG_EXPLAIN_INITIAL(buf, len) _db_explain_init_((buf), (len))
200200
#ifndef _WIN32
201201
#define DBUG_ABORT() (_db_flush_(), my_abort())

include/my_tree.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void delete_tree(TREE *);
8585
void reset_tree(TREE *);
8686
/* similar to delete tree, except we do not my_free() blocks in mem_root
8787
*/
88-
#define is_tree_inited(tree) ((tree)->root != 0)
88+
inline bool is_tree_inited(TREE *tree) { return tree->root != nullptr; }
8989

9090
/* Functions on leafs */
9191
TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size,

include/mysql/components/library_mysys/instrumented_mutex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace mysql {
5050
class mutex {
5151
public:
5252
mutex(PSI_mutex_key key) noexcept : m_key(key) {
53-
mysql_mutex_init(m_key, &m_mtx, 0);
53+
mysql_mutex_init(m_key, &m_mtx, nullptr);
5454
}
5555
mutex(const mutex &) = delete;
5656
~mutex() { mysql_mutex_destroy(&m_mtx); }

include/mysql/plugin.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,11 @@ struct MYSQL_XID {
159159
builtin_##NAME##_sizeof_struct_st_plugin, \
160160
builtin_##NAME##_plugin)
161161

162-
#define mysql_declare_plugin_end \
163-
, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } \
162+
#define mysql_declare_plugin_end \
163+
, { \
164+
0, nullptr, nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, \
165+
nullptr, nullptr, nullptr, 0 \
166+
} \
164167
}
165168

166169
/*

include/sql_common.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,21 @@ struct MYSQL_METHODS {
238238
ulong *res);
239239
};
240240

241-
#define simple_command(mysql, command, arg, length, skip_check) \
242-
((mysql)->methods \
243-
? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
244-
length, skip_check, NULL) \
245-
: (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
241+
#define simple_command(mysql, command, arg, length, skip_check) \
242+
((mysql)->methods \
243+
? (*(mysql)->methods->advanced_command)(mysql, command, nullptr, 0, \
244+
arg, length, skip_check, NULL) \
245+
: (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
246246
1))
247247
#define simple_command_nonblocking(mysql, command, arg, length, skip_check, \
248248
error) \
249249
(*(mysql)->methods->advanced_command_nonblocking)( \
250-
mysql, command, 0, 0, arg, length, skip_check, NULL, error)
250+
mysql, command, nullptr, 0, arg, length, skip_check, nullptr, error)
251251

252252
#define stmt_command(mysql, command, arg, length, stmt) \
253253
((mysql)->methods \
254-
? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
255-
length, 1, stmt) \
254+
? (*(mysql)->methods->advanced_command)(mysql, command, nullptr, 0, \
255+
arg, length, 1, stmt) \
256256
: (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
257257
1))
258258

libs/mysql/binlog/event/wrapper_functions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ inline char *strndup(const char *s, size_t n) {
126126
if (n < len) len = n;
127127

128128
result = (char *)malloc(len + 1);
129-
if (!result) return 0;
129+
if (!result) return nullptr;
130130

131131
result[len] = '\0';
132132
return (char *)memcpy(result, s, len);

plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_memory.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
#define X_FREE(x) \
3131
{ \
3232
free(x); \
33-
x = 0; \
33+
x = nullptr; \
3434
}
3535
#define XCOM_XDR_FREE(proc, ptr) \
3636
{ \
3737
xcom_xdr_free((xdrproc_t)proc, (char *)(ptr)); \
38-
(ptr) = 0; \
38+
(ptr) = nullptr; \
3939
}
4040

4141
void xcom_xdr_free(xdrproc_t f, char *p);

plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xcom_transport.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ static inline int old_proto_knows(xcom_proto x_proto [[maybe_unused]],
518518
}
519519

520520
static xdrproc_t pax_msg_func[] = {
521-
reinterpret_cast<xdrproc_t>(0),
521+
nullptr,
522522
reinterpret_cast<xdrproc_t>(xdr_pax_msg_1_0),
523523
reinterpret_cast<xdrproc_t>(xdr_pax_msg_1_1),
524524
reinterpret_cast<xdrproc_t>(xdr_pax_msg_1_2),

plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/xdr_utils.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ extern "C" u_long xdr_sizeof(xdrproc_t, void *);
4848
*/
4949
#define def_free_xdr_array(name) \
5050
static inline void free_##name##_array(name##_array *x)
51-
#define free_xdr_array(name) \
52-
def_free_xdr_array(name) { \
53-
free(x->name##_array_val); \
54-
x->name##_array_val = 0; \
55-
x->name##_array_len = 0; \
51+
#define free_xdr_array(name) \
52+
def_free_xdr_array(name) { \
53+
free(x->name##_array_val); \
54+
x->name##_array_val = nullptr; \
55+
x->name##_array_len = 0; \
5656
}
5757

5858
/**

plugin/x/protocol/stream/compression/compression_algorithm_zlib.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ namespace protocol {
3737
class Compression_algorithm_zlib : public Compression_algorithm_interface {
3838
public:
3939
explicit Compression_algorithm_zlib(const int32_t level) {
40-
m_stream.zalloc = Z_NULL;
41-
m_stream.zfree = Z_NULL;
42-
m_stream.opaque = Z_NULL;
40+
m_stream.zalloc = nullptr;
41+
m_stream.zfree = nullptr;
42+
m_stream.opaque = nullptr;
4343
m_stream.avail_in = 0;
4444
m_stream.avail_out = 0;
45-
m_stream.next_in = Z_NULL;
46-
m_stream.next_out = Z_NULL;
45+
m_stream.next_in = nullptr;
46+
m_stream.next_out = nullptr;
4747
deflateInit(&m_stream, level);
4848
}
4949

plugin/x/protocol/stream/compression/decompression_algorithm_zlib.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ namespace protocol {
3535
class Decompression_algorithm_zlib : public Decompression_algorithm_interface {
3636
public:
3737
Decompression_algorithm_zlib() {
38-
m_zstream.zalloc = Z_NULL;
39-
m_zstream.zfree = Z_NULL;
40-
m_zstream.opaque = Z_NULL;
38+
m_zstream.zalloc = nullptr;
39+
m_zstream.zfree = nullptr;
40+
m_zstream.opaque = nullptr;
4141
m_zstream.avail_in = 0;
42-
m_zstream.next_in = Z_NULL;
42+
m_zstream.next_in = nullptr;
4343
m_zstream.avail_out = 0;
4444
inflateInit(&m_zstream);
4545
}

plugin/x/src/ngs/protocol_flusher_compression.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class Compression_deflate : public ::protocol::Compression_buffer_interface {
4848
public:
4949
explicit Compression_deflate(const int32_t level) {
5050
DBUG_TRACE;
51-
m_stream.zalloc = Z_NULL;
52-
m_stream.zfree = Z_NULL;
53-
m_stream.opaque = Z_NULL;
51+
m_stream.zalloc = nullptr;
52+
m_stream.zfree = nullptr;
53+
m_stream.opaque = nullptr;
5454

5555
m_error = Z_OK != deflateInit(&m_stream, level);
5656
}

sql-common/client_authentication.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ net_async_status sha256_password_auth_client_nonblocking(MYSQL_PLUGIN_VIO *vio,
576576

577577
err:
578578
if (got_public_key_from_server) free_rsa_key(ctx);
579-
result = CR_ERROR;
579+
*result = CR_ERROR;
580580
return NET_ASYNC_COMPLETE;
581581
}
582582
/* caching_sha2_password */
@@ -1030,7 +1030,7 @@ net_async_status caching_sha2_password_auth_client_nonblocking(
10301030

10311031
err:
10321032
if (got_public_key_from_server) free_rsa_key(ctx);
1033-
result = CR_ERROR;
1033+
*result = CR_ERROR;
10341034
return NET_ASYNC_COMPLETE;
10351035
}
10361036

0 commit comments

Comments
 (0)