Skip to content

Commit

Permalink
[clang-tidy] NO.12 enable modernize-use-nullptr check(PaddlePaddle#5…
Browse files Browse the repository at this point in the history
  • Loading branch information
ccsuzzh authored and cxxly committed Aug 7, 2023
1 parent 59c5dd2 commit b42ef79
Show file tree
Hide file tree
Showing 32 changed files with 433 additions and 421 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ modernize-redundant-void-arg,
-modernize-use-equals-default,
-modernize-use-equals-delete,
-modernize-use-noexcept,
-modernize-use-nullptr,
modernize-use-nullptr,
modernize-use-override,
-modernize-use-transparent-functors,
-modernize-use-uncaught-exceptions,
Expand Down
23 changes: 12 additions & 11 deletions paddle/fluid/framework/data_feed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class BufferedLineFileReader {
int read_lines(T* reader, LineFunc func, int skip_lines) {
int lines = 0;
size_t ret = 0;
char* ptr = NULL;
char* eol = NULL;
char* ptr = nullptr;
char* eol = nullptr;
total_len_ = 0;
error_line_ = 0;

Expand All @@ -70,7 +70,7 @@ class BufferedLineFileReader {
total_len_ += ret;
ptr = buff_;
eol = reinterpret_cast<char*>(memchr(ptr, '\n', ret));
while (eol != NULL) {
while (eol != nullptr) {
int size = static_cast<int>((eol - ptr) + 1);
x.append(ptr, size - 1);
++lines;
Expand Down Expand Up @@ -1106,13 +1106,13 @@ void MultiSlotInMemoryDataFeed::GetMsgFromLogKey(const std::string& log_key,
uint32_t* cmatch,
uint32_t* rank) {
std::string searchid_str = log_key.substr(16, 16);
*search_id = (uint64_t)strtoull(searchid_str.c_str(), NULL, 16);
*search_id = (uint64_t)strtoull(searchid_str.c_str(), nullptr, 16);

std::string cmatch_str = log_key.substr(11, 3);
*cmatch = (uint32_t)strtoul(cmatch_str.c_str(), NULL, 16);
*cmatch = (uint32_t)strtoul(cmatch_str.c_str(), nullptr, 16);

std::string rank_str = log_key.substr(14, 2);
*rank = (uint32_t)strtoul(rank_str.c_str(), NULL, 16);
*rank = (uint32_t)strtoul(rank_str.c_str(), nullptr, 16);
}

int MultiSlotInMemoryDataFeed::ParseInstanceFromSo(
Expand Down Expand Up @@ -1657,8 +1657,8 @@ bool MultiSlotFileInstantDataFeed::Preprocess(const std::string& filename) {
fstat(fd_, &sb);
end_ = static_cast<size_t>(sb.st_size);

buffer_ =
reinterpret_cast<char*>(mmap(NULL, end_, PROT_READ, MAP_PRIVATE, fd_, 0));
buffer_ = reinterpret_cast<char*>(
mmap(nullptr, end_, PROT_READ, MAP_PRIVATE, fd_, 0));
PADDLE_ENFORCE_NE(
buffer_,
MAP_FAILED,
Expand Down Expand Up @@ -2401,11 +2401,12 @@ static void parser_log_key(const std::string& log_key,
uint32_t* cmatch,
uint32_t* rank) {
std::string searchid_str = log_key.substr(16, 16);
*search_id = static_cast<uint64_t>(strtoull(searchid_str.c_str(), NULL, 16));
*search_id =
static_cast<uint64_t>(strtoull(searchid_str.c_str(), nullptr, 16));
std::string cmatch_str = log_key.substr(11, 3);
*cmatch = static_cast<uint32_t>(strtoul(cmatch_str.c_str(), NULL, 16));
*cmatch = static_cast<uint32_t>(strtoul(cmatch_str.c_str(), nullptr, 16));
std::string rank_str = log_key.substr(14, 2);
*rank = static_cast<uint32_t>(strtoul(rank_str.c_str(), NULL, 16));
*rank = static_cast<uint32_t>(strtoul(rank_str.c_str(), nullptr, 16));
}

bool SlotRecordInMemoryDataFeed::ParseOneInstance(const std::string& line,
Expand Down
20 changes: 12 additions & 8 deletions paddle/fluid/framework/io/crypto/aes_cipher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,38 +187,42 @@ void AESCipher::BuildCipher(
m_cipher->reset(new CryptoPP::ECB_Mode<CryptoPP::AES>::Encryption);
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(),
NULL,
nullptr,
CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
} else if (aes_cipher_name_ == "AES_ECB_PKCSPadding" && !for_encrypt) {
m_cipher->reset(new CryptoPP::ECB_Mode<CryptoPP::AES>::Decryption);
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(),
NULL,
nullptr,
CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
} else if (aes_cipher_name_ == "AES_CBC_PKCSPadding" && for_encrypt) {
m_cipher->reset(new CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption);
*need_iv = true;
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(),
NULL,
nullptr,
CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
} else if (aes_cipher_name_ == "AES_CBC_PKCSPadding" && !for_encrypt) {
m_cipher->reset(new CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption);
*need_iv = true;
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(),
NULL,
nullptr,
CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
} else if (aes_cipher_name_ == "AES_CTR_NoPadding" && for_encrypt) {
m_cipher->reset(new CryptoPP::CTR_Mode<CryptoPP::AES>::Encryption);
*need_iv = true;
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(), NULL, CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
*(*m_cipher).get(),
nullptr,
CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
} else if (aes_cipher_name_ == "AES_CTR_NoPadding" && !for_encrypt) {
m_cipher->reset(new CryptoPP::CTR_Mode<CryptoPP::AES>::Decryption);
*need_iv = true;
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(), NULL, CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
*(*m_cipher).get(),
nullptr,
CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
} else {
PADDLE_THROW(paddle::platform::errors::Unimplemented(
"Create cipher error. "
Expand All @@ -236,7 +240,7 @@ void AESCipher::BuildAuthEncCipher(
*need_iv = true;
m_filter->reset(new CryptoPP::AuthenticatedEncryptionFilter(
*(*m_cipher).get(),
NULL,
nullptr,
false,
tag_size_ / 8,
CryptoPP::DEFAULT_CHANNEL,
Expand All @@ -258,7 +262,7 @@ void AESCipher::BuildAuthDecCipher(
*need_iv = true;
m_filter->reset(new CryptoPP::AuthenticatedDecryptionFilter(
*(*m_cipher).get(),
NULL,
nullptr,
CryptoPP::AuthenticatedDecryptionFilter::DEFAULT_FLAGS,
tag_size_ / 8,
CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/io/fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static std::shared_ptr<FILE> fs_open_internal(const std::string& path,
bool is_pipe,
const std::string& mode,
size_t buffer_size,
int* err_no = 0) {
int* err_no = nullptr) {
std::shared_ptr<FILE> fp = nullptr;

if (!is_pipe) {
Expand Down
28 changes: 14 additions & 14 deletions paddle/fluid/framework/io/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int close_open_fds_internal() {
break;
}

linux_dirent* entry = NULL;
linux_dirent* entry = nullptr;

for (int offset = 0; offset < bytes; offset += entry->d_reclen) {
entry = reinterpret_cast<linux_dirent*>(buffer + offset);
Expand Down Expand Up @@ -140,9 +140,9 @@ static int shell_popen_fork_internal(const char* real_cmd,
close_open_fds_internal();

#if defined(PADDLE_WITH_MUSL)
PCHECK(execl("/bin/sh", "sh", "-c", real_cmd, NULL) >= 0);
PCHECK(execl("/bin/sh", "sh", "-c", real_cmd, nullptr) >= 0);
#else
PCHECK(execl("/bin/bash", "bash", "-c", real_cmd, NULL) >= 0);
PCHECK(execl("/bin/bash", "bash", "-c", real_cmd, nullptr) >= 0);
#endif
// Note: just for compilation. the child don't run this line.
_exit(0);
Expand Down Expand Up @@ -179,7 +179,7 @@ std::shared_ptr<FILE> shell_popen(const std::string& cmd,
bool do_write = mode == "w";
if (!(do_read || do_write)) {
*err_no = -1;
return NULL;
return nullptr;
}

VLOG(3) << "Opening pipe[" << cmd << "] with mode[" << mode << "]";
Expand All @@ -189,7 +189,7 @@ std::shared_ptr<FILE> shell_popen(const std::string& cmd,
int pipe_fds[2];
if (pipe(pipe_fds) != 0) {
*err_no = -1;
return NULL;
return nullptr;
}
int parent_end = 0;
int child_end = 0;
Expand All @@ -212,11 +212,11 @@ std::shared_ptr<FILE> shell_popen(const std::string& cmd,

close(child_end);

FILE* fp = NULL;
if ((fp = fdopen(parent_end, mode.c_str())) == NULL) {
FILE* fp = nullptr;
if ((fp = fdopen(parent_end, mode.c_str())) == nullptr) {
*err_no = -1;
signal(SIGCHLD, old_handler);
return NULL;
return nullptr;
}

return {fp, [cmd, child_pid, old_handler, err_no, status](FILE* fp) {
Expand Down Expand Up @@ -281,7 +281,7 @@ static int shell_p2open_fork_internal(const char* real_cmd,
}

close_open_fds_internal();
if (execl("/bin/sh", "sh", "-c", real_cmd, NULL) < 0) {
if (execl("/bin/sh", "sh", "-c", real_cmd, nullptr) < 0) {
return -1;
}
exit(127);
Expand All @@ -302,10 +302,10 @@ std::pair<std::shared_ptr<FILE>, std::shared_ptr<FILE>> shell_p2open(
int pipein_fds[2];
int pipeout_fds[2];
if (pipe(pipein_fds) != 0) {
return {NULL, NULL};
return {nullptr, nullptr};
}
if (pipe(pipeout_fds) != 0) {
return {NULL, NULL};
return {nullptr, nullptr};
}

int child_pid =
Expand All @@ -317,7 +317,7 @@ std::pair<std::shared_ptr<FILE>, std::shared_ptr<FILE>> shell_p2open(
fcntl(pipeout_fds[1], F_SETFD, FD_CLOEXEC);

std::shared_ptr<int> child_life = {
NULL, [child_pid, cmd](void*) {
nullptr, [child_pid, cmd](void*) {
if (shell_verbose()) {
LOG(INFO) << "Closing bidirectional pipe[" << cmd << "]";
}
Expand All @@ -340,9 +340,9 @@ std::pair<std::shared_ptr<FILE>, std::shared_ptr<FILE>> shell_p2open(
}};

FILE* in_fp;
PCHECK((in_fp = fdopen(pipein_fds[0], "r")) != NULL);
PCHECK((in_fp = fdopen(pipein_fds[0], "r")) != nullptr);
FILE* out_fp;
PCHECK((out_fp = fdopen(pipeout_fds[1], "w")) != NULL);
PCHECK((out_fp = fdopen(pipeout_fds[1], "w")) != nullptr);
return {{in_fp, [child_life](FILE* fp) { PCHECK(fclose(fp) == 0); }},
{out_fp, [child_life](FILE* fp) { PCHECK(fclose(fp) == 0); }}};
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class FuseAllReduceOpPass : public ir::Pass {
const platform::BKCLCommunicator *multi_bkcl_ctxs,
#endif
ir::Graph *result) const {
details::FusedAllReduceOpHandle *op_handle = NULL;
details::FusedAllReduceOpHandle *op_handle = nullptr;
if (is_grad_merge) {
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
op_handle = new details::FusedGradMergeAllReduceOpHandle(
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/inference/capi_exp/pd_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ __pd_give PD_Config* PD_ConfigCreate() {
}

void PD_ConfigDestroy(__pd_take PD_Config* pd_config) {
if (pd_config != NULL) {
if (pd_config != nullptr) {
delete reinterpret_cast<Config*>(pd_config);
}
}
Expand Down
5 changes: 3 additions & 2 deletions paddle/fluid/inference/capi_exp/pd_predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ __pd_give PD_IOInfos* PD_PredictorGetInputInfos(

PD_IOInfos* input_infos = new PD_IOInfos;
input_infos->size = names.size();
input_infos->io_info = names.empty() ? NULL : new PD_IOInfo*[names.size()];
input_infos->io_info = names.empty() ? nullptr : new PD_IOInfo*[names.size()];
for (size_t i = 0; i < names.size(); i++) {
const std::string& name = names[i];
input_infos->io_info[i] = new PD_IOInfo;
Expand Down Expand Up @@ -99,7 +99,8 @@ __pd_give PD_IOInfos* PD_PredictorGetOutputInfos(

PD_IOInfos* output_infos = new PD_IOInfos;
output_infos->size = names.size();
output_infos->io_info = names.empty() ? NULL : new PD_IOInfo*[names.size()];
output_infos->io_info =
names.empty() ? nullptr : new PD_IOInfo*[names.size()];
for (size_t i = 0; i < names.size(); i++) {
const std::string& name = names[i];
output_infos->io_info[i] = new PD_IOInfo;
Expand Down
Loading

0 comments on commit b42ef79

Please sign in to comment.