Skip to content

Commit ff9adf6

Browse files
Mixficsolwuxianrong
andauthored
fix: function return value logic and variable initialization (#2176)
* code format * code format --------- Co-authored-by: wuxianrong <[email protected]>
1 parent 3ad5f2f commit ff9adf6

File tree

12 files changed

+48
-49
lines changed

12 files changed

+48
-49
lines changed

src/pika_admin.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ void InfoCmd::InfoKeyspace(std::string& info) {
12731273

12741274
std::string db_name;
12751275
KeyScanInfo key_scan_info;
1276-
int32_t duration;
1276+
int32_t duration = 0;
12771277
std::vector<storage::KeyInfo> key_infos;
12781278
std::stringstream tmp_stream;
12791279
tmp_stream << "# Keyspace"
@@ -1492,8 +1492,7 @@ std::string InfoCmd::CacheStatusToString(int status) {
14921492
}
14931493

14941494
void InfoCmd::Execute() {
1495-
std::shared_ptr<Slot> slot;
1496-
slot = g_pika_server->GetSlotByDBName(db_name_);
1495+
std::shared_ptr<Slot> slot = g_pika_server->GetSlotByDBName(db_name_);
14971496
Do(slot);
14981497
}
14991498

@@ -2129,7 +2128,7 @@ void ConfigCmd::ConfigSet(std::string& ret, std::shared_ptr<Slot> slot) {
21292128
EncodeString(&ret, "max-rsync-parallel-num");
21302129
return;
21312130
}
2132-
long int ival;
2131+
long int ival = 0;
21332132
std::string value = config_args_v_[2];
21342133
if (set_item == "timeout") {
21352134
if (pstd::string2int(value.data(), value.size(), &ival) == 0) {

src/pika_bit.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,13 @@ void BitOpCmd::DoInitial() {
305305
}
306306

307307
dest_key_ = argv_[2];
308-
for (unsigned int i = 3; i <= argv_.size() - 1; i++) {
308+
for (size_t i = 3; i <= argv_.size() - 1; i++) {
309309
src_keys_.emplace_back(argv_[i].data());
310310
}
311311
}
312312

313313
void BitOpCmd::Do(std::shared_ptr<Slot> slot) {
314-
int64_t result_length;
314+
int64_t result_length = 0;
315315
s_ = slot->db()->BitOp(op_, dest_key_, src_keys_, value_to_dest_, &result_length);
316316
if (s_.ok()) {
317317
res_.AppendInteger(result_length);

src/pika_geo.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void GeoPosCmd::DoInitial() {
7878
}
7979

8080
void GeoPosCmd::Do(std::shared_ptr<Slot> slot) {
81-
double score;
81+
double score = 0.0;
8282
res_.AppendArrayLenUint64(members_.size());
8383
for (const auto& member : members_) {
8484
rocksdb::Status s = slot->db()->ZScore(key_, member, &score);
@@ -153,8 +153,8 @@ void GeoDistCmd::DoInitial() {
153153
}
154154

155155
void GeoDistCmd::Do(std::shared_ptr<Slot> slot) {
156-
double first_score;
157-
double second_score;
156+
double first_score = 0.0;
157+
double second_score = 0.0;
158158
double first_xy[2];
159159
double second_xy[2];
160160
rocksdb::Status s = slot->db()->ZScore(key_, first_pos_, &first_score);
@@ -206,7 +206,7 @@ void GeoHashCmd::Do(std::shared_ptr<Slot> slot) {
206206
const char* geoalphabet = "0123456789bcdefghjkmnpqrstuvwxyz";
207207
res_.AppendArrayLenUint64(members_.size());
208208
for (const auto& member : members_) {
209-
double score;
209+
double score = 0.0;
210210
rocksdb::Status s = slot->db()->ZScore(key_, member, &score);
211211
if (s.ok()) {
212212
double xy[2];
@@ -307,7 +307,7 @@ static void GetAllNeighbors(const std::shared_ptr<Slot>& slot, std::string& key,
307307
// Insert into result only if the point is within the search area.
308308
for (auto & score_member : score_members) {
309309
double xy[2];
310-
double real_distance;
310+
double real_distance = 0.0;
311311
GeoHashBits hash = {.bits = static_cast<uint64_t>(score_member.score), .step = GEO_STEP_MAX};
312312
geohashDecodeToLongLatWGS84(hash, xy);
313313
if (geohashGetDistanceIfInRadiusWGS84(longitude, latitude, xy[0], xy[1], distance, &real_distance) != 0) {
@@ -542,7 +542,7 @@ void GeoRadiusByMemberCmd::DoInitial() {
542542
}
543543

544544
void GeoRadiusByMemberCmd::Do(std::shared_ptr<Slot> slot) {
545-
double score;
545+
double score = 0.0;
546546
rocksdb::Status s = slot->db()->ZScore(key_, range_.member, &score);
547547
if (s.ok()) {
548548
double xy[2];

src/pika_hash.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void HIncrbyCmd::DoInitial() {
258258
}
259259

260260
void HIncrbyCmd::Do(std::shared_ptr<Slot> slot) {
261-
int64_t new_value;
261+
int64_t new_value = 0;
262262
s_ = slot->db()->HIncrby(key_, field_, by_, &new_value);
263263
if (s_.ok() || s_.IsNotFound()) {
264264
res_.AppendContent(":" + std::to_string(new_value));

src/pika_kv.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ void MsetCmd::Split(std::shared_ptr<Slot> slot, const HintKeys& hint_keys) {
892892
}
893893

894894
void MsetCmd::Merge() {}
895+
895896
void MsetCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
896897
PikaCmdArgsType set_argv;
897898
set_argv.resize(3);
@@ -938,7 +939,7 @@ void MsetnxCmd::Do(std::shared_ptr<Slot> slot) {
938939
}
939940

940941
void MsetnxCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
941-
if(!success_){
942+
if (!success_) {
942943
//some keys already exist, set operations aborted, no need of binlog
943944
return;
944945
}
@@ -948,7 +949,7 @@ void MsetnxCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
948949
set_argv[0] = "set";
949950
set_cmd_->SetConn(GetConn());
950951
set_cmd_->SetResp(resp_.lock());
951-
for(auto& kv: kvs_){
952+
for (auto& kv: kvs_) {
952953
set_argv[1] = kv.key;
953954
set_argv[2] = kv.value;
954955
set_cmd_->Initial(set_argv, db_name_);
@@ -1031,7 +1032,7 @@ void SetrangeCmd::DoInitial() {
10311032
}
10321033

10331034
void SetrangeCmd::Do(std::shared_ptr<Slot> slot) {
1034-
int32_t new_len;
1035+
int32_t new_len = 0;
10351036
s_ = slot->db()->Setrange(key_, offset_, value_, &new_len);
10361037
if (s_.ok()) {
10371038
res_.AppendInteger(new_len);

src/pika_list.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ void LPushCmd::DoInitial() {
261261
values_.push_back(argv_[pos++]);
262262
}
263263
}
264+
264265
void LPushCmd::Do(std::shared_ptr<Slot> slot) {
265266
uint64_t llen = 0;
266267
s_ = slot->db()->LPush(key_, values_, &llen);
@@ -333,7 +334,7 @@ void BLPopCmd::DoInitial() {
333334
// fetching all keys(*argv_.begin is the command itself and *argv_.end() is the timeout value)
334335
keys_.assign(++argv_.begin(), --argv_.end());
335336
removeDuplicates(keys_);
336-
int64_t timeout;
337+
int64_t timeout = 0;
337338
if (!pstd::string2int(argv_.back().data(), argv_.back().size(), &timeout)) {
338339
res_.SetRes(CmdRes::kInvalidInt);
339340
return;
@@ -691,7 +692,7 @@ void BRPopCmd::DoInitial() {
691692
// fetching all keys(*argv_.begin is the command itself and *argv_.end() is the timeout value)
692693
keys_.assign(++argv_.begin(), --argv_.end());
693694
removeDuplicates(keys_);
694-
int64_t timeout;
695+
int64_t timeout = 0;
695696
if (!pstd::string2int(argv_.back().data(), argv_.back().size(), &timeout)) {
696697
res_.SetRes(CmdRes::kInvalidInt);
697698
return;

src/pika_rm.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ bool SyncMasterSlot::BinlogCloudPurge(uint32_t index) {
343343
if (!s.ok()) {
344344
return false;
345345
}
346-
if (index > boffset.filenum - 10) { // remain some more
346+
if (index > (boffset.filenum - 10)) { // remain some more
347347
return false;
348348
} else {
349349
std::unordered_map<std::string, std::shared_ptr<SlaveNode>> slaves = GetAllSlaveNodes();

src/pika_set.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ void SetOperationCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
332332
del_cmd_->SetResp(resp_.lock());
333333
del_cmd_->DoBinlog(slot);
334334

335-
if(value_to_dest_.size() == 0){
335+
if (value_to_dest_.size() == 0) {
336336
//The union/diff/inter operation got an empty set, just exec del to simulate overwrite an empty set to dest_key
337337
return;
338338
}
@@ -348,8 +348,8 @@ void SetOperationCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
348348
auto& sadd_argv = sadd_cmd_->argv();
349349
size_t data_size = value_to_dest_[0].size();
350350

351-
for(int i = 1; i < value_to_dest_.size(); i++){
352-
if(data_size >= 131072){
351+
for (size_t i = 1; i < value_to_dest_.size(); i++) {
352+
if (data_size >= 131072) {
353353
// If the binlog has reached the size of 128KB. (131,072 bytes = 128KB)
354354
sadd_cmd_->DoBinlog(slot);
355355
sadd_argv.clear();
@@ -547,7 +547,7 @@ void SMoveCmd::DoUpdateCache(std::shared_ptr<Slot> slot) {
547547
}
548548

549549
void SMoveCmd::DoBinlog(const std::shared_ptr<SyncMasterSlot>& slot) {
550-
if(!move_success_){
550+
if (!move_success_) {
551551
//the member is not in the source set, nothing changed
552552
return;
553553
}
@@ -588,7 +588,6 @@ void SRandmemberCmd::DoInitial() {
588588
res_.SetRes(CmdRes::kInvalidInt);
589589
} else {
590590
reply_arr = true;
591-
;
592591
}
593592
}
594593
}

src/pika_slot_command.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ void SlotsMgrtTagOneCmd::Do(std::shared_ptr<Slot> slot) {
11081108
int64_t ret = 0;
11091109
int32_t len = 0;
11101110
int hastag = 0;
1111-
uint32_t crc;
1111+
uint32_t crc = 0;
11121112
std::string detail;
11131113
rocksdb::Status s;
11141114
std::map<storage::DataType, rocksdb::Status> type_status;
@@ -1375,7 +1375,7 @@ void SlotsMgrtAsyncStatusCmd::Do(std::shared_ptr<Slot> slot) {
13751375
std::string status;
13761376
std::string ip;
13771377
int64_t port = -1, slots = -1, moved = -1, remained = -1;
1378-
bool migrating;
1378+
bool migrating = false;
13791379
g_pika_server->GetSlotsMgrtSenderStatus(&ip, &port, &slots, &migrating, &moved, &remained);
13801380
std::string mstatus = migrating ? "yes" : "no";
13811381
res_.AppendArrayLen(5);
@@ -1598,7 +1598,7 @@ void SlotsCleanupCmd::DoInitial() {
15981598

15991599
auto iter = argv_.begin() + 1;
16001600
std::string slot;
1601-
long slotLong;
1601+
long slotLong = 0;
16021602
std::vector<int> slots;
16031603
for (; iter != argv_.end(); iter++) {
16041604
slot = *iter;

src/pika_transaction.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void ExecCmd::Do(std::shared_ptr<Slot> slot) {
4444
auto client_conn = std::dynamic_pointer_cast<PikaClientConn>(conn);
4545
std::vector<CmdRes> res_vec = {};
4646
std::vector<std::shared_ptr<std::string>> resp_strs;
47-
for (int i = 0; i < cmds_.size(); ++i) {
47+
for (size_t i = 0; i < cmds_.size(); ++i) {
4848
resp_strs.emplace_back(std::make_shared<std::string>());
4949
}
5050
auto resp_strs_iter = resp_strs.begin();
@@ -246,9 +246,8 @@ void WatchCmd::Do(std::shared_ptr<Slot> slot) {
246246
}
247247

248248
void WatchCmd::Execute() {
249-
std::shared_ptr<Slot> slot;
250-
slot = g_pika_server->GetSlotByDBName(db_name_);
251-
Do(slot);
249+
std::shared_ptr<Slot> slot = g_pika_server->GetSlotByDBName(db_name_);
250+
Do(slot);
252251
}
253252

254253
void WatchCmd::DoInitial() {

0 commit comments

Comments
 (0)