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 ? "" : "\n"); os.move_to(resp); @@ -787,9 +787,9 @@ static void DoProfiling(ProfilingType type, butil::IOBufProfilerFlush(prof_name); } else if (type == PROFILING_HEAP) { MallocExtension* malloc_ext = MallocExtension::instance(); - if (malloc_ext == NULL || !has_TCMALLOC_SAMPLE_PARAMETER()) { + if (malloc_ext == nullptr || !has_TCMALLOC_SAMPLE_PARAMETER()) { os << "Heap profiler is not enabled"; - if (malloc_ext != NULL) { + if (malloc_ext != nullptr) { os << " (no TCMALLOC_SAMPLE_PARAMETER in env)"; } os << '.' << (use_html ? "" : "\n"); @@ -809,7 +809,7 @@ static void DoProfiling(ProfilingType type, } } else if (type == PROFILING_GROWTH) { MallocExtension* malloc_ext = MallocExtension::instance(); - if (malloc_ext == NULL) { + if (malloc_ext == nullptr) { os << "Growth profiler is not enabled." << (use_html ? "" : "\n"); os.move_to(resp); @@ -921,7 +921,7 @@ static void StartProfiling(ProfilingType type, ProfilingClient profiling_client; size_t nwaiters = 0; ProfilingEnvironment & env = g_env[type]; - if (view == NULL) { + if (view == nullptr) { BAIDU_SCOPED_LOCK(env.mutex); if (env.client) { profiling_client = *env.client; @@ -965,7 +965,7 @@ static void StartProfiling(ProfilingType type, "}\n" "$(function() {\n" " function onDataReceived(data) {\n"; - if (view == NULL) { + if (view == nullptr) { os << " var selEnd = data.indexOf('[addToProfEnd]');\n" " if (selEnd != -1) {\n" @@ -1090,7 +1090,7 @@ static void StartProfiling(ProfilingType type, os << ""; for (size_t i = 0; i < past_profs.size(); ++i) { os << ""; for (size_t i = 0; i' << GetBaseName(&past_profs[i]); @@ -1123,7 +1123,7 @@ static void StartProfiling(ProfilingType type, os << ""; } - if (!enabled && view == NULL) { + if (!enabled && view == nullptr) { os << "

Error: " << type_str << " profiler is not enabled." << extra_desc << "

" "

To enable all profilers, link tcmalloc and define macros BRPC_ENABLE_CPU_PROFILER" @@ -1135,7 +1135,7 @@ static void StartProfiling(ProfilingType type, return; } - if ((type == PROFILING_CPU || type == PROFILING_CONTENTION) && view == NULL) { + if ((type == PROFILING_CPU || type == PROFILING_CONTENTION) && view == nullptr) { if (seconds < 0) { os << "Invalid seconds"; os.move_to(cntl->response_attachment()); @@ -1163,7 +1163,7 @@ static void StartProfiling(ProfilingType type, os << ", showing in about " << wait_seconds << " seconds ..."; } } else { - if ((type == PROFILING_CPU || type == PROFILING_CONTENTION) && view == NULL) { + if ((type == PROFILING_CPU || type == PROFILING_CONTENTION) && view == nullptr) { os << "Profiling " << ProfilingType2String(type) << " for " << seconds << " seconds ..."; } else { diff --git a/src/brpc/builtin/ids_service.cpp b/src/brpc/builtin/ids_service.cpp index ba6a25fb9c..a57941524c 100644 --- a/src/brpc/builtin/ids_service.cpp +++ b/src/brpc/builtin/ids_service.cpp @@ -44,7 +44,7 @@ void IdsService::default_method(::google::protobuf::RpcController* cntl_base, os << "# Use /ids/\n"; bthread::id_pool_status(os); } else { - char* endptr = NULL; + char* endptr = nullptr; bthread_id_t id = { strtoull(constraint.c_str(), &endptr, 10) }; if (*endptr == '\0' || *endptr == '/') { bthread::id_status(id, os); diff --git a/src/brpc/builtin/index_service.cpp b/src/brpc/builtin/index_service.cpp index 3b1aa3bcb5..b7cf160d53 100644 --- a/src/brpc/builtin/index_service.cpp +++ b/src/brpc/builtin/index_service.cpp @@ -54,15 +54,15 @@ void IndexService::default_method(::google::protobuf::RpcController* controller, google::protobuf::Service* svc = server->FindServiceByFullName( StatusService::descriptor()->full_name()); StatusService* st_svc = dynamic_cast(svc); - if (st_svc == NULL) { + if (st_svc == nullptr) { cntl->SetFailed("Fail to find StatusService"); return; } - return st_svc->default_method(cntl, NULL, NULL, done_guard.release()); + return st_svc->default_method(cntl, nullptr, nullptr, done_guard.release()); } cntl->http_response().set_content_type( use_html ? "text/html" : "text/plain"); - const butil::EndPoint* const html_addr = (use_html ? Path::LOCAL : NULL); + const butil::EndPoint* const html_addr = (use_html ? Path::LOCAL : nullptr); const char* const NL = (use_html ? "
\n" : "\n"); const char* const SP = (use_html ? " " : " "); diff --git a/src/brpc/builtin/jquery_min_js.cpp b/src/brpc/builtin/jquery_min_js.cpp index 818e399dc9..27a3015b9f 100644 --- a/src/brpc/builtin/jquery_min_js.cpp +++ b/src/brpc/builtin/jquery_min_js.cpp @@ -25,13 +25,13 @@ namespace brpc { static pthread_once_t s_jquery_min_buf_once = PTHREAD_ONCE_INIT; -static butil::IOBuf* s_jquery_min_buf = NULL; -static butil::IOBuf* s_jquery_min_buf_gzip = NULL; +static butil::IOBuf* s_jquery_min_buf = nullptr; +static butil::IOBuf* s_jquery_min_buf_gzip = nullptr; static void InitJQueryMinBuf() { s_jquery_min_buf = new butil::IOBuf; s_jquery_min_buf->append(jquery_min_js()); s_jquery_min_buf_gzip = new butil::IOBuf; - CHECK(policy::GzipCompress(*s_jquery_min_buf, s_jquery_min_buf_gzip, NULL)); + CHECK(policy::GzipCompress(*s_jquery_min_buf, s_jquery_min_buf_gzip, nullptr)); } const butil::IOBuf& jquery_min_js_iobuf() { pthread_once(&s_jquery_min_buf_once, InitJQueryMinBuf); diff --git a/src/brpc/builtin/pprof_service.cpp b/src/brpc/builtin/pprof_service.cpp index e22144f2ad..3e445a9ce2 100644 --- a/src/brpc/builtin/pprof_service.cpp +++ b/src/brpc/builtin/pprof_service.cpp @@ -58,8 +58,8 @@ static int ReadSeconds(Controller* cntl) { int seconds = 0; 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; @@ -101,7 +101,7 @@ void PProfService::profile( ClosureGuard done_guard(done); Controller* cntl = static_cast(controller_base); cntl->http_response().set_content_type("text/plain"); - if ((void*)ProfilerStart == NULL || (void*)ProfilerStop == NULL) { + if ((void*)ProfilerStart == nullptr || (void*)ProfilerStop == nullptr) { cntl->SetFailed(ENOMETHOD, "%s, to enable cpu profiler, check out " "docs/cn/cpu_profiler.md", berror(ENOMETHOD)); @@ -221,9 +221,9 @@ void PProfService::heap( } MallocExtension* malloc_ext = MallocExtension::instance(); - if (malloc_ext == NULL || !has_TCMALLOC_SAMPLE_PARAMETER()) { + if (malloc_ext == nullptr || !has_TCMALLOC_SAMPLE_PARAMETER()) { const char* extra_desc = ""; - if (malloc_ext != NULL) { + if (malloc_ext != nullptr) { extra_desc = " (no TCMALLOC_SAMPLE_PARAMETER in env)"; } cntl->SetFailed(ENOMETHOD, "Heap profiler is not enabled%s," @@ -255,7 +255,7 @@ void PProfService::growth( ClosureGuard done_guard(done); Controller* cntl = static_cast(controller_base); MallocExtension* malloc_ext = MallocExtension::instance(); - if (malloc_ext == NULL) { + if (malloc_ext == nullptr) { cntl->SetFailed(ENOMETHOD, "%s, to enable growth profiler, check out " "docs/cn/heap_profiler.md", berror(ENOMETHOD)); @@ -312,10 +312,10 @@ static int ExtractSymbolsFromBinary( std::string line; while (std::getline(ss, line)) { butil::StringSplitter sp(line.c_str(), ' '); - if (sp == NULL) { + if (sp == nullptr) { continue; } - char* endptr = NULL; + char* endptr = nullptr; uintptr_t addr = strtoull(sp.field(), &endptr, 16); if (*endptr != ' ') { continue; @@ -327,7 +327,7 @@ static int ExtractSymbolsFromBinary( continue; } ++sp; - if (sp == NULL) { + if (sp == nullptr) { continue; } if (sp.length() != 1UL) { @@ -336,7 +336,7 @@ static int ExtractSymbolsFromBinary( //const char c = *sp.field(); ++sp; - if (sp == NULL) { + if (sp == nullptr) { continue; } const char* name_begin = sp.field(); @@ -403,15 +403,15 @@ static void LoadSymbols() { butil::Timer tm; tm.start(); butil::ScopedFILE fp(fopen("/proc/self/maps", "r")); - if (fp == NULL) { + if (fp == nullptr) { return; } - char* line = NULL; + char* line = nullptr; size_t line_len = 0; ssize_t nr = 0; while ((nr = getline(&line, &line_len, fp.get())) != -1) { butil::StringSplitter sp(line, line + nr, ' '); - if (sp == NULL) { + if (sp == nullptr) { continue; } char* endptr; @@ -426,11 +426,11 @@ static void LoadSymbols() { } ++sp; // ..x. must be executable - if (sp == NULL || sp.length() != 4 || sp.field()[2] != 'x') { + if (sp == nullptr || sp.length() != 4 || sp.field()[2] != 'x') { continue; } ++sp; - if (sp == NULL) { + if (sp == nullptr) { continue; } size_t offset = strtoull(sp.field(), &endptr, 16); @@ -441,7 +441,7 @@ static void LoadSymbols() { for (int i = 0; i < 3; ++i) { ++sp; } - if (sp == NULL) { + if (sp == nullptr) { continue; } size_t n = sp.length(); @@ -551,7 +551,7 @@ void PProfService::symbol( std::vector addr_list; addr_list.reserve(32); butil::StringSplitter sp(addr_cstr, '+'); - for ( ; sp != NULL; ++sp) { + for ( ; sp != nullptr; ++sp) { char* endptr; uintptr_t addr = strtoull(sp.field(), &endptr, 16); addr_list.push_back(addr); diff --git a/src/brpc/builtin/prometheus_metrics_service.cpp b/src/brpc/builtin/prometheus_metrics_service.cpp index 4efc24b9c5..c02e78ddf4 100644 --- a/src/brpc/builtin/prometheus_metrics_service.cpp +++ b/src/brpc/builtin/prometheus_metrics_service.cpp @@ -156,16 +156,16 @@ PrometheusMetricsDumper::ProcessLatencyRecorderSuffix(const butil::StringPiece& if (metric_name.ends_with("_latency")) { metric_name.remove_suffix(8); SummaryItems* si = &_m[metric_name.as_string()]; - si->latency_avg = strtoll(desc_str.data(), NULL, 10); + si->latency_avg = strtoll(desc_str.data(), nullptr, 10); return si; } if (metric_name.ends_with("_count")) { metric_name.remove_suffix(6); SummaryItems* si = &_m[metric_name.as_string()]; - si->count = strtoll(desc_str.data(), NULL, 10); + si->count = strtoll(desc_str.data(), nullptr, 10); return si; } - return NULL; + return nullptr; } bool PrometheusMetricsDumper::DumpLatencyRecorderSuffix( @@ -224,7 +224,7 @@ void PrometheusMetricsService::default_method(::google::protobuf::RpcController* int DumpPrometheusMetricsToIOBuf(butil::IOBuf* output) { butil::IOBufBuilder os; PrometheusMetricsDumper dumper(&os, g_server_info_prefix); - const int ndump = bvar::Variable::dump_exposed(&dumper, NULL); + const int ndump = bvar::Variable::dump_exposed(&dumper, nullptr); if (ndump < 0) { return -1; } @@ -232,7 +232,7 @@ int DumpPrometheusMetricsToIOBuf(butil::IOBuf* output) { if (bvar::FLAGS_bvar_max_dump_multi_dimension_metric_number > 0) { PrometheusMetricsDumper dumper_md(&os, g_server_info_prefix); - const int ndump_md = bvar::MVariableBase::dump_exposed(&dumper_md, NULL); + const int ndump_md = bvar::MVariableBase::dump_exposed(&dumper_md, nullptr); if (ndump_md < 0) { return -1; } diff --git a/src/brpc/builtin/rpcz_service.cpp b/src/brpc/builtin/rpcz_service.cpp index 9afb651ee6..fac905a4c5 100644 --- a/src/brpc/builtin/rpcz_service.cpp +++ b/src/brpc/builtin/rpcz_service.cpp @@ -319,7 +319,7 @@ static void PrintClientSpan( static void PrintClientSpan(std::ostream& os,const RpczSpan& span, bool use_html) { int64_t last_time = span.start_send_real_us(); - PrintClientSpan(os, span, &last_time, NULL, use_html); + PrintClientSpan(os, span, &last_time, nullptr, use_html); } static void PrintBthreadSpan(std::ostream& os, const RpczSpan& span, int64_t* last_time, @@ -465,14 +465,14 @@ static int64_t ParseDateTime(const std::string& time_str) { struct tm timeinfo; int64_t microseconds = 999999; char* endptr = strptime(time_str.c_str(), "%Y/%m/%d-%H:%M:%S", &timeinfo); - if (endptr == NULL) { + if (endptr == nullptr) { time_t now; time(&now); - if (localtime_r(&now, &timeinfo) == NULL) { + if (localtime_r(&now, &timeinfo) == nullptr) { return -1; } endptr = strptime(time_str.c_str(), "%H:%M:%S", &timeinfo); - if (endptr == NULL) { + if (endptr == nullptr) { return -1; } } @@ -487,11 +487,11 @@ static int64_t ParseDateTime(const std::string& time_str) { } static bool ParseUint64(const std::string* str, uint64_t* val) { - if (NULL == str) { + if (nullptr == str) { return false; } const char* p = str->c_str(); - char* endptr = NULL; + char* endptr = nullptr; if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { *val = strtoull(p + 2, &endptr, 16); return (*endptr == '\0'); @@ -601,7 +601,7 @@ void RpczService::default_method(::google::protobuf::RpcController* cntl_base, const std::string* time_str = cntl->http_request().uri().GetQuery(TIME_STR); int64_t start_tm; - if (time_str == NULL) { + if (time_str == nullptr) { start_tm = butil::gettimeofday_us(); } else { start_tm = ParseDateTime(*time_str); diff --git a/src/brpc/builtin/sockets_service.cpp b/src/brpc/builtin/sockets_service.cpp index deedf65d12..c17e86cf6e 100644 --- a/src/brpc/builtin/sockets_service.cpp +++ b/src/brpc/builtin/sockets_service.cpp @@ -40,7 +40,7 @@ void SocketsService::default_method(::google::protobuf::RpcController* cntl_base os << "# Use /sockets/\n" << butil::describe_resources() << '\n'; } else { - char* endptr = NULL; + char* endptr = nullptr; SocketId sid = strtoull(constraint.c_str(), &endptr, 10); if (*endptr == '\0' || *endptr == '/') { Socket::DebugSocket(os, sid); diff --git a/src/brpc/builtin/sorttable_js.cpp b/src/brpc/builtin/sorttable_js.cpp index a37bac749f..8ef8250c25 100644 --- a/src/brpc/builtin/sorttable_js.cpp +++ b/src/brpc/builtin/sorttable_js.cpp @@ -23,7 +23,7 @@ namespace brpc { static pthread_once_t s_sorttable_buf_once = PTHREAD_ONCE_INIT; -static butil::IOBuf* s_sorttable_buf = NULL; +static butil::IOBuf* s_sorttable_buf = nullptr; static void InitSortTableBuf() { s_sorttable_buf = new butil::IOBuf; s_sorttable_buf->append(sorttable_js()); diff --git a/src/brpc/builtin/vars_service.cpp b/src/brpc/builtin/vars_service.cpp index 00235e213e..007b040499 100644 --- a/src/brpc/builtin/vars_service.cpp +++ b/src/brpc/builtin/vars_service.cpp @@ -311,7 +311,7 @@ void VarsService::default_method(::google::protobuf::RpcController* cntl_base, ::google::protobuf::Closure* done) { ClosureGuard done_guard(done); Controller *cntl = static_cast(cntl_base); - if (cntl->http_request().uri().GetQuery("series") != NULL) { + if (cntl->http_request().uri().GetQuery("series") != nullptr) { butil::IOBufBuilder os; bvar::SeriesOptions series_options; const int rc = bvar::Variable::describe_series_exposed( @@ -330,7 +330,7 @@ void VarsService::default_method(::google::protobuf::RpcController* cntl_base, } const bool use_html = UseHTML(cntl->http_request()); bool with_tabs = false; - if (use_html && cntl->http_request().uri().GetQuery("dataonly") == NULL) { + if (use_html && cntl->http_request().uri().GetQuery("dataonly") == nullptr) { with_tabs = true; } cntl->http_response().set_content_type( diff --git a/src/brpc/builtin/viz_min_js.cpp b/src/brpc/builtin/viz_min_js.cpp index 36970ef424..f2400df9fc 100644 --- a/src/brpc/builtin/viz_min_js.cpp +++ b/src/brpc/builtin/viz_min_js.cpp @@ -25,7 +25,7 @@ namespace brpc { static pthread_once_t s_viz_min_buf_once = PTHREAD_ONCE_INIT; -static butil::IOBuf* s_viz_min_buf = NULL; +static butil::IOBuf* s_viz_min_buf = nullptr; static void InitVizMinBuf() { s_viz_min_buf = new butil::IOBuf; s_viz_min_buf->append(viz_min_js()); @@ -38,12 +38,12 @@ const butil::IOBuf& viz_min_js_iobuf() { // viz.js is huge. We separate the creation of gzip version from uncompress // version so that at most time we only keep gzip version in memory. static pthread_once_t s_viz_min_buf_gzip_once = PTHREAD_ONCE_INIT; -static butil::IOBuf* s_viz_min_buf_gzip = NULL; +static butil::IOBuf* s_viz_min_buf_gzip = nullptr; static void InitVizMinBufGzip() { butil::IOBuf viz_min; viz_min.append(viz_min_js()); s_viz_min_buf_gzip = new butil::IOBuf; - CHECK(policy::GzipCompress(viz_min, s_viz_min_buf_gzip, NULL)); + CHECK(policy::GzipCompress(viz_min, s_viz_min_buf_gzip, nullptr)); } const butil::IOBuf& viz_min_js_iobuf_gzip() { pthread_once(&s_viz_min_buf_gzip_once, InitVizMinBufGzip);