diff --git a/src/brpc/builtin/bad_method_service.cpp b/src/brpc/builtin/bad_method_service.cpp
index 346b68d613..5d5ed3260a 100644
--- a/src/brpc/builtin/bad_method_service.cpp
+++ b/src/brpc/builtin/bad_method_service.cpp
@@ -47,7 +47,7 @@ void BadMethodService::no_method(::google::protobuf::RpcController* cntl_base,
os << "Missing method name for service=" << request->service_name() << '.';
const Server::ServiceProperty* sp = ServerPrivateAccessor(server)
.FindServicePropertyAdaptively(request->service_name());
- if (sp != NULL && sp->service != NULL) {
+ if (sp != nullptr && sp->service != nullptr) {
const google::protobuf::ServiceDescriptor* sd =
sp->service->GetDescriptor();
os << " Available methods are: " << newline << newline;
@@ -58,7 +58,7 @@ void BadMethodService::no_method(::google::protobuf::RpcController* cntl_base,
<< ");" << newline;
}
}
- if (sp != NULL && sp->restful_map != NULL) {
+ if (sp != nullptr && sp->restful_map != nullptr) {
os << " This path is associated with a RestfulMap!";
}
cntl->SetFailed(ENOMETHOD, "%s", os.str().c_str());
diff --git a/src/brpc/builtin/bthreads_service.cpp b/src/brpc/builtin/bthreads_service.cpp
index fca86bc6bb..7a2c0835d5 100644
--- a/src/brpc/builtin/bthreads_service.cpp
+++ b/src/brpc/builtin/bthreads_service.cpp
@@ -52,11 +52,11 @@ void BthreadsService::default_method(::google::protobuf::RpcController* cntl_bas
bool enable_trace = false;
#ifdef BRPC_BTHREAD_TRACER
const std::string* st = cntl->http_request().uri().GetQuery("st");
- if (NULL != st && *st == "1") {
+ if (nullptr != st && *st == "1") {
enable_trace = true;
}
#endif // BRPC_BTHREAD_TRACER
- char* endptr = NULL;
+ char* endptr = nullptr;
bthread_t tid = strtoull(constraint.c_str(), &endptr, 10);
if (*endptr == '\0' || *endptr == '/' || *endptr == '?') {
::bthread::print_task(os, tid, enable_trace);
diff --git a/src/brpc/builtin/common.cpp b/src/brpc/builtin/common.cpp
index 8663682d75..d9d90202f3 100644
--- a/src/brpc/builtin/common.cpp
+++ b/src/brpc/builtin/common.cpp
@@ -35,13 +35,13 @@ DEFINE_string(rpc_profiling_dir, "./rpc_data/profiling",
bool UseHTML(const HttpHeader& header) {
const std::string* console = header.uri().GetQuery(CONSOLE_STR);
- if (console != NULL) {
+ if (console != nullptr) {
return atoi(console->c_str()) == 0;
}
// [curl header]
// User-Agent: curl/7.12.1 (x86_64-redhat-linux-gnu) libcurl/7.12.1 ...
const std::string* agent = header.GetHeader(USER_AGENT_STR);
- if (agent == NULL) { // use text when user-agent is absent
+ if (agent == nullptr) { // use text when user-agent is absent
return false;
}
return agent->find("curl/") == std::string::npos;
@@ -50,8 +50,8 @@ bool UseHTML(const HttpHeader& header) {
// Written by Jack Handy
// jakkhandy@hotmail.com
inline bool url_wildcmp(const char* wild, const char* str) {
- const char* cp = NULL;
- const char* mp = NULL;
+ const char* cp = nullptr;
+ const char* mp = nullptr;
while (*str && *wild != '*') {
if (*wild != *str && *wild != '$') {
@@ -384,7 +384,7 @@ const char* GetProgramChecksum() {
bool SupportGzip(Controller* cntl) {
const std::string* encodings =
cntl->http_request().GetHeader("Accept-Encoding");
- if (encodings == NULL) {
+ if (encodings == nullptr) {
return false;
}
return encodings->find("gzip") != std::string::npos;
diff --git a/src/brpc/builtin/common.h b/src/brpc/builtin/common.h
index 0c1af8418b..d2e7787647 100644
--- a/src/brpc/builtin/common.h
+++ b/src/brpc/builtin/common.h
@@ -73,7 +73,7 @@ std::ostream& operator<<(std::ostream& os, const PrintedAsDateTime&);
struct Path {
static const butil::EndPoint *LOCAL;
Path(const char* uri2, const butil::EndPoint* html_addr2)
- : uri(uri2), html_addr(html_addr2), text(NULL) {}
+ : uri(uri2), html_addr(html_addr2), text(nullptr) {}
Path(const char* uri2, const butil::EndPoint* html_addr2, const char* text2)
: uri(uri2), html_addr(html_addr2), text(text2) {}
diff --git a/src/brpc/builtin/connections_service.cpp b/src/brpc/builtin/connections_service.cpp
index 02adc56b38..22786352cb 100644
--- a/src/brpc/builtin/connections_service.cpp
+++ b/src/brpc/builtin/connections_service.cpp
@@ -223,7 +223,7 @@ void ConnectionsService::PrintConnections(
// Special treatment for nshead services. Notice that
// pref_index is comparable to ProtocolType after r31951
if (pref_index == (int)PROTOCOL_NSHEAD &&
- server->options().nshead_service != NULL) {
+ server->options().nshead_service != nullptr) {
if (nshead_service_name.empty()) {
nshead_service_name = BriefName(butil::class_name_str(
*server->options().nshead_service));
@@ -244,7 +244,7 @@ void ConnectionsService::PrintConnections(
ptr->GetStat(&stat);
PrintRealDateTime(os, ptr->_reset_fd_real_us);
int rttfd = ptr->fd();
- if (rttfd < 0 && first_sub != NULL) {
+ if (rttfd < 0 && first_sub != nullptr) {
rttfd = first_sub->fd();
}
diff --git a/src/brpc/builtin/dir_service.cpp b/src/brpc/builtin/dir_service.cpp
index 98973b9641..c292a262d8 100644
--- a/src/brpc/builtin/dir_service.cpp
+++ b/src/brpc/builtin/dir_service.cpp
@@ -48,7 +48,7 @@ void DirService::default_method(::google::protobuf::RpcController* cntl_base,
open_path = "/";
}
DIR* dir = opendir(open_path.c_str());
- if (NULL == dir) {
+ if (nullptr == dir) {
butil::fd_guard fd(open(open_path.c_str(), O_RDONLY));
if (fd < 0) {
cntl->SetFailed(errno, "Cannot open `%s'", open_path.c_str());
@@ -81,7 +81,7 @@ void DirService::default_method(::google::protobuf::RpcController* cntl_base,
cntl->http_response().set_content_type("text/plain");
} else {
const bool use_html = UseHTML(cntl->http_request());
- const butil::EndPoint* const html_addr = (use_html ? Path::LOCAL : NULL);
+ const butil::EndPoint* const html_addr = (use_html ? Path::LOCAL : nullptr);
cntl->http_response().set_content_type(
use_html ? "text/html" : "text/plain");
@@ -90,10 +90,10 @@ void DirService::default_method(::google::protobuf::RpcController* cntl_base,
// readdir_r is marked as deprecated since glibc 2.24.
#if defined(__GLIBC__) && \
(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 24))
- for (struct dirent* p = NULL; (p = readdir(dir)) != NULL; ) {
+ for (struct dirent* p = nullptr; (p = readdir(dir)) != nullptr; ) {
#else
struct dirent entbuf;
- for (struct dirent* p = NULL; readdir_r(dir, &entbuf, &p) == 0 && p; ) {
+ for (struct dirent* p = nullptr; readdir_r(dir, &entbuf, &p) == 0 && p; ) {
#endif
files.push_back(p->d_name);
}
diff --git a/src/brpc/builtin/flags_service.cpp b/src/brpc/builtin/flags_service.cpp
index 1c9075c54e..18152baa86 100644
--- a/src/brpc/builtin/flags_service.cpp
+++ b/src/brpc/builtin/flags_service.cpp
@@ -146,7 +146,7 @@ void FlagsService::default_method(::google::protobuf::RpcController* cntl_base,
cntl->http_response().set_content_type(
use_html ? "text/html" : "text/plain");
- if (value_str != NULL) {
+ if (value_str != nullptr) {
// reload value if ?setvalue=VALUE is present.
if (constraint.empty()) {
cntl->SetFailed(ENOMETHOD, "Require gflag name");
@@ -189,7 +189,7 @@ void FlagsService::default_method(::google::protobuf::RpcController* cntl_base,
std::vector wildcards;
std::set exact;
if (!constraint.empty()) {
- for (butil::StringMultiSplitter sp(constraint.c_str(), ",;"); sp != NULL; ++sp) {
+ for (butil::StringMultiSplitter sp(constraint.c_str(), ",;"); sp != nullptr; ++sp) {
std::string name(sp.field(), sp.length());
if (name.find_first_of("$*") != std::string::npos) {
wildcards.push_back(name);
diff --git a/src/brpc/builtin/flot_min_js.cpp b/src/brpc/builtin/flot_min_js.cpp
index a123b4bc9b..d2680576dd 100644
--- a/src/brpc/builtin/flot_min_js.cpp
+++ b/src/brpc/builtin/flot_min_js.cpp
@@ -25,13 +25,13 @@
namespace brpc {
static pthread_once_t s_flot_min_buf_once = PTHREAD_ONCE_INIT;
-static butil::IOBuf* s_flot_min_buf = NULL;
-static butil::IOBuf* s_flot_min_buf_gzip = NULL;
+static butil::IOBuf* s_flot_min_buf = nullptr;
+static butil::IOBuf* s_flot_min_buf_gzip = nullptr;
static void InitFlotMinBuf() {
s_flot_min_buf = new butil::IOBuf;
s_flot_min_buf->append(flot_min_js());
s_flot_min_buf_gzip = new butil::IOBuf;
- CHECK(policy::GzipCompress(*s_flot_min_buf, s_flot_min_buf_gzip, NULL));
+ CHECK(policy::GzipCompress(*s_flot_min_buf, s_flot_min_buf_gzip, nullptr));
}
const butil::IOBuf& flot_min_js_iobuf() {
pthread_once(&s_flot_min_buf_once, InitFlotMinBuf);
diff --git a/src/brpc/builtin/get_favicon_service.cpp b/src/brpc/builtin/get_favicon_service.cpp
index 64b0d708ed..81ce8e18d9 100644
--- a/src/brpc/builtin/get_favicon_service.cpp
+++ b/src/brpc/builtin/get_favicon_service.cpp
@@ -51,7 +51,7 @@ static unsigned char s_favicon_array[] = {
};
static pthread_once_t s_favicon_buf_once = PTHREAD_ONCE_INIT;
-static butil::IOBuf* s_favicon_buf = NULL;
+static butil::IOBuf* s_favicon_buf = nullptr;
static void InitFavIcon() {
s_favicon_buf = new butil::IOBuf;
s_favicon_buf->append((const void *)s_favicon_array,
diff --git a/src/brpc/builtin/get_js_service.cpp b/src/brpc/builtin/get_js_service.cpp
index 4b3477de9c..ee053edf75 100644
--- a/src/brpc/builtin/get_js_service.cpp
+++ b/src/brpc/builtin/get_js_service.cpp
@@ -63,7 +63,7 @@ void GetJsService::jquery_min(
const std::string* ims =
cntl->http_request().GetHeader("If-Modified-Since");
- if (ims != NULL && *ims == g_last_modified) {
+ if (ims != nullptr && *ims == g_last_modified) {
cntl->http_response().set_status_code(HTTP_STATUS_NOT_MODIFIED);
return;
}
@@ -89,7 +89,7 @@ void GetJsService::flot_min(
const std::string* ims =
cntl->http_request().GetHeader("If-Modified-Since");
- if (ims != NULL && *ims == g_last_modified) {
+ if (ims != nullptr && *ims == g_last_modified) {
cntl->http_response().set_status_code(HTTP_STATUS_NOT_MODIFIED);
return;
}
@@ -115,7 +115,7 @@ void GetJsService::viz_min(
const std::string* ims =
cntl->http_request().GetHeader("If-Modified-Since");
- if (ims != NULL && *ims == g_last_modified) {
+ if (ims != nullptr && *ims == g_last_modified) {
cntl->http_response().set_status_code(HTTP_STATUS_NOT_MODIFIED);
return;
}
diff --git a/src/brpc/builtin/hotspots_service.cpp b/src/brpc/builtin/hotspots_service.cpp
index 8d4d97bc77..2433a1e540 100644
--- a/src/brpc/builtin/hotspots_service.cpp
+++ b/src/brpc/builtin/hotspots_service.cpp
@@ -155,11 +155,11 @@ struct ProfilingEnvironment {
// Different ProfilingType have different env.
static ProfilingEnvironment g_env[5] = {
- { PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL, NULL },
- { PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL, NULL },
- { PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL, NULL },
- { PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL, NULL },
- { PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL, NULL }
+ { PTHREAD_MUTEX_INITIALIZER, 0, nullptr, nullptr, nullptr },
+ { PTHREAD_MUTEX_INITIALIZER, 0, nullptr, nullptr, nullptr },
+ { PTHREAD_MUTEX_INITIALIZER, 0, nullptr, nullptr, nullptr },
+ { PTHREAD_MUTEX_INITIALIZER, 0, nullptr, nullptr, nullptr },
+ { PTHREAD_MUTEX_INITIALIZER, 0, nullptr, nullptr, nullptr }
};
// The `content' should be small so that it can be written into file in one
@@ -175,7 +175,7 @@ static bool WriteSmallFile(const char* filepath_in,
return false;
}
FILE* fp = fopen(path.value().c_str(), "w");
- if (NULL == fp) {
+ if (nullptr == fp) {
LOG(ERROR) << "Fail to open `" << path.value() << '\'';
return false;
}
@@ -199,12 +199,12 @@ static bool WriteSmallFile(const char* filepath_in,
return false;
}
FILE* fp = fopen(path.value().c_str(), "w");
- if (NULL == fp) {
+ if (nullptr == fp) {
LOG(ERROR) << "Fail to open `" << path.value() << '\'';
return false;
}
butil::IOBufAsZeroCopyInputStream iter(content);
- const void* data = NULL;
+ const void* data = nullptr;
int size = 0;
while (iter.Next(&data, &size)) {
if (fwrite(data, size, 1UL, fp) != 1UL) {
@@ -221,8 +221,8 @@ static int ReadSeconds(const Controller* cntl) {
int seconds = DEFAULT_PROFILING_SECONDS;
const std::string* param =
cntl->http_request().uri().GetQuery("seconds");
- if (param != NULL) {
- char* endptr = NULL;
+ if (param != nullptr) {
+ char* endptr = nullptr;
const long sec = strtol(param->c_str(), &endptr, 10);
if (endptr == param->c_str() + param->length()) {
seconds = sec;
@@ -235,8 +235,8 @@ static int ReadSeconds(const Controller* cntl) {
}
static const char* GetBaseName(const std::string* full_base_name) {
- if (full_base_name == NULL) {
- return NULL;
+ if (full_base_name == nullptr) {
+ return nullptr;
}
size_t offset = full_base_name->find_last_of('/');
if (offset == std::string::npos) {
@@ -338,10 +338,10 @@ static void ConsumeWaiters(ProfilingType type, const Controller* cur_cntl,
ProfilingEnvironment& env = g_env[type];
if (env.client) {
BAIDU_SCOPED_LOCK(env.mutex);
- if (env.client == NULL) {
+ if (env.client == nullptr) {
return;
}
- if (env.cached_result == NULL) {
+ if (env.cached_result == nullptr) {
env.cached_result = new ProfilingResult;
}
env.cached_result->id = env.client->id;
@@ -350,7 +350,7 @@ static void ConsumeWaiters(ProfilingType type, const Controller* cur_cntl,
env.cached_result->result = cur_cntl->response_attachment();
delete env.client;
- env.client = NULL;
+ env.client = nullptr;
if (env.waiters) {
env.waiters->swap(*waiters);
}
@@ -360,7 +360,7 @@ static void ConsumeWaiters(ProfilingType type, const Controller* cur_cntl,
// This function is always called with g_env[type].mutex UNLOCKED.
static void NotifyWaiters(ProfilingType type, const Controller* cur_cntl,
const std::string* view) {
- if (view != NULL) {
+ if (view != nullptr) {
return;
}
std::vector saved_waiters;
@@ -380,7 +380,7 @@ static void NotifyWaiters(ProfilingType type, const Controller* cur_cntl,
static const char* s_pprof_binary_path = nullptr;
static bool check_GOOGLE_PPROF_BINARY_PATH() {
char* str = getenv("GOOGLE_PPROF_BINARY_PATH");
- if (str == NULL) {
+ if (str == nullptr) {
return false;
}
butil::fd_guard fd(open(str, O_RDONLY));
@@ -431,7 +431,7 @@ static void DisplayResult(Controller* cntl,
}
#endif
}
- if (base_name != NULL) {
+ if (base_name != nullptr) {
if (!ValidProfilePath(*base_name)) {
return cntl->SetFailed(EINVAL, "Invalid query `base'");
}
@@ -448,7 +448,7 @@ static void DisplayResult(Controller* cntl,
display_type, show_ccount);
// Try to read cache first.
FILE* fp = fopen(expected_result_name, "r");
- if (fp != NULL) {
+ if (fp != nullptr) {
bool succ = false;
char buffer[1024];
while (1) {
@@ -561,7 +561,7 @@ static void DisplayResult(Controller* cntl,
// current profile is.
butil::IOBuf before_label;
butil::IOBuf tmp;
- if (cntl->http_request().uri().GetQuery("view") == NULL) {
+ if (cntl->http_request().uri().GetQuery("view") == nullptr) {
tmp.append(prof_name);
tmp.append("[addToProfEnd]");
}
@@ -670,8 +670,8 @@ static void DoProfiling(ProfilingType type,
int64_t prof_id = 0;
const std::string* prof_id_str =
cntl->http_request().uri().GetQuery("profiling_id");
- if (prof_id_str != NULL) {
- char* endptr = NULL;
+ if (prof_id_str != nullptr) {
+ char* endptr = nullptr;
prof_id = strtoll(prof_id_str->c_str(), &endptr, 10);
LOG_IF(ERROR, *endptr != '\0') << "Invalid profiling_id=" << prof_id;
}
@@ -679,7 +679,7 @@ static void DoProfiling(ProfilingType type,
{
BAIDU_SCOPED_LOCK(g_env[type].mutex);
if (g_env[type].client) {
- if (NULL == g_env[type].waiters) {
+ if (nullptr == g_env[type].waiters) {
g_env[type].waiters = new std::vector;
}
ProfilingWaiter waiter = { cntl, done_guard.release() };
@@ -687,7 +687,7 @@ static void DoProfiling(ProfilingType type,
RPC_VLOG << "Queue request from " << cntl->remote_side();
return;
}
- if (g_env[type].cached_result != NULL &&
+ if (g_env[type].cached_result != nullptr &&
g_env[type].cached_result->id == prof_id) {
cntl->http_response().set_status_code(
g_env[type].cached_result->status_code);
@@ -696,7 +696,7 @@ static void DoProfiling(ProfilingType type,
RPC_VLOG << "Hit cached result, id=" << prof_id;
return;
}
- CHECK(NULL == g_env[type].client);
+ CHECK(nullptr == g_env[type].client);
g_env[type].client = new ProfilingClient;
g_env[type].client->end_us = butil::cpuwide_time_us() + seconds * 1000000L;
g_env[type].client->seconds = seconds;
@@ -736,7 +736,7 @@ static void DoProfiling(ProfilingType type,
}
#endif
if (type == PROFILING_CPU) {
- if ((void*)ProfilerStart == NULL || (void*)ProfilerStop == NULL) {
+ if ((void*)ProfilerStart == nullptr || (void*)ProfilerStop == nullptr) {
os << "CPU profiler is not enabled"
<< (use_html ? "