This is an automated email from the ASF dual-hosted git repository.

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new ac3cf3c4 Fix cppcoreguidelines-init-variables warning reported by 
clang-tidy (#1153)
ac3cf3c4 is described below

commit ac3cf3c47f43cbd112189843ae4604301618d96d
Author: Maxim Smolskiy <[email protected]>
AuthorDate: Sat Dec 3 18:03:11 2022 +0300

    Fix cppcoreguidelines-init-variables warning reported by clang-tidy (#1153)
    
    Co-authored-by: Twice <[email protected]>
---
 .clang-tidy                               |  2 +-
 src/common/io_util.cc                     |  8 ++++----
 src/common/sha1.cc                        |  8 ++++----
 src/common/string_util.cc                 |  4 ++--
 src/config/config.cc                      |  4 ++--
 src/config/config_util.cc                 |  2 +-
 src/server/redis_connection.cc            |  6 +++---
 src/server/server.cc                      | 12 ++++++------
 src/server/worker.cc                      |  8 ++++----
 src/stats/log_collector.cc                |  4 ++--
 src/storage/redis_db.cc                   |  2 +-
 src/storage/redis_metadata.cc             | 10 +++++-----
 src/storage/scripting.cc                  | 24 ++++++++++++------------
 src/storage/storage.cc                    |  8 ++++----
 src/storage/table_properties_collector.cc |  8 ++++----
 src/types/geohash.cc                      |  6 +++---
 src/types/redis_bitmap.cc                 |  8 ++++----
 src/types/redis_bitmap_string.cc          | 12 ++++++------
 src/types/redis_geo.cc                    | 12 ++++++------
 src/types/redis_list.cc                   |  8 ++++----
 src/types/redis_set.cc                    |  2 +-
 src/types/redis_sortedint.cc              |  4 ++--
 src/types/redis_stream_base.cc            |  2 +-
 src/types/redis_string.cc                 |  6 +++---
 src/types/redis_zset.cc                   | 10 +++++-----
 25 files changed, 90 insertions(+), 90 deletions(-)

diff --git a/.clang-tidy b/.clang-tidy
index a6091926..5653281b 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,7 +1,7 @@
 # refer to https://clang.llvm.org/extra/clang-tidy/checks/list.html
 Checks: -*, clang-analyzer-core.*, clang-analyzer-cplusplus.*, 
clang-analyzer-deadcode.*, clang-analyzer-nullability.*, 
clang-analyzer-security.*, clang-analyzer-unix.*, clang-analyzer-valist.*, 
cppcoreguidelines-init-variables, cppcoreguidelines-macro-usage, 
cppcoreguidelines-interfaces-global-init, 
cppcoreguidelines-narrowing-conversions, cppcoreguidelines-no-malloc, 
cppcoreguidelines-prefer-member-initializer, 
cppcoreguidelines-special-member-functions, cppcoreguidelines-slicing, goog 
[...]
 
-WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, 
cppcoreguidelines-interfaces-global-init, cppcoreguidelines-no-malloc, 
cppcoreguidelines-slicing, google-*, modernize-use-emplace, 
modernize-use-equals-default, modernize-use-equals-delete, 
performance-implicit-conversion-in-loop, performance-inefficient-algorithm, 
performance-move-constructor-init, performance-no-automatic-move, 
performance-trivially-destructible, performance-type-promotion-in-math-fn, 
perfor [...]
+WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, 
cppcoreguidelines-interfaces-global-init, cppcoreguidelines-no-malloc, 
cppcoreguidelines-slicing, google-*, modernize-use-emplace, 
modernize-use-equals-default, modernize-use-equals-delete, 
performance-implicit-conversion-in-loop, performance-inefficient-algorithm, 
performance-move-constructor-init, performance-no-automatic-move, 
performance-trivially-destructible, performance-type-promotion-in-math-fn, 
perfor [...]
 
 CheckOptions:
   - key:           
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
diff --git a/src/common/io_util.cc b/src/common/io_util.cc
index 43fa1be6..e30ca915 100644
--- a/src/common/io_util.cc
+++ b/src/common/io_util.cc
@@ -51,7 +51,7 @@
 
 namespace Util {
 Status SockConnect(const std::string &host, uint32_t port, int *fd) {
-  addrinfo hints, *servinfo, *p;
+  addrinfo hints, *servinfo = nullptr, *p = nullptr;
 
   memset(&hints, 0, sizeof(hints));
   hints.ai_family = AF_UNSPEC;
@@ -160,7 +160,7 @@ Status SockConnect(const std::string &host, uint32_t port, 
int *fd, uint64_t con
       return Status::FromErrno();
     }
 
-    int socket_arg;
+    int socket_arg = 0;
     // Set to blocking mode again...
     if ((socket_arg = fcntl(*fd, F_GETFL, NULL)) < 0) {
       return Status::FromErrno();
@@ -236,7 +236,7 @@ Status SockSendFile(int out_fd, int in_fd, size_t size) {
 }
 
 Status SockSetBlocking(int fd, int blocking) {
-  int flags;
+  int flags = 0;
   // Old flags
   if ((flags = fcntl(fd, F_GETFL)) == -1) {
     return Status(Status::NotOK, std::string("fcntl(F_GETFL): ") + 
strerror(errno));
@@ -318,7 +318,7 @@ bool IsPortInUse(int port) {
  * writable/readable/exception */
 int aeWait(int fd, int mask, uint64_t timeout) {
   pollfd pfd;
-  int retmask = 0, retval;
+  int retmask = 0, retval = 0;
 
   memset(&pfd, 0, sizeof(pfd));
   pfd.fd = fd;
diff --git a/src/common/sha1.cc b/src/common/sha1.cc
index 4a434622..89808a06 100644
--- a/src/common/sha1.cc
+++ b/src/common/sha1.cc
@@ -78,7 +78,7 @@ A million repetitions of "a"
 /* Hash a single 512-bit block. This is the core of the algorithm. */
 
 void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) {
-  uint32_t a, b, c, d, e;
+  uint32_t a = 0, b = 0, c = 0, d = 0, e = 0;
   union CHAR64LONG16 {
     unsigned char c[64];
     uint32_t l[16];
@@ -209,7 +209,7 @@ void SHA1Init(SHA1_CTX* context) {
 /* Run your data through this. */
 
 void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len) {
-  uint32_t i, j;
+  uint32_t i = 0, j = 0;
 
   j = context->count[0];
   if ((context->count[0] += len << 3) < j) context->count[1]++;
@@ -230,9 +230,9 @@ void SHA1Update(SHA1_CTX* context, const unsigned char* 
data, uint32_t len) {
 
 /* Add padding and return the message digest. */
 void SHA1Final(unsigned char digest[20], SHA1_CTX* context) {
-  unsigned i;
+  unsigned i = 0;
   unsigned char finalcount[8];
-  unsigned char c;
+  unsigned char c = 0;
 
   for (i = 0; i < 8; i++) {
     finalcount[i] =
diff --git a/src/common/string_util.cc b/src/common/string_util.cc
index 204307de..f4a48736 100644
--- a/src/common/string_util.cc
+++ b/src/common/string_util.cc
@@ -143,7 +143,7 @@ int StringMatchLen(const char *pattern, int patternLen, 
const char *string, int
         stringLen--;
         break;
       case '[': {
-        int not_symbol, match;
+        int not_symbol = 0, match = 0;
 
         pattern++;
         patternLen--;
@@ -268,7 +268,7 @@ std::vector<std::string> TokenizeRedisProtocol(const 
std::string &value) {
   enum ParserState { stateArrayLen, stateBulkLen, stateBulkData };
   uint64_t array_len = 0, bulk_len = 0;
   int state = stateArrayLen;
-  const char *start = value.data(), *end = start + value.size(), *p;
+  const char *start = value.data(), *end = start + value.size(), *p = nullptr;
   while (start != end) {
     switch (state) {
       case stateArrayLen: {
diff --git a/src/config/config.cc b/src/config/config.cc
index 09058b8c..8982a7a9 100644
--- a/src/config/config.cc
+++ b/src/config/config.cc
@@ -262,7 +262,7 @@ void Config::initFieldValidator() {
          if (args.size() != 2) {
            return Status(Status::NotOK, "invalid range format, the range 
should be between 0 and 24");
          }
-         int64_t start, stop;
+         int64_t start = 0, stop = 0;
          Status s = Util::DecimalStringToNum(args[0], &start, 0, 24);
          if (!s.IsOK()) return s;
          s = Util::DecimalStringToNum(args[1], &stop, 0, 24);
@@ -517,7 +517,7 @@ void Config::initFieldCallback() {
          if (!RocksDB.enable_blob_files) {
            return Status(Status::NotOK, errNotEnableBlobDB);
          }
-         int val;
+         int val = 0;
          auto parse_result = ParseInt<int>(v, 10);
          if (!parse_result) {
            return Status(Status::NotOK, "Illegal 
blob_garbage_collection_age_cutoff value.");
diff --git a/src/config/config_util.cc b/src/config/config_util.cc
index f4edf44e..9a07657c 100644
--- a/src/config/config_util.cc
+++ b/src/config/config_util.cc
@@ -34,7 +34,7 @@ StatusOr<ConfigKV> ParseConfigLine(const std::string& line) {
     ERROR             // error state, e.g. encounter more than one value
   } state = PRE_KEY_SPACE;
 
-  char quote;  // single or double quote
+  char quote = 0;  // single or double quote
   std::string current_str;
   ConfigKV res;
 
diff --git a/src/server/redis_connection.cc b/src/server/redis_connection.cc
index 1cec1317..2f5b7770 100644
--- a/src/server/redis_connection.cc
+++ b/src/server/redis_connection.cc
@@ -36,7 +36,7 @@ namespace Redis {
 
 Connection::Connection(bufferevent *bev, Worker *owner)
     : bev_(bev), req_(owner->svr_), owner_(owner), svr_(owner->svr_) {
-  time_t now;
+  time_t now = 0;
   time(&now);
   create_time_ = now;
   last_interaction_ = now;
@@ -133,7 +133,7 @@ void Connection::SetAddr(std::string ip, int port) {
 }
 
 uint64_t Connection::GetAge() {
-  time_t now;
+  time_t now = 0;
   time(&now);
   return static_cast<uint64_t>(now - create_time_);
 }
@@ -141,7 +141,7 @@ uint64_t Connection::GetAge() {
 void Connection::SetLastInteraction() { time(&last_interaction_); }
 
 uint64_t Connection::GetIdleTime() {
-  time_t now;
+  time_t now = 0;
   time(&now);
   return static_cast<uint64_t>(now - last_interaction_);
 }
diff --git a/src/server/server.cc b/src/server/server.cc
index b05189b4..43003cc6 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -701,9 +701,9 @@ void Server::GetRocksDBInfo(std::string *info) {
   std::ostringstream string_stream;
   rocksdb::DB *db = storage_->GetDB();
 
-  uint64_t memtable_sizes, cur_memtable_sizes, num_snapshots, 
num_running_flushes;
-  uint64_t num_immutable_tables, memtable_flush_pending, compaction_pending;
-  uint64_t num_running_compaction, num_live_versions, num_superversion, 
num_backgroud_errors;
+  uint64_t memtable_sizes = 0, cur_memtable_sizes = 0, num_snapshots = 0, 
num_running_flushes = 0;
+  uint64_t num_immutable_tables = 0, memtable_flush_pending = 0, 
compaction_pending = 0;
+  uint64_t num_running_compaction = 0, num_live_versions = 0, num_superversion 
= 0, num_backgroud_errors = 0;
 
   db->GetAggregatedIntProperty("rocksdb.num-snapshots", &num_snapshots);
   db->GetAggregatedIntProperty("rocksdb.size-all-mem-tables", &memtable_sizes);
@@ -719,7 +719,7 @@ void Server::GetRocksDBInfo(std::string *info) {
 
   string_stream << "# RocksDB\r\n";
   for (const auto &cf_handle : *storage_->GetCFHandles()) {
-    uint64_t estimate_keys, block_cache_usage, block_cache_pinned_usage, 
index_and_filter_cache_usage;
+    uint64_t estimate_keys = 0, block_cache_usage = 0, 
block_cache_pinned_usage = 0, index_and_filter_cache_usage = 0;
     std::map<std::string, std::string> cf_stats_map;
     db->GetIntProperty(cf_handle, "rocksdb.estimate-num-keys", &estimate_keys);
     string_stream << "estimate_keys[" << cf_handle->GetName() << "]:" << 
estimate_keys << "\r\n";
@@ -771,7 +771,7 @@ void Server::GetRocksDBInfo(std::string *info) {
 }
 
 void Server::GetServerInfo(std::string *info) {
-  time_t now;
+  time_t now = 0;
   std::ostringstream string_stream;
   static int call_uname = 1;
   static utsname name;
@@ -825,7 +825,7 @@ void Server::GetMemoryInfo(std::string *info) {
 }
 
 void Server::GetReplicationInfo(std::string *info) {
-  time_t now;
+  time_t now = 0;
   std::ostringstream string_stream;
   string_stream << "# Replication\r\n";
   string_stream << "role:" << (IsSlave() ? "slave" : "master") << "\r\n";
diff --git a/src/server/worker.cc b/src/server/worker.cc
index 0d4d32cb..80a9a921 100644
--- a/src/server/worker.cc
+++ b/src/server/worker.cc
@@ -123,7 +123,7 @@ void Worker::newTCPConnection(evconnlistener *listener, 
evutil_socket_t fd, sock
   event_base *base = evconnlistener_get_base(listener);
   auto evThreadSafeFlags = BEV_OPT_THREADSAFE | BEV_OPT_DEFER_CALLBACKS | 
BEV_OPT_UNLOCK_CALLBACKS;
 
-  bufferevent *bev;
+  bufferevent *bev = nullptr;
 #ifdef ENABLE_OPENSSL
   SSL *ssl = nullptr;
   if (local_port == worker->svr_->GetConfig()->tls_port) {
@@ -167,7 +167,7 @@ void Worker::newTCPConnection(evconnlistener *listener, 
evutil_socket_t fd, sock
     return;
   }
   std::string ip;
-  uint32_t port;
+  uint32_t port = 0;
   if (Util::GetPeerAddr(fd, &ip, &port) == 0) {
     conn->SetAddr(ip, port);
   }
@@ -201,14 +201,14 @@ void Worker::newUnixSocketConnection(evconnlistener 
*listener, evutil_socket_t f
 }
 
 Status Worker::listenTCP(const std::string &host, int port, int backlog) {
-  int af, rv, fd, sock_opt = 1;
+  int af = 0, rv = 0, fd = 0, sock_opt = 1;
 
   if (strchr(host.data(), ':')) {
     af = AF_INET6;
   } else {
     af = AF_INET;
   }
-  struct addrinfo hints, *srv_info, *p;
+  struct addrinfo hints, *srv_info = nullptr, *p = nullptr;
   memset(&hints, 0, sizeof(hints));
   hints.ai_family = af;
   hints.ai_socktype = SOCK_STREAM;
diff --git a/src/stats/log_collector.cc b/src/stats/log_collector.cc
index f828ed6a..629b0b81 100644
--- a/src/stats/log_collector.cc
+++ b/src/stats/log_collector.cc
@@ -53,7 +53,7 @@ LogCollector<T>::~LogCollector() {
 
 template <class T>
 ssize_t LogCollector<T>::Size() {
-  size_t n;
+  size_t n = 0;
   std::lock_guard<std::mutex> guard(mu_);
   n = entries_.size();
   return n;
@@ -92,7 +92,7 @@ void LogCollector<T>::PushEntry(T *entry) {
 
 template <class T>
 std::string LogCollector<T>::GetLatestEntries(int64_t cnt) {
-  size_t n;
+  size_t n = 0;
   std::string output;
 
   std::lock_guard<std::mutex> guard(mu_);
diff --git a/src/storage/redis_db.cc b/src/storage/redis_db.cc
index cdf79bdb..a871ef65 100644
--- a/src/storage/redis_db.cc
+++ b/src/storage/redis_db.cc
@@ -516,7 +516,7 @@ rocksdb::Status Database::ClearKeysOfSlot(const 
rocksdb::Slice &ns, int slot) {
 
 rocksdb::Status Database::GetSlotKeysInfo(int slot, std::map<int, uint64_t> 
*slotskeys, std::vector<std::string> *keys,
                                           int count) {
-  const rocksdb::Snapshot *snapshot;
+  const rocksdb::Snapshot *snapshot = nullptr;
   snapshot = storage_->GetDB()->GetSnapshot();
   rocksdb::ReadOptions read_options;
   read_options.snapshot = snapshot;
diff --git a/src/storage/redis_metadata.cc b/src/storage/redis_metadata.cc
index ed05f300..44b17639 100644
--- a/src/storage/redis_metadata.cc
+++ b/src/storage/redis_metadata.cc
@@ -42,8 +42,8 @@ const char *kErrMetadataTooShort = "metadata is too short";
 
 InternalKey::InternalKey(Slice input, bool slot_id_encoded) {
   slot_id_encoded_ = slot_id_encoded;
-  uint32_t key_size;
-  uint8_t namespace_size;
+  uint32_t key_size = 0;
+  uint8_t namespace_size = 0;
   GetFixed8(&input, &namespace_size);
   namespace_ = Slice(input.data(), namespace_size);
   input.remove_prefix(namespace_size);
@@ -61,7 +61,7 @@ InternalKey::InternalKey(Slice input, bool slot_id_encoded) {
 
 InternalKey::InternalKey(Slice ns_key, Slice sub_key, uint64_t version, bool 
slot_id_encoded) {
   slot_id_encoded_ = slot_id_encoded;
-  uint8_t namespace_size;
+  uint8_t namespace_size = 0;
   GetFixed8(&ns_key, &namespace_size);
   namespace_ = Slice(ns_key.data(), namespace_size);
   ns_key.remove_prefix(namespace_size);
@@ -125,13 +125,13 @@ bool InternalKey::operator==(const InternalKey &that) 
const {
 }
 
 void ExtractNamespaceKey(Slice ns_key, std::string *ns, std::string *key, bool 
slot_id_encoded) {
-  uint8_t namespace_size;
+  uint8_t namespace_size = 0;
   GetFixed8(&ns_key, &namespace_size);
   *ns = ns_key.ToString().substr(0, namespace_size);
   ns_key.remove_prefix(namespace_size);
 
   if (slot_id_encoded) {
-    uint16_t slot_id;
+    uint16_t slot_id = 0;
     GetFixed16(&ns_key, &slot_id);
   }
 
diff --git a/src/storage/scripting.cc b/src/storage/scripting.cc
index b47f1080..4edbf7c8 100644
--- a/src/storage/scripting.cc
+++ b/src/storage/scripting.cc
@@ -193,7 +193,7 @@ void loadFuncs(lua_State *lua, bool read_only) {
 }
 
 int redisLogCommand(lua_State *lua) {
-  int j, level, argc = lua_gettop(lua);
+  int j = 0, level = 0, argc = lua_gettop(lua);
 
   if (argc < 2) {
     lua_pushstring(lua, "redis.log() requires two arguments or more.");
@@ -214,8 +214,8 @@ int redisLogCommand(lua_State *lua) {
 
   std::string log_message;
   for (j = 1; j < argc; j++) {
-    size_t len;
-    const char *s;
+    size_t len = 0;
+    const char *s = nullptr;
     s = lua_tolstring(lua, (-argc) + j, &len);
     if (s) {
       if (j != 1) {
@@ -338,7 +338,7 @@ int redisCallCommand(lua_State *lua) { return 
redisGenericCommand(lua, 1); }
 
 int redisPCallCommand(lua_State *lua) { return redisGenericCommand(lua, 0); }
 int redisGenericCommand(lua_State *lua, int raise_error) {
-  int j, argc = lua_gettop(lua);
+  int j = 0, argc = lua_gettop(lua);
   std::vector<std::string> args;
   lua_getglobal(lua, "redis");
   lua_getfield(lua, -1, "read_only");
@@ -516,8 +516,8 @@ int redisStatusReplyCommand(lua_State *lua) { return 
redisReturnSingleFieldTable
 int redisSha1hexCommand(lua_State *lua) {
   int argc = lua_gettop(lua);
   char digest[41];
-  size_t len;
-  const char *s;
+  size_t len = 0;
+  const char *s = nullptr;
 
   if (argc != 1) {
     lua_pushstring(lua, "wrong number of arguments");
@@ -544,7 +544,7 @@ void SHA1Hex(char *digest, const char *script, size_t len) {
   SHA1_CTX ctx;
   unsigned char hash[20];
   const char *cset = "0123456789abcdef";
-  int j;
+  int j = 0;
 
   SHA1Init(&ctx);
   SHA1Update(&ctx, (const unsigned char *)script, len);
@@ -619,7 +619,7 @@ const char *redisProtocolToLuaType(lua_State *lua, const 
char *reply) {
 
 const char *redisProtocolToLuaType_Int(lua_State *lua, const char *reply) {
   const char *p = strchr(reply + 1, '\r');
-  int64_t value;
+  int64_t value = 0;
 
   Util::DecimalStringToNum(std::string(reply + 1, p - reply - 1), &value);
   lua_pushnumber(lua, static_cast<lua_Number>(value));
@@ -628,7 +628,7 @@ const char *redisProtocolToLuaType_Int(lua_State *lua, 
const char *reply) {
 
 const char *redisProtocolToLuaType_Bulk(lua_State *lua, const char *reply) {
   const char *p = strchr(reply + 1, '\r');
-  int64_t bulklen;
+  int64_t bulklen = 0;
 
   Util::DecimalStringToNum(std::string(reply + 1, p - reply - 1), &bulklen);
   if (bulklen == -1) {
@@ -662,7 +662,7 @@ const char *redisProtocolToLuaType_Error(lua_State *lua, 
const char *reply) {
 
 const char *redisProtocolToLuaType_Aggregate(lua_State *lua, const char 
*reply, int atype) {
   const char *p = strchr(reply + 1, '\r');
-  int64_t mbulklen;
+  int64_t mbulklen = 0;
   int j = 0;
 
   Util::DecimalStringToNum(std::string(reply + 1, p - reply - 1), &mbulklen);
@@ -696,7 +696,7 @@ const char *redisProtocolToLuaType_Double(lua_State *lua, 
const char *reply) {
   const char *p = strchr(reply + 1, '\r');
   char buf[MAX_LONG_DOUBLE_CHARS + 1];
   size_t len = p - reply - 1;
-  double d;
+  double d = NAN;
 
   if (len <= MAX_LONG_DOUBLE_CHARS) {
     memcpy(buf, reply + 1, len);
@@ -728,7 +728,7 @@ void pushError(lua_State *lua, const char *err) {
 std::string replyToRedisReply(lua_State *lua) {
   std::string output;
   const char *obj_s = nullptr;
-  size_t obj_len;
+  size_t obj_len = 0;
 
   int t = lua_type(lua, -1);
   switch (t) {
diff --git a/src/storage/storage.cc b/src/storage/storage.cc
index e6f4ae52..c45736e9 100644
--- a/src/storage/storage.cc
+++ b/src/storage/storage.cc
@@ -206,7 +206,7 @@ Status Storage::SetDBOption(const std::string &key, const 
std::string &value) {
 }
 
 Status Storage::CreateColumnFamilies(const rocksdb::Options &options) {
-  rocksdb::DB *tmp_db;
+  rocksdb::DB *tmp_db = nullptr;
   rocksdb::ColumnFamilyOptions cf_options(options);
   rocksdb::Status s = rocksdb::DB::Open(options, config_->db_dir, &tmp_db);
   if (s.ok()) {
@@ -586,7 +586,7 @@ uint64_t Storage::GetTotalSize(const std::string &ns) {
   ComposeNamespaceKey(ns, "", &prefix, false);
 
   Redis::Database db(this, ns);
-  uint64_t size, total_size = 0;
+  uint64_t size = 0, total_size = 0;
   rocksdb::DB::SizeApproximationFlags include_both =
       rocksdb::DB::SizeApproximationFlags::INCLUDE_FILES | 
rocksdb::DB::SizeApproximationFlags::INCLUDE_MEMTABLES;
   for (auto cf_handle : cf_handles_) {
@@ -604,7 +604,7 @@ uint64_t Storage::GetTotalSize(const std::string &ns) {
 }
 
 Status Storage::CheckDBSizeLimit() {
-  bool reach_db_size_limit;
+  bool reach_db_size_limit = false;
   if (config_->max_db_size == 0) {
     reach_db_size_limit = false;
   } else {
@@ -944,7 +944,7 @@ bool Storage::ReplDataManager::FileExists(Storage *storage, 
const std::string &d
   s = storage->env_->NewSequentialFile(file_path, &src_file, soptions);
   if (!s.ok()) return false;
 
-  uint64_t size;
+  uint64_t size = 0;
   s = storage->env_->GetFileSize(file_path, &size);
   if (!s.ok()) return false;
   auto src_reader = 
std::make_unique<rocksdb::SequentialFileWrapper>(src_file.get());
diff --git a/src/storage/table_properties_collector.cc 
b/src/storage/table_properties_collector.cc
index 73543d43..9c7b5f3a 100644
--- a/src/storage/table_properties_collector.cc
+++ b/src/storage/table_properties_collector.cc
@@ -30,10 +30,10 @@
 rocksdb::Status CompactOnExpiredCollector::AddUserKey(const rocksdb::Slice 
&key, const rocksdb::Slice &value,
                                                       rocksdb::EntryType 
entry_type, rocksdb::SequenceNumber,
                                                       uint64_t) {
-  int now;
-  uint8_t type;
-  uint32_t expired, subkeys = 0;
-  uint64_t version;
+  int now = 0;
+  uint8_t type = 0;
+  uint32_t expired = 0, subkeys = 0;
+  uint64_t version = 0;
 
   if (start_key_.empty()) {
     start_key_ = key.ToString();
diff --git a/src/types/geohash.cc b/src/types/geohash.cc
index 07b813d2..bbfc5256 100644
--- a/src/types/geohash.cc
+++ b/src/types/geohash.cc
@@ -387,9 +387,9 @@ GeoHashRadius GeoHashHelper::GetAreasByRadius(double 
longitude, double latitude,
   GeoHashBits hash;
   GeoHashNeighbors neighbors;
   GeoHashArea area;
-  double min_lon, max_lon, min_lat, max_lat;
+  double min_lon = NAN, max_lon = NAN, min_lat = NAN, max_lat = NAN;
   double bounds[4];
-  int steps;
+  int steps = 0;
 
   BoundingBox(longitude, latitude, radius_meters, bounds);
   min_lon = bounds[0];
@@ -472,7 +472,7 @@ GeoHashFix52Bits GeoHashHelper::Align52Bits(const 
GeoHashBits &hash) {
 
 /* Calculate distance using haversin great circle distance formula. */
 double GeoHashHelper::GetDistance(double lon1d, double lat1d, double lon2d, 
double lat2d) {
-  double lat1r, lon1r, lat2r, lon2r, u, v;
+  double lat1r = NAN, lon1r = NAN, lat2r = NAN, lon2r = NAN, u = NAN, v = NAN;
   lat1r = deg_rad(lat1d);
   lon1r = deg_rad(lon1d);
   lat2r = deg_rad(lat2d);
diff --git a/src/types/redis_bitmap.cc b/src/types/redis_bitmap.cc
index 8d800dd2..bb151cd7 100644
--- a/src/types/redis_bitmap.cc
+++ b/src/types/redis_bitmap.cc
@@ -122,7 +122,7 @@ rocksdb::Status Bitmap::GetString(const Slice &user_key, 
const uint32_t max_btos
   LatestSnapShot ss(db_);
   read_options.snapshot = ss.GetSnapShot();
   read_options.fill_cache = false;
-  uint32_t frag_index, valid_size;
+  uint32_t frag_index = 0, valid_size = 0;
 
   auto iter = DBUtil::UniqueIterator(db_, read_options);
   for (iter->Seek(prefix_key); iter->Valid() && 
iter->key().starts_with(prefix_key); iter->Next()) {
@@ -198,7 +198,7 @@ rocksdb::Status Bitmap::SetBit(const Slice &user_key, 
uint32_t offset, bool new_
   uint32_t used_size = index + byte_index + 1;
   uint32_t bitmap_size = std::max(used_size, metadata.size);
   if (byte_index >= value.size()) {  // expand the bitmap
-    size_t expand_size;
+    size_t expand_size = 0;
     if (byte_index >= value.size() * 2) {
       expand_size = byte_index - value.size() + 1;
     } else if (value.size() * 2 > kBitmapSegmentBytes) {
@@ -388,11 +388,11 @@ rocksdb::Status Bitmap::BitOp(BitOpFlags op_flag, const 
std::string &op_name, co
 
   BitmapMetadata res_metadata;
   if (num_keys == op_keys.size() || op_flag != kBitOpAnd) {
-    uint64_t i, frag_numkeys = num_keys, stop_index = (max_size - 1) / 
kBitmapSegmentBytes;
+    uint64_t i = 0, frag_numkeys = num_keys, stop_index = (max_size - 1) / 
kBitmapSegmentBytes;
     std::unique_ptr<unsigned char[]> frag_res(new unsigned 
char[kBitmapSegmentBytes]);
     uint16_t frag_maxlen = 0, frag_minlen = 0;
     std::string sub_key, fragment;
-    unsigned char output, byte;
+    unsigned char output = 0, byte = 0;
     std::vector<std::string> fragments;
 
     LatestSnapShot ss(db_);
diff --git a/src/types/redis_bitmap_string.cc b/src/types/redis_bitmap_string.cc
index 2a5284af..4aa0b1b9 100644
--- a/src/types/redis_bitmap_string.cc
+++ b/src/types/redis_bitmap_string.cc
@@ -130,7 +130,7 @@ rocksdb::Status BitmapString::BitPos(const std::string 
&raw_value, bool bit, int
  * */
 size_t BitmapString::redisPopcount(unsigned char *p, int64_t count) {
   size_t bits = 0;
-  uint32_t *p4;
+  uint32_t *p4 = nullptr;
 
   /* Count initial bytes not aligned to 32 bit. */
   while (reinterpret_cast<uint64_t>(p) & 3 && count) {
@@ -141,7 +141,7 @@ size_t BitmapString::redisPopcount(unsigned char *p, 
int64_t count) {
   /* Count bits 28 bytes at a time */
   p4 = reinterpret_cast<uint32_t *>(p);
   while (count >= 28) {
-    uint32_t aux1, aux2, aux3, aux4, aux5, aux6, aux7;
+    uint32_t aux1 = 0, aux2 = 0, aux3 = 0, aux4 = 0, aux5 = 0, aux6 = 0, aux7 
= 0;
 
     aux1 = *p4++;
     aux2 = *p4++;
@@ -192,11 +192,11 @@ size_t BitmapString::redisPopcount(unsigned char *p, 
int64_t count) {
  * https://github.com/antirez/redis/blob/94f2e7f/src/bitops.c#L101
  * */
 int64_t BitmapString::redisBitpos(unsigned char *c, int64_t count, int bit) {
-  uint64_t *l;
-  uint64_t skipval, word = 0, one;
+  uint64_t *l = nullptr;
+  uint64_t skipval = 0, word = 0, one = 0;
   int64_t pos = 0; /* Position of bit, to return to the caller. */
-  uint64_t j;
-  int found;
+  uint64_t j = 0;
+  int found = 0;
 
   /* Process whole words first, seeking for first word that is not
    * all ones or all zeros respectively if we are lookig for zeros
diff --git a/src/types/redis_geo.cc b/src/types/redis_geo.cc
index ff8078f2..348178b0 100644
--- a/src/types/redis_geo.cc
+++ b/src/types/redis_geo.cc
@@ -117,7 +117,7 @@ rocksdb::Status Geo::Radius(const Slice &user_key, double 
longitude, double lati
         double score = store_distance ? geo_point.dist / unit_conversion : 
geo_point.score;
         member_scores.emplace_back(MemberScore{geo_point.member, score});
       }
-      int ret;
+      int ret = 0;
       ZSet::Add(store_key, ZAddFlags::Default(), &member_scores, &ret);
     }
   }
@@ -188,7 +188,7 @@ std::string Geo::EncodeGeoHash(double longitude, double 
latitude) {
 
   std::string geoHash;
   for (int i = 0; i < 11; i++) {
-    int idx;
+    int idx = 0;
     if (i == 10) {
       /* We have just 52 bits, but the API used to output
        * an 11 bytes geohash. For compatibility we assume
@@ -211,7 +211,7 @@ int Geo::decodeGeoHash(double bits, double *xy) {
 int Geo::membersOfAllNeighbors(const Slice &user_key, GeoHashRadius n, double 
lon, double lat, double radius,
                                std::vector<GeoPoint> *geo_points) {
   GeoHashBits neighbors[9];
-  unsigned int i, count = 0, last_processed = 0;
+  unsigned int i = 0, count = 0, last_processed = 0;
 
   neighbors[0] = n.hash;
   neighbors[1] = n.neighbors.north;
@@ -249,7 +249,7 @@ int Geo::membersOfAllNeighbors(const Slice &user_key, 
GeoHashRadius n, double lo
  * Return the number of points added to the array. */
 int Geo::membersOfGeoHashBox(const Slice &user_key, GeoHashBits hash, 
std::vector<GeoPoint> *geo_points, double lon,
                              double lat, double radius) {
-  GeoHashFix52Bits min, max;
+  GeoHashFix52Bits min = 0, max = 0;
 
   scoresOfGeoHashBox(hash, &min, &max);
   return getPointsInRange(user_key, min, max, lon, lat, radius, geo_points);
@@ -304,7 +304,7 @@ int Geo::getPointsInRange(const Slice &user_key, double 
min, double max, double
   spec.min = min;
   spec.max = max;
   spec.maxex = true;
-  int size;
+  int size = 0;
   std::vector<MemberScore> member_scores;
   rocksdb::Status s = ZSet::RangeByScore(user_key, spec, &member_scores, 
&size);
   if (!s.ok()) return 0;
@@ -323,7 +323,7 @@ int Geo::getPointsInRange(const Slice &user_key, double 
min, double max, double
  * returns true if the point is included, or false if it is outside. */
 bool Geo::appendIfWithinRadius(std::vector<GeoPoint> *geo_points, double lon, 
double lat, double radius, double score,
                                const std::string &member) {
-  double distance, xy[2];
+  double distance = NAN, xy[2];
 
   if (!decodeGeoHash(score, xy)) return false; /* Can't decode. */
   /* Note that geohashGetDistanceIfInRadiusWGS84() takes arguments in
diff --git a/src/types/redis_list.cc b/src/types/redis_list.cc
index 6ed673d2..3d45419e 100644
--- a/src/types/redis_list.cc
+++ b/src/types/redis_list.cc
@@ -271,7 +271,7 @@ rocksdb::Status List::Insert(const Slice &user_key, const 
Slice &pivot, const Sl
   if (!s.ok()) return s;
 
   std::string buf, start_key, prefix, next_version_prefix;
-  uint64_t pivot_index = metadata.head - 1, new_elem_index;
+  uint64_t pivot_index = metadata.head - 1, new_elem_index = 0;
   PutFixed64(&buf, metadata.head);
   InternalKey(ns_key, buf, metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&start_key);
   InternalKey(ns_key, "", metadata.version, 
storage_->IsSlotIdEncoded()).Encode(&prefix);
@@ -397,7 +397,7 @@ rocksdb::Status List::Range(const Slice &user_key, int 
start, int stop, std::vec
   for (iter->Seek(start_key); iter->Valid() && 
iter->key().starts_with(prefix); iter->Next()) {
     InternalKey ikey(iter->key(), storage_->IsSlotIdEncoded());
     Slice sub_key = ikey.GetSubKey();
-    uint64_t index;
+    uint64_t index = 0;
     GetFixed64(&sub_key, &index);
     // index should be always >= start
     if (index > metadata.head + stop) break;
@@ -436,7 +436,7 @@ rocksdb::Status List::Set(const Slice &user_key, int index, 
Slice elem) {
 }
 
 rocksdb::Status List::RPopLPush(const Slice &src, const Slice &dst, 
std::string *elem) {
-  RedisType type;
+  RedisType type = kRedisNone;
   rocksdb::Status s = Type(dst, &type);
   if (!s.ok()) return s;
   if (type != kRedisNone && type != kRedisList) {
@@ -446,7 +446,7 @@ rocksdb::Status List::RPopLPush(const Slice &src, const 
Slice &dst, std::string
   s = Pop(src, false, elem);
   if (!s.ok()) return s;
 
-  int ret;
+  int ret = 0;
   std::vector<Slice> elems;
   elems.emplace_back(*elem);
   s = Push(dst, elems, true, &ret);
diff --git a/src/types/redis_set.cc b/src/types/redis_set.cc
index 882d9c3f..363e380d 100644
--- a/src/types/redis_set.cc
+++ b/src/types/redis_set.cc
@@ -244,7 +244,7 @@ rocksdb::Status Set::Take(const Slice &user_key, 
std::vector<std::string> *membe
 }
 
 rocksdb::Status Set::Move(const Slice &src, const Slice &dst, const Slice 
&member, int *ret) {
-  RedisType type;
+  RedisType type = kRedisNone;
   rocksdb::Status s = Type(dst, &type);
   if (!s.ok()) return s;
   if (type != kRedisNone && type != kRedisSet) {
diff --git a/src/types/redis_sortedint.cc b/src/types/redis_sortedint.cc
index da92bb7e..bd4d1031 100644
--- a/src/types/redis_sortedint.cc
+++ b/src/types/redis_sortedint.cc
@@ -141,7 +141,7 @@ rocksdb::Status Sortedint::Range(const Slice &user_key, 
uint64_t cursor_id, uint
   read_options.iterate_lower_bound = &lower_bound;
   read_options.fill_cache = false;
 
-  uint64_t id, pos = 0;
+  uint64_t id = 0, pos = 0;
   auto iter = DBUtil::UniqueIterator(db_, read_options);
   for (!reversed ? iter->Seek(start_key) : iter->SeekForPrev(start_key);
        iter->Valid() && iter->key().starts_with(prefix); !reversed ? 
iter->Next() : iter->Prev()) {
@@ -190,7 +190,7 @@ rocksdb::Status Sortedint::RangeByValue(const Slice 
&user_key, SortedintRangeSpe
     iter->SeekForPrev(start_key);
   }
 
-  uint64_t id;
+  uint64_t id = 0;
   for (; iter->Valid() && iter->key().starts_with(prefix_key); !spec.reversed 
? iter->Next() : iter->Prev()) {
     InternalKey ikey(iter->key(), storage_->IsSlotIdEncoded());
     Slice sub_key = ikey.GetSubKey();
diff --git a/src/types/redis_stream_base.cc b/src/types/redis_stream_base.cc
index 9f9d6e72..9da3b7fe 100644
--- a/src/types/redis_stream_base.cc
+++ b/src/types/redis_stream_base.cc
@@ -155,7 +155,7 @@ Status DecodeRawStreamEntryValue(const std::string &value, 
std::vector<std::stri
   rocksdb::Slice s(value);
 
   while (!s.empty()) {
-    uint32_t len;
+    uint32_t len = 0;
     if (!GetVarint32(&s, &len)) {
       return Status(Status::RedisParseErr, 
kErrDecodingStreamEntryValueFailure);
     }
diff --git a/src/types/redis_string.cc b/src/types/redis_string.cc
index d4b7f081..df665223 100644
--- a/src/types/redis_string.cc
+++ b/src/types/redis_string.cc
@@ -245,7 +245,7 @@ rocksdb::Status String::SetXX(const std::string &user_key, 
const std::string &va
 }
 
 rocksdb::Status String::SetRange(const std::string &user_key, int offset, 
const std::string &value, int *ret) {
-  int size;
+  int size = 0;
   std::string ns_key;
   AppendNamespacePrefix(user_key, &ns_key);
 
@@ -334,7 +334,7 @@ rocksdb::Status String::IncrByFloat(const std::string 
&user_key, double incremen
   }
   value = raw_value.substr(STRING_HDR_SIZE, raw_value.size() - 
STRING_HDR_SIZE);
   double n = 0;
-  std::size_t idx;
+  std::size_t idx = 0;
   if (!value.empty()) {
     try {
       n = std::stod(value, &idx);
@@ -394,7 +394,7 @@ rocksdb::Status String::MSetNX(const 
std::vector<StringPair> &pairs, int ttl, in
     expire = uint32_t(now) + ttl;
   }
 
-  int exists;
+  int exists = 0;
   std::vector<Slice> keys;
   keys.reserve(pairs.size());
   for (StringPair pair : pairs) {
diff --git a/src/types/redis_zset.cc b/src/types/redis_zset.cc
index d141a6f5..cdaa72d6 100644
--- a/src/types/redis_zset.cc
+++ b/src/types/redis_zset.cc
@@ -152,7 +152,7 @@ rocksdb::Status ZSet::Count(const Slice &user_key, const 
ZRangeSpec &spec, int *
 }
 
 rocksdb::Status ZSet::IncrBy(const Slice &user_key, const Slice &member, 
double increment, double *score) {
-  int ret;
+  int ret = 0;
   std::vector<MemberScore> mscores;
   mscores.emplace_back(MemberScore{member.ToString(), increment});
   rocksdb::Status s = Add(user_key, ZAddFlags::Incr(), &mscores, &ret);
@@ -382,7 +382,7 @@ rocksdb::Status ZSet::RangeByScore(const Slice &user_key, 
ZRangeSpec spec, std::
   for (; iter->Valid() && iter->key().starts_with(prefix_key); !spec.reversed 
? iter->Next() : iter->Prev()) {
     InternalKey ikey(iter->key(), storage_->IsSlotIdEncoded());
     Slice score_key = ikey.GetSubKey();
-    double score;
+    double score = NAN;
     GetDouble(&score_key, &score);
     if (spec.reversed) {
       if ((spec.minex && score == spec.min) || score < spec.min) break;
@@ -618,7 +618,7 @@ rocksdb::Status ZSet::Rank(const Slice &user_key, const 
Slice &member, bool reve
   for (; iter->Valid() && iter->key().starts_with(prefix_key); !reversed ? 
iter->Next() : iter->Prev()) {
     InternalKey ikey(iter->key(), storage_->IsSlotIdEncoded());
     Slice score_key = ikey.GetSubKey();
-    double score;
+    double score = NAN;
     GetDouble(&score_key, &score);
     if (score == target_score && score_key == member) break;
     rank++;
@@ -660,7 +660,7 @@ rocksdb::Status ZSet::InterStore(const Slice &dst, const 
std::vector<KeyWeight>
   std::map<std::string, double> dst_zset;
   std::map<std::string, size_t> member_counters;
   std::vector<MemberScore> target_mscores;
-  int target_size;
+  int target_size = 0;
   ZRangeSpec spec;
   auto s = RangeByScore(keys_weights[0].key, spec, &target_mscores, 
&target_size);
   if (!s.ok() || target_mscores.empty()) return s;
@@ -717,7 +717,7 @@ rocksdb::Status ZSet::UnionStore(const Slice &dst, const 
std::vector<KeyWeight>
 
   std::map<std::string, double> dst_zset;
   std::vector<MemberScore> target_mscores;
-  int target_size;
+  int target_size = 0;
   ZRangeSpec spec;
   for (const auto &key_weight : keys_weights) {
     // get all member


Reply via email to