mapleFU commented on code in PR #1839:
URL: https://github.com/apache/kvrocks/pull/1839#discussion_r1365650827


##########
src/storage/rdb.cc:
##########
@@ -471,7 +475,7 @@ Status RDB::saveRdbObject(int type, const std::string &key, 
const RedisObjValue
     const auto &member_scores = std::get<std::vector<MemberScore>>(obj);
     redis::ZSet zset_db(storage_, ns_);
     uint64_t count = 0;
-    db_status = zset_db.Add(key, ZAddFlags(0), (redis::ZSet::MemberScores 
*)&member_scores, &count);
+    db_status = zset_db.Add(key, ZAddFlags(0), 
const_cast<std::vector<MemberScore> *>(&member_scores), &count);

Review Comment:
   This is a const_cast but I think it's ok to calling it?



##########
src/storage/rdb.cc:
##########
@@ -173,9 +173,13 @@ StatusOr<std::string> RDB::loadEncodedString() {
   }
 
   // Normal string
-  std::vector<char> vec(len);
-  GET_OR_RET(stream_->Read(vec.data(), len));
-  return std::string(vec.data(), len);
+  if (len == 0) {
+    return "";
+  }
+  std::string read_string;
+  read_string.resize(len);
+  GET_OR_RET(stream_->Read(read_string.data(), len));

Review Comment:
   I wonder if it's a RdbStringStream, it might call `memcpy` on 
`std::vector<char>`, and when size is `0`, maybe memcpy will `memcpy` 0 in a 
invalid address, which might be a ub?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to