Skip to content

Commit

Permalink
delete == 0
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed May 24, 2023
1 parent 9b9ca7c commit 569c68a
Show file tree
Hide file tree
Showing 38 changed files with 92 additions and 89 deletions.
8 changes: 4 additions & 4 deletions src/net/src/backend_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BackendThread::BackendThread(ConnFactory* conn_factory, int cron_interval, int k
BackendThread::~BackendThread() = default;

int BackendThread::StartThread() {
if (handle_ == nullptr) {
if (!handle_) {
handle_ = new BackendHandle();
own_handle_ = true;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ Status BackendThread::Connect(const std::string& dst_ip, const int dst_port, int
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;

if (fd == nullptr) {
if (!fd) {
return Status::InvalidArgument("fd argument is nullptr");
}
// We do not handle IPv6
Expand Down Expand Up @@ -194,7 +194,7 @@ Status BackendThread::Connect(const std::string& dst_ip, const int dst_port, int
freeaddrinfo(servinfo);
return s;
}
if (p == nullptr) {
if (!p) {
s = Status::IOError(strerror(errno), "Can't create socket ");
return s;
}
Expand Down Expand Up @@ -390,7 +390,7 @@ void* BackendThread::ThreadMain() {
nfds = net_multiplexer_->NetPoll(timeout);
for (int i = 0; i < nfds; i++) {
pfe = (net_multiplexer_->FiredEvents()) + i;
if (pfe == nullptr) {
if (!pfe) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/net/src/holy_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void HolyThread::HandleNewConn(const int connfd, const std::string& ip_port) {
}

void HolyThread::HandleConnEvent(NetFiredEvent* pfe) {
if (pfe == nullptr) {
if (!pfe) {
return;
}
std::shared_ptr<NetConn> in_conn = nullptr;
Expand Down Expand Up @@ -292,7 +292,7 @@ void HolyThread::ProcessNotifyEvents(const net::NetFiredEvent* pfe) {
} else if (ti.notify_type() == net::kNotiClose) {
LOG(INFO) << "receive noti close";
std::shared_ptr<net::NetConn> conn = get_conn(fd);
if (conn == nullptr) {
if (!conn) {
continue;
}
CloseFd(conn);
Expand Down
2 changes: 1 addition & 1 deletion src/net/src/http_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ bool HTTPRequest::ParseParameters(std::string& data, size_t line_start) {
int HTTPRequest::ParseHeader() {
rbuf_[rbuf_pos_] = '\0'; // Avoid strstr() parsing expire char
char* sep_pos = strstr(rbuf_, "\r\n\r\n");
if (sep_pos == nullptr) {
if (!sep_pos) {
// Haven't find header
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/net/src/net_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ std::string GetIpByInterface(const std::string& network_interface) {

std::string host;
for (ifa = ifAddrStruct; ifa != nullptr; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == nullptr) {
if (!(ifa->ifa_addr)) {
continue;
}

Expand All @@ -141,7 +141,7 @@ std::string GetIpByInterface(const std::string& network_interface) {
freeifaddrs(ifAddrStruct);
}

if (ifa == nullptr) {
if (!ifa) {
LOG(ERROR) << "error network interface: " << network_interface;
}

Expand Down
2 changes: 1 addition & 1 deletion src/net/src/pb_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ReadStatus PbConn::GetRequest() {
uint32_t new_size = header_len_ + COMMAND_HEADER_LENGTH;
if (new_size < kProtoMaxMessage) {
rbuf_ = reinterpret_cast<char*>(realloc(rbuf_, sizeof(char) * new_size));
if (rbuf_ == nullptr) {
if (!rbuf_) {
return kFullError;
}
rbuf_len_ = new_size;
Expand Down
4 changes: 2 additions & 2 deletions src/net/src/redis_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ int RedisCli::ProcessLineItem() {
char* p;
int len;

if ((p = ReadLine(&len)) == nullptr) {
if (!(p = ReadLine(&len))) {
return REDIS_HALF;
}

Expand Down Expand Up @@ -345,7 +345,7 @@ int RedisCli::GetReplyFromReader() {
}

char* p;
if ((p = ReadBytes(1)) == nullptr) {
if (!(p = ReadBytes(1))) {
return REDIS_HALF;
}

Expand Down
2 changes: 1 addition & 1 deletion src/net/src/redis_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ReadStatus RedisConn::GetRequest() {
return kFullError;
}
rbuf_ = static_cast<char*>(realloc(rbuf_, new_size)); // NOLINT
if (rbuf_ == nullptr) {
if (!rbuf_) {
return kFullError;
}
rbuf_len_ = new_size;
Expand Down
2 changes: 1 addition & 1 deletion src/net/src/redis_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void RedisParser::PrintCurrentStatus() {
// }
LOG(INFO) << "cur_pos : " << cur_pos_;
LOG(INFO) << "input_buf_ is clean ? " << (input_buf_ == nullptr);
if (input_buf_ != nullptr) {
if (input_buf_) {
LOG(INFO) << " input_buf " << input_buf_;
}
LOG(INFO) << "half_argv_ : " << half_argv_;
Expand Down
2 changes: 1 addition & 1 deletion src/net/src/server_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DefaultServerHandle : public ServerHandle {
};

static const ServerHandle* SanitizeHandle(const ServerHandle* raw_handle) {
if (raw_handle == nullptr) {
if (!raw_handle) {
return new DefaultServerHandle();
}
return raw_handle;
Expand Down
7 changes: 4 additions & 3 deletions src/net/src/simple_http_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ ReadStatus SimpleHTTPConn::GetRequest() {
// So that strstr will not parse the expire char
rbuf_[rbuf_pos_] = '\0';
char* sep_pos = strstr(rbuf_, "\r\n\r\n");
if (sep_pos == nullptr) {
if (!sep_pos) {
break;
}
header_len_ = sep_pos - rbuf_ + 4;
Expand All @@ -364,8 +364,9 @@ ReadStatus SimpleHTTPConn::GetRequest() {
response_->SetStatusCode(100);
set_is_reply(true);
conn_status_ = kPacket;
if (remain_packet_len_ > 0) { return kReadHalf;
}
if (remain_packet_len_ > 0) {
return kReadHalf;
}
}
conn_status_ = kPacket;
}
Expand Down
2 changes: 1 addition & 1 deletion src/net/src/worker_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void* WorkerThread::ThreadMain() {

for (int i = 0; i < nfds; i++) {
pfe = (net_multiplexer_->FiredEvents()) + i;
if (pfe == nullptr) {
if (!pfe) {
continue;
}
if (pfe->fd == net_multiplexer_->NotifyReceiveFd()) {
Expand Down
2 changes: 1 addition & 1 deletion src/pika_binlog_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Status PikaBinlogReader::Consume(std::string* scratch, uint32_t* filenum, uint64
// Append to scratch;
// the status will be OK, IOError or Corruption, EndFile;
Status PikaBinlogReader::Get(std::string* scratch, uint32_t* filenum, uint64_t* offset) {
if (logger_ == nullptr || queue_ == nullptr) {
if (!logger_ || !queue_) {
return Status::Corruption("Not seek");
}
scratch->clear();
Expand Down
4 changes: 2 additions & 2 deletions src/pika_client_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ void PikaClientConn::DoExecTask(void* arg) {

std::shared_ptr<SyncMasterPartition> partition =
g_pika_rm->GetSyncMasterPartitionByName(PartitionInfo(table_name, partition_id));
if (partition == nullptr) {
if (!partition) {
LOG(WARNING) << "Sync Master Partition not exist " << table_name << partition_id;
return;
}
partition->ConsensusUpdateAppliedIndex(offset);

if (conn_ptr == nullptr || resp_ptr == nullptr) {
if (!conn_ptr || !resp_ptr) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/pika_geohash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void geohashGetCoordRange(GeoHashRange* long_range, GeoHashRange* lat_range) {
int geohashEncode(const GeoHashRange* long_range, const GeoHashRange* lat_range, double longitude, double latitude,
uint8_t step, GeoHashBits* hash) {
/* Check basic arguments sanity. */
if (hash == nullptr || step > 32 || step == 0 || RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) {
if (!hash || step > 32 || step == 0 || RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) {
return 0;
}

Expand Down Expand Up @@ -193,7 +193,7 @@ int geohashDecodeType(const GeoHashBits hash, GeoHashArea* area) {
int geohashDecodeWGS84(const GeoHashBits hash, GeoHashArea* area) { return geohashDecodeType(hash, area); }

int geohashDecodeAreaToLongLat(const GeoHashArea* area, double* xy) {
if (xy == nullptr) {
if (!xy) {
return 0;
}
xy[0] = (area->longitude.min + area->longitude.max) / 2;
Expand All @@ -203,7 +203,7 @@ int geohashDecodeAreaToLongLat(const GeoHashArea* area, double* xy) {

int geohashDecodeToLongLatType(const GeoHashBits hash, double* xy) {
GeoHashArea area = {{0}};
if ((xy == nullptr) || (geohashDecodeType(hash, &area) == 0)) {
if (!xy || !(geohashDecodeType(hash, &area))) {
return 0;
}
return geohashDecodeAreaToLongLat(&area, xy);
Expand Down
2 changes: 1 addition & 1 deletion src/pika_geohash_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ uint8_t geohashEstimateStepsByRadius(double range_meters, double lat) {
* optimization is not used for very big radiuses, however the function
* should be fixed. */
int geohashBoundingBox(double longitude, double latitude, double radius_meters, double* bounds) {
if (bounds == nullptr) {
if (!bounds) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pika_meta.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Status PikaMeta::ParseMeta(std::vector<TableStruct>* const table_structs) {
return Status::Corruption("open local meta file failed");
}

if (reader->GetData() == nullptr) {
if (!reader->GetData()) {
LOG(WARNING) << "Meta file init error";
return Status::Corruption("meta file init error");
}
Expand Down
2 changes: 1 addition & 1 deletion src/pika_repl_bgworker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void PikaReplBgWorker::HandleBGWorkerWriteDB(void* arg) {
if (g_pika_conf->consensus_level() != 0) {
std::shared_ptr<SyncMasterPartition> partition =
g_pika_rm->GetSyncMasterPartitionByName(PartitionInfo(table_name, partition_id));
if (partition == nullptr) {
if (!partition) {
LOG(WARNING) << "Sync Master Partition not exist " << table_name << partition_id;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pika_repl_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ pstd::Status PikaReplServer::Write(const std::string& ip, const int port, const
}
int fd = client_conn_map_[ip_port];
std::shared_ptr<net::PbConn> conn = std::dynamic_pointer_cast<net::PbConn>(pika_repl_server_thread_->get_conn(fd));
if (conn == nullptr) {
if (!conn) {
return Status::NotFound("The" + ip_port + " conn cannot be found");
}

if (conn->WriteResp(msg) != 0) {
if (conn->WriteResp(msg)) {
conn->NotifyClose();
return Status::Corruption("The" + ip_port + " conn, Write Resp Failed");
}
Expand Down
4 changes: 2 additions & 2 deletions src/pika_rm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Status SyncMasterPartition::ActivateSlaveDbSync(const std::string& ip, int port)
Status SyncMasterPartition::ReadBinlogFileToWq(const std::shared_ptr<SlaveNode>& slave_ptr) {
int cnt = slave_ptr->sync_win.Remaining();
std::shared_ptr<PikaBinlogReader> reader = slave_ptr->binlog_reader;
if (reader == nullptr) {
if (!reader) {
return Status::OK();
}
std::vector<WriteTask> tasks;
Expand Down Expand Up @@ -196,7 +196,7 @@ Status SyncMasterPartition::ConsensusUpdateSlave(const std::string& ip, int port

Status SyncMasterPartition::ConsensusUpdateAppliedIndex(const LogOffset& offset) {
std::shared_ptr<Context> context = coordinator_.context();
if (context == nullptr) {
if (!context) {
LOG(WARNING) << "Coordinator context empty.";
return Status::NotFound("context");
}
Expand Down
8 changes: 4 additions & 4 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ bool PikaServer::readonly(const std::string& table_name, const std::string& key)
bool PikaServer::ConsensusCheck(const std::string& table_name, const std::string& key) {
if (g_pika_conf->consensus_level() != 0) {
std::shared_ptr<Table> table = GetTable(table_name);
if (table == nullptr) {
if (!table) {
return false;
}
uint32_t index = g_pika_cmd_table_manager->DistributeKey(key, table->PartitionNum());
Expand Down Expand Up @@ -546,7 +546,7 @@ Status PikaServer::DoSameThingEveryPartition(const TaskType& type) {
case TaskType::kResetReplState: {
slave_partition = g_pika_rm->GetSyncSlavePartitionByName(
PartitionInfo(table_item.second->GetTableName(), partition_item.second->GetPartitionId()));
if (slave_partition == nullptr) {
if (!slave_partition) {
LOG(WARNING) << "Slave Partition: " << table_item.second->GetTableName() << ":"
<< partition_item.second->GetPartitionId() << " Not Found";
}
Expand Down Expand Up @@ -789,7 +789,7 @@ bool PikaServer::AllPartitionConnectSuccess() {
for (const auto& partition_item : table_item.second->partitions_) {
slave_partition = g_pika_rm->GetSyncSlavePartitionByName(
PartitionInfo(table_item.second->GetTableName(), partition_item.second->GetPartitionId()));
if (slave_partition == nullptr) {
if (!slave_partition) {
LOG(WARNING) << "Slave Partition: " << table_item.second->GetTableName() << ":"
<< partition_item.second->GetPartitionId() << ", NotFound";
return false;
Expand Down Expand Up @@ -843,7 +843,7 @@ void PikaServer::ScheduleClientBgThreads(net::TaskFunc func, void* arg, const st
}

size_t PikaServer::ClientProcessorThreadPoolCurQueueSize() {
if (pika_client_processor_ == nullptr) {
if (!pika_client_processor_) {
return 0;
}
return pika_client_processor_->ThreadPoolCurQueueSize();
Expand Down
12 changes: 6 additions & 6 deletions src/pstd/include/pstd_coding.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,47 +89,47 @@ inline uint64_t DecodeFixed64(const char* ptr) {
}

inline void GetFixed16(std::string* dst, uint16_t* value) {
if (dst == nullptr || value == nullptr) {
if (!dst || !value) {
return;
}
*value = DecodeFixed16(dst->data());
dst->erase(0, sizeof(uint16_t));
}

inline void GetFixed32(std::string* dst, uint32_t* value) {
if (dst == nullptr || value == nullptr) {
if (!dst || !value) {
return;
}
*value = DecodeFixed32(dst->data());
dst->erase(0, sizeof(uint32_t));
}

inline void GetFixed64(std::string* dst, uint64_t* value) {
if (dst == nullptr || value == nullptr) {
if (!dst || !value) {
return;
}
*value = DecodeFixed64(dst->data());
dst->erase(0, sizeof(uint64_t));
}

inline void GetFixed16(Slice* dst, uint16_t* value) {
if (dst == nullptr || value == nullptr) {
if (!dst || !value) {
return;
}
*value = DecodeFixed16(dst->data());
dst->remove_prefix(sizeof(uint16_t) / sizeof(char));
}

inline void GetFixed32(Slice* dst, uint32_t* value) {
if (dst == nullptr || value == nullptr) {
if (!dst || !value) {
return;
}
*value = DecodeFixed32(dst->data());
dst->remove_prefix(sizeof(uint32_t) / sizeof(char));
}

inline void GetFixed64(Slice* dst, uint64_t* value) {
if (dst == nullptr || value == nullptr) {
if (!dst || !value) {
return;
}
*value = DecodeFixed64(dst->data());
Expand Down
8 changes: 4 additions & 4 deletions src/pstd/include/pstd_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Status {
static Status Busy(const Slice& msg, const Slice& msg2 = Slice()) { return Status(kBusy, msg, msg2); }

// Returns true if the status indicates success.
bool ok() const { return (state_ == nullptr); }
bool ok() const { return !state_; }

// Returns true if the status indicates a NotFound error.
bool IsNotFound() const { return code() == kNotFound; }
Expand Down Expand Up @@ -102,19 +102,19 @@ class Status {
kBusy = 11
};

Code code() const { return (state_ == nullptr) ? kOk : static_cast<Code>(state_[4]); }
Code code() const { return !state_ ? kOk : static_cast<Code>(state_[4]); }

Status(Code code, const Slice& msg, const Slice& msg2);
static const char* CopyState(const char* s);
};

inline Status::Status(const Status& s) { state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_); }
inline Status::Status(const Status& s) { state_ = !s.state_ ? nullptr : CopyState(s.state_); }
inline void Status::operator=(const Status& s) {
// The following condition catches both aliasing (when this == &s),
// and the common case where both s and *this are ok.
if (state_ != s.state_) {
delete[] state_;
state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_);
state_ = !s.state_ ? nullptr : CopyStte(s.state_);
}
}

Expand Down
Loading

0 comments on commit 569c68a

Please sign in to comment.