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

hulk 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 e6aa8987 Fix cppcoreguidelines-narrowing-conversions warning reported 
by clang-tidy (#1159)
e6aa8987 is described below

commit e6aa8987950924821baf74ca912be4837d686032
Author: Maxim Smolskiy <[email protected]>
AuthorDate: Mon Dec 12 05:32:11 2022 +0300

    Fix cppcoreguidelines-narrowing-conversions warning reported by clang-tidy 
(#1159)
---
 .clang-tidy                      |  2 +-
 src/commands/redis_cmd.cc        | 11 ++++----
 src/common/io_util.cc            |  8 +++---
 src/common/io_util.h             |  6 ++---
 src/common/string_util.cc        | 52 ++++++++++++++++++-------------------
 src/common/string_util.h         |  2 +-
 src/config/config.cc             | 12 ++++-----
 src/config/config.h              | 12 ++++-----
 src/config/config_type.h         | 56 ++++++++++++++++------------------------
 src/main.cc                      |  6 ++---
 src/server/redis_connection.cc   |  6 ++---
 src/server/redis_connection.h    |  4 +--
 src/server/redis_reply.cc        |  4 ---
 src/server/redis_reply.h         | 14 ++++++++--
 src/server/redis_request.cc      |  2 +-
 src/server/server.cc             |  8 +++---
 src/server/worker.cc             |  6 ++---
 src/server/worker.h              |  2 +-
 src/stats/log_collector.cc       |  2 +-
 src/storage/lock_manager.cc      |  4 +--
 src/storage/lock_manager.h       |  2 +-
 src/storage/scripting.cc         |  6 ++---
 src/storage/storage.cc           | 15 ++++++-----
 src/storage/storage.h            |  2 +-
 src/types/geohash.cc             | 14 +++++-----
 src/types/redis_bitmap.cc        |  8 +++---
 src/types/redis_bitmap_string.cc | 12 ++++-----
 src/types/redis_geo.cc           |  9 ++++---
 src/types/redis_hash.cc          |  2 +-
 src/types/redis_list.cc          | 12 ++++-----
 src/types/redis_set.cc           |  2 +-
 src/types/redis_sortedint.cc     |  2 +-
 src/types/redis_string.cc        | 20 +++++++-------
 src/types/redis_zset.cc          | 12 ++++-----
 34 files changed, 167 insertions(+), 170 deletions(-)

diff --git a/.clang-tidy b/.clang-tidy
index 3064647a..e1bb8f05 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/commands/redis_cmd.cc b/src/commands/redis_cmd.cc
index 8edcef61..87ffae04 100644
--- a/src/commands/redis_cmd.cc
+++ b/src/commands/redis_cmd.cc
@@ -670,7 +670,7 @@ class CommandPSetEX : public Commander {
     if (*ttl_ms < 1000) {
       ttl_ = 1;
     } else {
-      ttl_ = *ttl_ms / 1000;
+      ttl_ = static_cast<int>(*ttl_ms / 1000);
     }
 
     return Commander::Parse(args);
@@ -1270,7 +1270,7 @@ class CommandExpireAt : public Commander {
       return {Status::RedisParseErr, "the expire time was overflow"};
     }
 
-    timestamp_ = *parse_result;
+    timestamp_ = static_cast<int>(*parse_result);
 
     return Commander::Parse(args);
   }
@@ -3470,7 +3470,7 @@ class CommandGeoRadius : public CommandGeoBase {
   }
 
   std::string GenerateOutput(const std::vector<GeoPoint> &geo_points) {
-    int result_length = geo_points.size();
+    int result_length = static_cast<int>(geo_points.size());
     int returned_items_count = (count_ == 0 || result_length < count_) ? 
result_length : count_;
     std::vector<std::string> list;
     for (int i = 0; i < returned_items_count; i++) {
@@ -4581,7 +4581,7 @@ class CommandCommand : public Commander {
         GetCommandsInfo(output, std::vector<std::string>(args_.begin() + 2, 
args_.end()));
       } else if (sub_command == "getkeys") {
         std::vector<int> keys_indexes;
-        auto s = GetKeysFromCommand(args_[2], args_.size() - 2, &keys_indexes);
+        auto s = GetKeysFromCommand(args_[2], static_cast<int>(args_.size()) - 
2, &keys_indexes);
         if (!s.IsOK()) return s;
 
         if (keys_indexes.size() == 0) {
@@ -5043,7 +5043,8 @@ class CommandFetchFile : public Commander {
         // Sleep if the speed of sending file is more than replication speed 
limit
         auto end = std::chrono::high_resolution_clock::now();
         uint64_t duration = 
std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
-        auto shortest = static_cast<uint64_t>(static_cast<double>(file_size) / 
max_replication_bytes * (1000 * 1000));
+        auto shortest = static_cast<uint64_t>(static_cast<double>(file_size) /
+                                              
static_cast<double>(max_replication_bytes) * (1000 * 1000));
         if (max_replication_bytes > 0 && duration < shortest) {
           LOG(INFO) << "[replication] Need to sleep " << (shortest - duration) 
/ 1000
                     << " ms since of sending files too quickly";
diff --git a/src/common/io_util.cc b/src/common/io_util.cc
index 99e16f32..4c3e40ba 100644
--- a/src/common/io_util.cc
+++ b/src/common/io_util.cc
@@ -130,7 +130,7 @@ Status SockSetTcpKeepalive(int fd, int interval) {
   return Status::OK();
 }
 
-Status SockConnect(const std::string &host, uint32_t port, int *fd, uint64_t 
conn_timeout, uint64_t timeout) {
+Status SockConnect(const std::string &host, uint32_t port, int *fd, int 
conn_timeout, int timeout) {
   if (conn_timeout == 0) {
     auto s = SockConnect(host, port, fd);
     if (!s) return s;
@@ -307,16 +307,16 @@ int GetLocalPort(int fd) {
   return 0;
 }
 
-bool IsPortInUse(int port) {
+bool IsPortInUse(uint32_t port) {
   int fd = NullFD;
-  Status s = SockConnect("0.0.0.0", static_cast<uint32_t>(port), &fd);
+  Status s = SockConnect("0.0.0.0", port, &fd);
   if (fd != NullFD) close(fd);
   return s.IsOK();
 }
 
 /* Wait for milliseconds until the given file descriptor becomes
  * writable/readable/exception */
-int aeWait(int fd, int mask, uint64_t timeout) {
+int aeWait(int fd, int mask, int timeout) {
   pollfd pfd;
   int retmask = 0, retval = 0;
 
diff --git a/src/common/io_util.h b/src/common/io_util.h
index 23f431b4..87fdc3d6 100644
--- a/src/common/io_util.h
+++ b/src/common/io_util.h
@@ -28,7 +28,7 @@ namespace Util {
 
 sockaddr_in NewSockaddrInet(const std::string &host, uint32_t port);
 Status SockConnect(const std::string &host, uint32_t port, int *fd);
-Status SockConnect(const std::string &host, uint32_t port, int *fd, uint64_t 
conn_timeout, uint64_t timeout = 0);
+Status SockConnect(const std::string &host, uint32_t port, int *fd, int 
conn_timeout, int timeout = 0);
 Status SockSetTcpNoDelay(int fd, int val);
 Status SockSetTcpKeepalive(int fd, int interval);
 Status SockSend(int fd, const std::string &data);
@@ -37,9 +37,9 @@ Status SockSendFile(int out_fd, int in_fd, size_t size);
 Status SockSetBlocking(int fd, int blocking);
 int GetPeerAddr(int fd, std::string *addr, uint32_t *port);
 int GetLocalPort(int fd);
-bool IsPortInUse(int port);
+bool IsPortInUse(uint32_t port);
 
-int aeWait(int fd, int mask, uint64_t milliseconds);
+int aeWait(int fd, int mask, int milliseconds);
 
 Status Write(int fd, const std::string &data);
 Status Pwrite(int fd, const std::string &data, off_t offset);
diff --git a/src/common/string_util.cc b/src/common/string_util.cc
index f4a48736..03cfe67e 100644
--- a/src/common/string_util.cc
+++ b/src/common/string_util.cc
@@ -121,50 +121,50 @@ int StringMatch(const std::string &pattern, const 
std::string &in, int nocase) {
 }
 
 // Glob-style pattern matching.
-int StringMatchLen(const char *pattern, int patternLen, const char *string, 
int stringLen, int nocase) {
-  while (patternLen && stringLen) {
+int StringMatchLen(const char *pattern, size_t pattern_len, const char 
*string, size_t string_len, int nocase) {
+  while (pattern_len && string_len) {
     switch (pattern[0]) {
       case '*':
         while (pattern[1] == '*') {
           pattern++;
-          patternLen--;
+          pattern_len--;
         }
-        if (patternLen == 1) return 1; /* match */
-        while (stringLen) {
-          if (StringMatchLen(pattern + 1, patternLen - 1, string, stringLen, 
nocase)) return 1; /* match */
+        if (pattern_len == 1) return 1; /* match */
+        while (string_len) {
+          if (StringMatchLen(pattern + 1, pattern_len - 1, string, string_len, 
nocase)) return 1; /* match */
           string++;
-          stringLen--;
+          string_len--;
         }
         return 0; /* no match */
         break;
       case '?':
-        if (stringLen == 0) return 0; /* no match */
+        if (string_len == 0) return 0; /* no match */
         string++;
-        stringLen--;
+        string_len--;
         break;
       case '[': {
         int not_symbol = 0, match = 0;
 
         pattern++;
-        patternLen--;
+        pattern_len--;
         not_symbol = pattern[0] == '^';
         if (not_symbol) {
           pattern++;
-          patternLen--;
+          pattern_len--;
         }
         match = 0;
         while (true) {
-          if (pattern[0] == '\\' && patternLen >= 2) {
+          if (pattern[0] == '\\' && pattern_len >= 2) {
             pattern++;
-            patternLen--;
+            pattern_len--;
             if (pattern[0] == string[0]) match = 1;
           } else if (pattern[0] == ']') {
             break;
-          } else if (patternLen == 0) {
+          } else if (pattern_len == 0) {
             pattern--;
-            patternLen++;
+            pattern_len++;
             break;
-          } else if (pattern[1] == '-' && patternLen >= 3) {
+          } else if (pattern[1] == '-' && pattern_len >= 3) {
             int start = pattern[0];
             int end = pattern[2];
             int c = string[0];
@@ -179,7 +179,7 @@ int StringMatchLen(const char *pattern, int patternLen, 
const char *string, int
               c = tolower(c);
             }
             pattern += 2;
-            patternLen -= 2;
+            pattern_len -= 2;
             if (c >= start && c <= end) match = 1;
           } else {
             if (!nocase) {
@@ -189,18 +189,18 @@ int StringMatchLen(const char *pattern, int patternLen, 
const char *string, int
             }
           }
           pattern++;
-          patternLen--;
+          pattern_len--;
         }
         if (not_symbol) match = !match;
         if (!match) return 0; /* no match */
         string++;
-        stringLen--;
+        string_len--;
         break;
       }
       case '\\':
-        if (patternLen >= 2) {
+        if (pattern_len >= 2) {
           pattern++;
-          patternLen--;
+          pattern_len--;
         }
         /* fall through */
       default:
@@ -210,20 +210,20 @@ int StringMatchLen(const char *pattern, int patternLen, 
const char *string, int
           if (tolower(static_cast<int>(pattern[0])) != 
tolower(static_cast<int>(string[0]))) return 0; /* no match */
         }
         string++;
-        stringLen--;
+        string_len--;
         break;
     }
     pattern++;
-    patternLen--;
-    if (stringLen == 0) {
+    pattern_len--;
+    if (string_len == 0) {
       while (*pattern == '*') {
         pattern++;
-        patternLen--;
+        pattern_len--;
       }
       break;
     }
   }
-  if (patternLen == 0 && stringLen == 0) return 1;
+  if (pattern_len == 0 && string_len == 0) return 1;
   return 0;
 }
 
diff --git a/src/common/string_util.h b/src/common/string_util.h
index 9ed3a145..e67893c7 100644
--- a/src/common/string_util.h
+++ b/src/common/string_util.h
@@ -35,7 +35,7 @@ std::vector<std::string> Split(const std::string &in, const 
std::string &delim);
 std::vector<std::string> Split2KV(const std::string &in, const std::string 
&delim);
 bool HasPrefix(const std::string &str, const std::string &prefix);
 int StringMatch(const std::string &pattern, const std::string &in, int nocase);
-int StringMatchLen(const char *p, int plen, const char *s, int slen, int 
nocase);
+int StringMatchLen(const char *p, size_t plen, const char *s, size_t slen, int 
nocase);
 std::string StringToHex(const std::string &input);
 std::vector<std::string> TokenizeRedisProtocol(const std::string &value);
 
diff --git a/src/config/config.cc b/src/config/config.cc
index 8982a7a9..5fecfe7e 100644
--- a/src/config/config.cc
+++ b/src/config/config.cc
@@ -97,9 +97,9 @@ Config::Config() {
   FieldWrapper fields[] = {
       {"daemonize", true, new YesNoField(&daemonize, false)},
       {"bind", true, new StringField(&binds_, "")},
-      {"port", true, new IntField(&port, kDefaultPort, 1, PORT_LIMIT)},
+      {"port", true, new UInt32Field(&port, kDefaultPort, 1, PORT_LIMIT)},
 #ifdef ENABLE_OPENSSL
-      {"tls-port", true, new IntField(&tls_port, 0, 0, PORT_LIMIT)},
+      {"tls-port", true, new UInt32Field(&tls_port, 0, 0, PORT_LIMIT)},
       {"tls-cert-file", false, new StringField(&tls_cert_file, "")},
       {"tls-key-file", false, new StringField(&tls_key_file, "")},
       {"tls-key-file-pass", false, new StringField(&tls_key_file_pass, "")},
@@ -268,8 +268,8 @@ void Config::initFieldValidator() {
          s = Util::DecimalStringToNum(args[1], &stop, 0, 24);
          if (!s.IsOK()) return s;
          if (start > stop) return Status(Status::NotOK, "invalid range format, 
start should be smaller than stop");
-         compaction_checker_range.Start = start;
-         compaction_checker_range.Stop = stop;
+         compaction_checker_range.Start = static_cast<int>(start);
+         compaction_checker_range.Stop = static_cast<int>(stop);
          return Status::OK();
        }},
       {"rename-command",
@@ -430,7 +430,7 @@ void Config::initFieldCallback() {
       {"max-io-mb",
        [this](Server *srv, const std::string &k, const std::string &v) -> 
Status {
          if (!srv) return Status::OK();
-         srv->storage_->SetIORateLimit(static_cast<uint64_t>(max_io_mb));
+         srv->storage_->SetIORateLimit(max_io_mb);
          return Status::OK();
        }},
       {"profiling-sample-record-max-len",
@@ -588,7 +588,7 @@ void Config::initFieldCallback() {
   }
 }
 
-void Config::SetMaster(const std::string &host, int port) {
+void Config::SetMaster(const std::string &host, uint32_t port) {
   master_host = host;
   master_port = port;
   auto iter = fields_.find("slaveof");
diff --git a/src/config/config.h b/src/config/config.h
index e5714526..144ae192 100644
--- a/src/config/config.h
+++ b/src/config/config.h
@@ -39,7 +39,7 @@ namespace Engine {
 class Storage;
 }
 
-constexpr const uint16_t PORT_LIMIT = 65535;
+constexpr const uint32_t PORT_LIMIT = 65535;
 
 enum SupervisedMode { kSupervisedNone = 0, kSupervisedAutoDetect, 
kSupervisedSystemd, kSupervisedUpStart };
 
@@ -49,7 +49,7 @@ constexpr const char *TLS_AUTH_CLIENTS_OPTIONAL = "optional";
 constexpr const size_t KiB = 1024L;
 constexpr const size_t MiB = 1024L * KiB;
 constexpr const size_t GiB = 1024L * MiB;
-constexpr const int kDefaultPort = 6666;
+constexpr const uint32_t kDefaultPort = 6666;
 
 extern const char *kDefaultNamespace;
 
@@ -73,8 +73,8 @@ struct Config {
  public:
   Config();
   ~Config() = default;
-  int port = 0;
-  int tls_port = 0;
+  uint32_t port = 0;
+  uint32_t tls_port = 0;
   std::string tls_cert_file;
   std::string tls_key_file;
   std::string tls_key_file_pass;
@@ -127,7 +127,7 @@ struct Config {
   std::string master_host;
   std::string unixsocket;
   int unixsocketperm = 0777;
-  int master_port = 0;
+  uint32_t master_port = 0;
   Cron compact_cron;
   Cron bgsave_cron;
   CompactionCheckerRange compaction_checker_range{-1, -1};
@@ -197,7 +197,7 @@ struct Config {
   Status Load(const CLIOptions &path);
   void Get(const std::string &key, std::vector<std::string> *values);
   Status Set(Server *svr, std::string key, const std::string &value);
-  void SetMaster(const std::string &host, int port);
+  void SetMaster(const std::string &host, uint32_t port);
   void ClearMaster();
   Status GetNamespace(const std::string &ns, std::string *token);
   Status AddNamespace(const std::string &ns, const std::string &token);
diff --git a/src/config/config_type.h b/src/config/config_type.h
index ad776f92..65e774d9 100644
--- a/src/config/config_type.h
+++ b/src/config/config_type.h
@@ -22,9 +22,11 @@
 
 #include <fmt/format.h>
 
+#include <limits>
 #include <string>
 #include <utility>
 
+#include "parse_util.h"
 #include "status.h"
 #include "string_util.h"
 
@@ -34,6 +36,14 @@ class Server;
 using validate_fn = std::function<Status(const std::string &, const 
std::string &)>;
 using callback_fn = std::function<Status(Server *, const std::string &, const 
std::string &)>;
 
+// forward declaration
+template <typename>
+class IntegerField;
+
+using IntField = IntegerField<int>;
+using UInt32Field = IntegerField<uint32_t>;
+using Int64Field = IntegerField<int64_t>;
+
 struct configEnum {
   const char *name;
   const int val;
@@ -101,27 +111,30 @@ class MultiStringField : public ConfigField {
   std::vector<std::string> *receiver_;
 };
 
-class IntField : public ConfigField {
+template <typename IntegerType>
+class IntegerField : public ConfigField {
  public:
-  IntField(int *receiver, int n, int min, int max) : receiver_(receiver), 
min_(min), max_(max) { *receiver_ = n; }
-  ~IntField() override = default;
+  IntegerField(IntegerType *receiver, IntegerType n, IntegerType min, 
IntegerType max)
+      : receiver_(receiver), min_(min), max_(max) {
+    *receiver_ = n;
+  }
+  ~IntegerField() override = default;
   std::string ToString() override { return std::to_string(*receiver_); }
   Status ToNumber(int64_t *n) override {
     *n = *receiver_;
     return Status::OK();
   }
   Status Set(const std::string &v) override {
-    int64_t n;
-    auto s = Util::DecimalStringToNum(v, &n, min_, max_);
+    auto s = ParseInt<IntegerType>(v, {min_, max_});
     if (!s.IsOK()) return s;
-    *receiver_ = static_cast<int>(n);
+    *receiver_ = s.GetValue();
     return Status::OK();
   }
 
  private:
-  int *receiver_;
-  int min_ = INT_MIN;
-  int max_ = INT_MAX;
+  IntegerType *receiver_;
+  IntegerType min_ = std::numeric_limits<IntegerType>::min();
+  IntegerType max_ = std::numeric_limits<IntegerType>::max();
 };
 
 class OctalField : public ConfigField {
@@ -147,31 +160,6 @@ class OctalField : public ConfigField {
   int max_ = INT_MAX;
 };
 
-class Int64Field : public ConfigField {
- public:
-  Int64Field(int64_t *receiver, int64_t n, int64_t min, int64_t max) : 
receiver_(receiver), min_(min), max_(max) {
-    *receiver_ = n;
-  }
-  ~Int64Field() override = default;
-  std::string ToString() override { return std::to_string(*receiver_); }
-  Status ToNumber(int64_t *n) override {
-    *n = *receiver_;
-    return Status::OK();
-  }
-  Status Set(const std::string &v) override {
-    int64_t n;
-    auto s = Util::DecimalStringToNum(v, &n, min_, max_);
-    if (!s.IsOK()) return s;
-    *receiver_ = n;
-    return Status::OK();
-  }
-
- private:
-  int64_t *receiver_;
-  int64_t min_ = INT64_MIN;
-  int64_t max_ = INT64_MAX;
-};
-
 class YesNoField : public ConfigField {
  public:
   YesNoField(bool *receiver, bool b) : receiver_(receiver) { *receiver_ = b; }
diff --git a/src/main.cc b/src/main.cc
index e8d1bb44..356b49c9 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -81,7 +81,7 @@ extern "C" void segvHandler(int sig, siginfo_t *info, void 
*secret) {
   for (int i = 1; i < trace_size; ++i) {
     char func_info[1024] = {};
     if (google::Symbolize(trace[i], func_info, sizeof(func_info) - 1)) {
-      LOG(ERROR) << std::left << std::setw(max_msg_len) << messages[i] << "  " 
<< func_info;
+      LOG(ERROR) << std::left << std::setw(static_cast<int>(max_msg_len)) << 
messages[i] << "  " << func_info;
     } else {
       LOG(ERROR) << messages[i];
     }
@@ -309,8 +309,8 @@ int main(int argc, char *argv[]) {
   // but the server use REUSE_PORT to support the multi listeners. So we 
connect
   // the listen port to check if the port has already listened or not.
   if (!config.binds.empty()) {
-    int ports[] = {config.port, config.tls_port, 0};
-    for (int *port = ports; *port; ++port) {
+    uint32_t ports[] = {config.port, config.tls_port, 0};
+    for (uint32_t *port = ports; *port; ++port) {
       if (Util::IsPortInUse(*port)) {
         LOG(ERROR) << "Could not create server TCP since the specified port[" 
<< *port << "] is already in use"
                    << std::endl;
diff --git a/src/server/redis_connection.cc b/src/server/redis_connection.cc
index 2f5b7770..8f41750e 100644
--- a/src/server/redis_connection.cc
+++ b/src/server/redis_connection.cc
@@ -126,7 +126,7 @@ void Connection::SendFile(int fd) {
   evbuffer_add_file(output, fd, 0, -1);
 }
 
-void Connection::SetAddr(std::string ip, int port) {
+void Connection::SetAddr(std::string ip, uint32_t port) {
   ip_ = std::move(ip);
   port_ = port;
   addr_ = ip_ + ":" + std::to_string(port_);
@@ -196,7 +196,7 @@ void Connection::UnSubscribeChannel(const std::string 
&channel) {
 
 void Connection::UnSubscribeAll(const unsubscribe_callback &reply) {
   if (subscribe_channels_.empty()) {
-    if (reply != nullptr) reply("", subcribe_patterns_.size());
+    if (reply != nullptr) reply("", 
static_cast<int>(subcribe_patterns_.size()));
     return;
   }
   int removed = 0;
@@ -233,7 +233,7 @@ void Connection::PUnSubscribeChannel(const std::string 
&pattern) {
 
 void Connection::PUnSubscribeAll(const unsubscribe_callback &reply) {
   if (subcribe_patterns_.empty()) {
-    if (reply != nullptr) reply("", subscribe_channels_.size());
+    if (reply != nullptr) reply("", 
static_cast<int>(subscribe_channels_.size()));
     return;
   }
 
diff --git a/src/server/redis_connection.h b/src/server/redis_connection.h
index b9522532..54e86f0c 100644
--- a/src/server/redis_connection.h
+++ b/src/server/redis_connection.h
@@ -79,7 +79,7 @@ class Connection {
   std::string GetName() { return name_; }
   void SetName(std::string name) { name_ = std::move(name); }
   std::string GetAddr() { return addr_; }
-  void SetAddr(std::string ip, int port);
+  void SetAddr(std::string ip, uint32_t port);
   void SetLastCmd(std::string cmd) { last_cmd_ = std::move(cmd); }
   std::string GetIP() { return ip_; }
   int GetPort() { return port_; }
@@ -125,7 +125,7 @@ class Connection {
   std::string ns_;
   std::string name_;
   std::string ip_;
-  int port_ = 0;
+  uint32_t port_ = 0;
   std::string addr_;
   int listening_port_ = 0;
   bool is_admin_ = false;
diff --git a/src/server/redis_reply.cc b/src/server/redis_reply.cc
index 741b9e75..86ccf030 100644
--- a/src/server/redis_reply.cc
+++ b/src/server/redis_reply.cc
@@ -30,14 +30,10 @@ std::string SimpleString(const std::string &data) { return 
"+" + data + CRLF; }
 
 std::string Error(const std::string &err) { return "-" + err + CRLF; }
 
-std::string Integer(int64_t data) { return ":" + std::to_string(data) + CRLF; }
-
 std::string BulkString(const std::string &data) { return "$" + 
std::to_string(data.length()) + CRLF + data + CRLF; }
 
 std::string NilString() { return "$-1" CRLF; }
 
-std::string MultiLen(int64_t len) { return "*" + std::to_string(len) + CRLF; }
-
 std::string MultiBulkString(const std::vector<std::string> &values, bool 
output_nil_for_empty_string) {
   std::string result = "*" + std::to_string(values.size()) + CRLF;
   for (const auto &value : values) {
diff --git a/src/server/redis_reply.h b/src/server/redis_reply.h
index ebf4fe44..436b9f12 100644
--- a/src/server/redis_reply.h
+++ b/src/server/redis_reply.h
@@ -32,10 +32,20 @@ namespace Redis {
 void Reply(evbuffer *output, const std::string &data);
 std::string SimpleString(const std::string &data);
 std::string Error(const std::string &err);
-std::string Integer(int64_t data);
+
+template <typename IntegerType>
+std::string Integer(IntegerType data) {
+  return ":" + std::to_string(data) + CRLF;
+}
+
 std::string BulkString(const std::string &data);
 std::string NilString();
-std::string MultiLen(int64_t len);
+
+template <typename IntegerType>
+std::string MultiLen(IntegerType len) {
+  return "*" + std::to_string(len) + CRLF;
+}
+
 std::string Array(const std::vector<std::string> &list);
 std::string MultiBulkString(const std::vector<std::string> &values, bool 
output_nil_for_empty_string = true);
 std::string MultiBulkString(const std::vector<std::string> &values, const 
std::vector<rocksdb::Status> &statuses);
diff --git a/src/server/redis_request.cc b/src/server/redis_request.cc
index 22066331..c5c43381 100644
--- a/src/server/redis_request.cc
+++ b/src/server/redis_request.cc
@@ -110,7 +110,7 @@ Status Request::Tokenize(evbuffer *input) {
       }
       case BulkData:
         if (evbuffer_get_length(input) < bulk_len_ + 2) return Status::OK();
-        char *data = reinterpret_cast<char *>(evbuffer_pullup(input, bulk_len_ 
+ 2));
+        char *data = reinterpret_cast<char *>(evbuffer_pullup(input, 
static_cast<ssize_t>(bulk_len_ + 2)));
         tokens_.emplace_back(data, bulk_len_);
         evbuffer_drain(input, bulk_len_ + 2);
         svr_->stats_.IncrInbondBytes(bulk_len_ + 2);
diff --git a/src/server/server.cc b/src/server/server.cc
index daccf0a2..fd7bfe07 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -157,7 +157,7 @@ Status Server::Start() {
 
   compaction_checker_thread_ = std::thread([this]() {
     uint64_t counter = 0;
-    int32_t last_compact_date = 0;
+    time_t last_compact_date = 0;
     Util::ThreadSetName("compact-check");
     CompactionChecker compaction_checker(this->storage_);
     while (!stop_) {
@@ -1037,7 +1037,9 @@ void Server::GetInfo(const std::string &ns, const 
std::string &section, std::str
     string_stream << "sequence:" << 
storage_->GetDB()->GetLatestSequenceNumber() << "\r\n";
     string_stream << "used_db_size:" << storage_->GetTotalSize(ns) << "\r\n";
     string_stream << "max_db_size:" << config_->max_db_size * GiB << "\r\n";
-    double used_percent = config_->max_db_size ? storage_->GetTotalSize() * 
100 / (config_->max_db_size * GiB) : 0;
+    double used_percent = config_->max_db_size ? 
static_cast<double>(storage_->GetTotalSize() * 100) /
+                                                     
static_cast<double>(config_->max_db_size * GiB)
+                                               : 0;
     string_stream << "used_percent: " << used_percent << "%\r\n";
     struct statvfs stat;
     if (statvfs(config_->db_dir.c_str(), &stat) == 0) {
@@ -1045,7 +1047,7 @@ void Server::GetInfo(const std::string &ns, const 
std::string &section, std::str
       auto used_disk_size = (stat.f_blocks - stat.f_bavail) * stat.f_frsize;
       string_stream << "disk_capacity:" << disk_capacity << "\r\n";
       string_stream << "used_disk_size:" << used_disk_size << "\r\n";
-      double used_disk_percent = used_disk_size * 100 / disk_capacity;
+      double used_disk_percent = static_cast<double>(used_disk_size * 100) / 
static_cast<double>(disk_capacity);
       string_stream << "used_disk_percent: " << used_disk_percent << "%\r\n";
     }
   }
diff --git a/src/server/worker.cc b/src/server/worker.cc
index 80a9a921..c7f82ebc 100644
--- a/src/server/worker.cc
+++ b/src/server/worker.cc
@@ -59,10 +59,10 @@ Worker::Worker(Server *svr, Config *config, bool repl) : 
svr_(svr) {
   timeval tm = {10, 0};
   evtimer_add(timer_, &tm);
 
-  int ports[3] = {config->port, config->tls_port, 0};
+  uint32_t ports[3] = {config->port, config->tls_port, 0};
   auto binds = config->binds;
 
-  for (int *port = ports; *port; ++port) {
+  for (uint32_t *port = ports; *port; ++port) {
     for (const auto &bind : binds) {
       Status s = listenTCP(bind, *port, config->backlog);
       if (!s.IsOK()) {
@@ -200,7 +200,7 @@ void Worker::newUnixSocketConnection(evconnlistener 
*listener, evutil_socket_t f
   }
 }
 
-Status Worker::listenTCP(const std::string &host, int port, int backlog) {
+Status Worker::listenTCP(const std::string &host, uint32_t port, int backlog) {
   int af = 0, rv = 0, fd = 0, sock_opt = 1;
 
   if (strchr(host.data(), ':')) {
diff --git a/src/server/worker.h b/src/server/worker.h
index f2f53e22..365a1244 100644
--- a/src/server/worker.h
+++ b/src/server/worker.h
@@ -70,7 +70,7 @@ class Worker {
   Server *svr_;
 
  private:
-  Status listenTCP(const std::string &host, int port, int backlog);
+  Status listenTCP(const std::string &host, uint32_t port, int backlog);
   static void newTCPConnection(evconnlistener *listener, evutil_socket_t fd, 
sockaddr *address, int socklen, void *ctx);
   static void newUnixSocketConnection(evconnlistener *listener, 
evutil_socket_t fd, sockaddr *address, int socklen,
                                       void *ctx);
diff --git a/src/stats/log_collector.cc b/src/stats/log_collector.cc
index 629b0b81..08211dbb 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 = 0;
+  ssize_t n = 0;
   std::lock_guard<std::mutex> guard(mu_);
   n = entries_.size();
   return n;
diff --git a/src/storage/lock_manager.cc b/src/storage/lock_manager.cc
index 49fc52e3..f4668526 100644
--- a/src/storage/lock_manager.cc
+++ b/src/storage/lock_manager.cc
@@ -37,9 +37,7 @@ LockManager::~LockManager() {
   }
 }
 
-unsigned LockManager::hash(const rocksdb::Slice &key) {
-  return static_cast<unsigned>(std::hash<std::string>{}(key.ToString()) & 
hash_mask_);
-}
+unsigned LockManager::hash(const rocksdb::Slice &key) { return 
std::hash<std::string>{}(key.ToString()) & hash_mask_; }
 
 unsigned LockManager::Size() { return (1U << hash_power_); }
 
diff --git a/src/storage/lock_manager.h b/src/storage/lock_manager.h
index 9520649b..e6ff30a0 100644
--- a/src/storage/lock_manager.h
+++ b/src/storage/lock_manager.h
@@ -39,7 +39,7 @@ class LockManager {
 
  private:
   int hash_power_;
-  int hash_mask_;
+  unsigned hash_mask_;
   std::vector<std::mutex *> mutex_pool_;
   unsigned hash(const rocksdb::Slice &key);
 };
diff --git a/src/storage/scripting.cc b/src/storage/scripting.cc
index 57ffcca6..7d165715 100644
--- a/src/storage/scripting.cc
+++ b/src/storage/scripting.cc
@@ -203,7 +203,7 @@ int redisLogCommand(lua_State *lua) {
     lua_pushstring(lua, "First argument must be a number (log level).");
     return lua_error(lua);
   }
-  level = lua_tonumber(lua, -argc);
+  level = static_cast<int>(lua_tonumber(lua, -argc));
   if (level < LL_DEBUG || level > LL_WARNING) {
     lua_pushstring(lua, "Invalid debug level.");
     return lua_error(lua);
@@ -269,7 +269,7 @@ Status evalGenericCommand(Redis::Connection *conn, const 
std::vector<std::string
   } else {
     for (int j = 0; j < 40; j++) {
       std::string sha = args[1];
-      funcname[j + 2] = (sha[j] >= 'A' && sha[j] <= 'Z') ? sha[j] + ('a' - 
'A') : sha[j];
+      funcname[j + 2] = (sha[j] >= 'A' && sha[j] <= 'Z') ? 
static_cast<char>(sha[j] + 'a' - 'A') : sha[j];
     }
     funcname[42] = '\0';
   }
@@ -835,7 +835,7 @@ void sortArray(lua_State *lua) {
 
 void setGlobalArray(lua_State *lua, const std::string &var, const 
std::vector<std::string> &elems) {
   lua_newtable(lua);
-  for (size_t i = 0; i < elems.size(); i++) {
+  for (int i = 0; i < elems.size(); i++) {
     lua_pushlstring(lua, elems[i].c_str(), elems[i].size());
     lua_rawseti(lua, -2, i + 1);
   }
diff --git a/src/storage/storage.cc b/src/storage/storage.cc
index b5f38a67..efb7e469 100644
--- a/src/storage/storage.cc
+++ b/src/storage/storage.cc
@@ -64,7 +64,7 @@ const char *kLuaFunctionPrefix = "lua_f_";
 
 const char *kReplicationIdKey = "replication_id_";
 
-const uint64_t kIORateLimitMaxMb = 1024000;
+const int64_t kIORateLimitMaxMb = 1024000;
 
 using rocksdb::Slice;
 
@@ -169,9 +169,10 @@ rocksdb::Options Storage::InitOptions() {
   options.dump_malloc_stats = true;
   sst_file_manager_ = 
std::shared_ptr<rocksdb::SstFileManager>(rocksdb::NewSstFileManager(rocksdb::Env::Default()));
   options.sst_file_manager = sst_file_manager_;
-  uint64_t max_io_mb = kIORateLimitMaxMb;
-  if (config_->max_io_mb > 0) max_io_mb = 
static_cast<uint64_t>(config_->max_io_mb);
-  rate_limiter_ = 
std::shared_ptr<rocksdb::RateLimiter>(rocksdb::NewGenericRateLimiter(max_io_mb 
* MiB));
+  int64_t max_io_mb = kIORateLimitMaxMb;
+  if (config_->max_io_mb > 0) max_io_mb = config_->max_io_mb;
+  rate_limiter_ =
+      
std::shared_ptr<rocksdb::RateLimiter>(rocksdb::NewGenericRateLimiter(max_io_mb 
* static_cast<int64_t>(MiB)));
   options.rate_limiter = rate_limiter_;
   options.delayed_write_rate = 
static_cast<uint64_t>(config_->RocksDB.delayed_write_rate);
   options.compaction_readahead_size = 
static_cast<size_t>(config_->RocksDB.compaction_readahead_size);
@@ -623,11 +624,11 @@ Status Storage::CheckDBSizeLimit() {
   return Status::OK();
 }
 
-void Storage::SetIORateLimit(uint64_t max_io_mb) {
+void Storage::SetIORateLimit(int64_t max_io_mb) {
   if (max_io_mb == 0) {
     max_io_mb = kIORateLimitMaxMb;
   }
-  rate_limiter_->SetBytesPerSecond(max_io_mb * MiB);
+  rate_limiter_->SetBytesPerSecond(max_io_mb * static_cast<int64_t>(MiB));
 }
 
 rocksdb::DB *Storage::GetDB() { return db_; }
@@ -646,7 +647,7 @@ Status Storage::WriteToPropagateCF(const std::string &key, 
const std::string &va
 
 bool Storage::ShiftReplId() {
   const char *charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-  const int charset_len = strlen(charset);
+  const int charset_len = static_cast<int>(strlen(charset));
 
   // Do nothing if don't enable rsid psync
   if (!config_->use_rsid_psync) return true;
diff --git a/src/storage/storage.h b/src/storage/storage.h
index 689eb2d0..01dd6130 100644
--- a/src/storage/storage.h
+++ b/src/storage/storage.h
@@ -103,7 +103,7 @@ class Storage {
   void PurgeOldBackups(uint32_t num_backups_to_keep, uint32_t 
backup_max_keep_hours);
   uint64_t GetTotalSize(const std::string &ns = kDefaultNamespace);
   Status CheckDBSizeLimit();
-  void SetIORateLimit(uint64_t max_io_mb);
+  void SetIORateLimit(int64_t max_io_mb);
 
   std::unique_ptr<RWLock::ReadLock> ReadLockGuard();
   std::unique_ptr<RWLock::WriteLock> WriteLockGuard();
diff --git a/src/types/geohash.cc b/src/types/geohash.cc
index 438731f3..c613abd4 100644
--- a/src/types/geohash.cc
+++ b/src/types/geohash.cc
@@ -180,9 +180,9 @@ int geohashEncode(const GeoHashRange *long_range, const 
GeoHashRange *lat_range,
   double long_offset = (longitude - long_range->min) / (long_range->max - 
long_range->min);
 
   /* convert to fixed point based on the step size */
-  lat_offset *= (1ULL << step);
-  long_offset *= (1ULL << step);
-  hash->bits = interleave64(lat_offset, long_offset);
+  lat_offset *= static_cast<double>(1ULL << step);
+  long_offset *= static_cast<double>(1ULL << step);
+  hash->bits = interleave64(static_cast<uint32_t>(lat_offset), 
static_cast<uint32_t>(long_offset));
   return 1;
 }
 
@@ -215,10 +215,10 @@ int geohashDecode(const GeoHashRange &long_range, const 
GeoHashRange &lat_range,
   /* divide by 2**step.
    * Then, for 0-1 coordinate, multiply times scale and add
      to the min to get the absolute coordinate. */
-  area->latitude.min = lat_range.min + (ilato * 1.0 / (1ull << step)) * 
lat_scale;
-  area->latitude.max = lat_range.min + ((ilato + 1) * 1.0 / (1ull << step)) * 
lat_scale;
-  area->longitude.min = long_range.min + (ilono * 1.0 / (1ull << step)) * 
long_scale;
-  area->longitude.max = long_range.min + ((ilono + 1) * 1.0 / (1ull << step)) 
* long_scale;
+  area->latitude.min = lat_range.min + (ilato * 1.0 / static_cast<double>(1ull 
<< step)) * lat_scale;
+  area->latitude.max = lat_range.min + ((ilato + 1) * 1.0 / 
static_cast<double>(1ull << step)) * lat_scale;
+  area->longitude.min = long_range.min + (ilono * 1.0 / 
static_cast<double>(1ull << step)) * long_scale;
+  area->longitude.max = long_range.min + ((ilono + 1) * 1.0 / 
static_cast<double>(1ull << step)) * long_scale;
 
   return 1;
 }
diff --git a/src/types/redis_bitmap.cc b/src/types/redis_bitmap.cc
index bb151cd7..c81d5414 100644
--- a/src/types/redis_bitmap.cc
+++ b/src/types/redis_bitmap.cc
@@ -165,7 +165,7 @@ rocksdb::Status Bitmap::GetString(const Slice &user_key, 
const uint32_t max_btos
         0x3F, 0xBF, 0x7F, 0xFF};
     for (uint32_t i = 0; i < valid_size; i++) {
       if (!fragment[i]) continue;
-      fragment[i] = swap_table[static_cast<uint8_t>(fragment[i])];
+      fragment[i] = 
static_cast<char>(swap_table[static_cast<uint8_t>(fragment[i])]);
       ;
     }
     value->replace(frag_index, valid_size, fragment.data(), valid_size);
@@ -211,9 +211,9 @@ rocksdb::Status Bitmap::SetBit(const Slice &user_key, 
uint32_t offset, bool new_
   uint32_t bit_offset = offset % 8;
   *old_bit = (value[byte_index] & (1 << bit_offset)) != 0;
   if (new_bit) {
-    value[byte_index] |= 1 << bit_offset;
+    value[byte_index] = static_cast<char>(value[byte_index] | (1 << 
bit_offset));
   } else {
-    value[byte_index] &= ~(1 << bit_offset);
+    value[byte_index] = static_cast<char>(value[byte_index] & (~(1 << 
bit_offset)));
   }
   rocksdb::WriteBatch batch;
   WriteBatchLogData log_data(kRedisBitmap, {std::to_string(kRedisCmdSetBit), 
std::to_string(offset)});
@@ -536,7 +536,7 @@ rocksdb::Status Bitmap::BitOp(BitOpFlags op_flag, const 
std::string &op_name, co
   res_metadata.size = max_size;
   res_metadata.Encode(&bytes);
   batch.Put(metadata_cf_handle_, ns_key, bytes);
-  *len = max_size;
+  *len = static_cast<int64_t>(max_size);
   return storage_->Write(storage_->DefaultWriteOptions(), &batch);
 }
 
diff --git a/src/types/redis_bitmap_string.cc b/src/types/redis_bitmap_string.cc
index 4aa0b1b9..f7859295 100644
--- a/src/types/redis_bitmap_string.cc
+++ b/src/types/redis_bitmap_string.cc
@@ -51,8 +51,8 @@ rocksdb::Status BitmapString::SetBit(const Slice &ns_key, 
std::string *raw_value
   auto byteval = string_value[byte_index];
   *old_bit = (byteval & (1 << bit_offset)) != 0;
 
-  byteval &= ~(1 << bit_offset);
-  byteval |= ((new_bit & 0x1) << bit_offset);
+  byteval = static_cast<char>(byteval & (~(1 << bit_offset)));
+  byteval = static_cast<char>(byteval | ((new_bit & 0x1) << bit_offset));
   string_value[byte_index] = byteval;
 
   *raw_value = raw_value->substr(0, STRING_HDR_SIZE);
@@ -71,12 +71,12 @@ rocksdb::Status BitmapString::BitCount(const std::string 
&raw_value, int64_t sta
   if (start < 0 && stop < 0 && start > stop) {
     return rocksdb::Status::OK();
   }
-  auto strlen = string_value.size();
+  auto strlen = static_cast<int64_t>(string_value.size());
   if (start < 0) start = strlen + start;
   if (stop < 0) stop = strlen + stop;
   if (start < 0) start = 0;
   if (stop < 0) stop = 0;
-  if (stop >= static_cast<int64_t>(strlen)) stop = strlen - 1;
+  if (stop >= strlen) stop = strlen - 1;
 
   /* Precondition: end >= 0 && end < strlen, so the only condition where
    * zero can be returned is: start > stop. */
@@ -90,13 +90,13 @@ rocksdb::Status BitmapString::BitCount(const std::string 
&raw_value, int64_t sta
 rocksdb::Status BitmapString::BitPos(const std::string &raw_value, bool bit, 
int64_t start, int64_t stop,
                                      bool stop_given, int64_t *pos) {
   auto string_value = raw_value.substr(STRING_HDR_SIZE, raw_value.size() - 
STRING_HDR_SIZE);
-  auto strlen = string_value.size();
+  auto strlen = static_cast<int64_t>(string_value.size());
   /* Convert negative indexes */
   if (start < 0) start = strlen + start;
   if (stop < 0) stop = strlen + stop;
   if (start < 0) start = 0;
   if (stop < 0) stop = 0;
-  if (stop >= static_cast<int64_t>(strlen)) stop = strlen - 1;
+  if (stop >= strlen) stop = strlen - 1;
 
   if (start > stop) {
     *pos = -1;
diff --git a/src/types/redis_geo.cc b/src/types/redis_geo.cc
index 348178b0..d4c27409 100644
--- a/src/types/redis_geo.cc
+++ b/src/types/redis_geo.cc
@@ -104,7 +104,7 @@ rocksdb::Status Geo::Radius(const Slice &user_key, double 
longitude, double lati
   }
 
   if (!store_key.empty()) {
-    int64_t result_length = geo_points->size();
+    auto result_length = static_cast<int64_t>(geo_points->size());
     int64_t returned_items_count = (count == 0 || result_length < count) ? 
result_length : count;
     if (returned_items_count == 0) {
       ZSet::Del(user_key);
@@ -195,7 +195,7 @@ std::string Geo::EncodeGeoHash(double longitude, double 
latitude) {
        * zero. */
       idx = 0;
     } else {
-      idx = (hash.bits >> (52 - ((i + 1) * 5))) & 0x1f;
+      idx = static_cast<int>((hash.bits >> (52 - ((i + 1) * 5))) & 0x1f);
     }
     geoHash += geoalphabet[idx];
   }
@@ -211,7 +211,8 @@ 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 = 0, count = 0, last_processed = 0;
+  unsigned int i = 0, last_processed = 0;
+  int count = 0;
 
   neighbors[0] = n.hash;
   neighbors[1] = n.neighbors.north;
@@ -252,7 +253,7 @@ int Geo::membersOfGeoHashBox(const Slice &user_key, 
GeoHashBits hash, std::vecto
   GeoHashFix52Bits min = 0, max = 0;
 
   scoresOfGeoHashBox(hash, &min, &max);
-  return getPointsInRange(user_key, min, max, lon, lat, radius, geo_points);
+  return getPointsInRange(user_key, static_cast<double>(min), 
static_cast<double>(max), lon, lat, radius, geo_points);
 }
 
 /* Compute the sorted set scores min (inclusive), max (exclusive) we should
diff --git a/src/types/redis_hash.cc b/src/types/redis_hash.cc
index 86444a0b..d7001b67 100644
--- a/src/types/redis_hash.cc
+++ b/src/types/redis_hash.cc
@@ -113,7 +113,7 @@ rocksdb::Status Hash::IncrBy(const Slice &user_key, const 
Slice &field, int64_t
 
 rocksdb::Status Hash::IncrByFloat(const Slice &user_key, const Slice &field, 
double increment, double *ret) {
   bool exists = false;
-  float old_value = 0;
+  double old_value = 0;
 
   std::string ns_key;
   AppendNamespacePrefix(user_key, &ns_key);
diff --git a/src/types/redis_list.cc b/src/types/redis_list.cc
index 3d45419e..d049bfda 100644
--- a/src/types/redis_list.cc
+++ b/src/types/redis_list.cc
@@ -84,7 +84,7 @@ rocksdb::Status List::push(const Slice &user_key, const 
std::vector<Slice> &elem
   metadata.size += elems.size();
   metadata.Encode(&bytes);
   batch.Put(metadata_cf_handle_, ns_key, bytes);
-  *ret = metadata.size;
+  *ret = static_cast<int>(metadata.size);
   return storage_->Write(storage_->DefaultWriteOptions(), &batch);
 }
 
@@ -334,7 +334,7 @@ rocksdb::Status List::Insert(const Slice &user_key, const 
Slice &pivot, const Sl
   metadata.Encode(&bytes);
   batch.Put(metadata_cf_handle_, ns_key, bytes);
 
-  *ret = metadata.size;
+  *ret = static_cast<int>(metadata.size);
   return storage_->Write(storage_->DefaultWriteOptions(), &batch);
 }
 
@@ -347,7 +347,7 @@ rocksdb::Status List::Index(const Slice &user_key, int 
index, std::string *elem)
   rocksdb::Status s = GetMetadata(ns_key, &metadata);
   if (!s.ok()) return s;
 
-  if (index < 0) index += metadata.size;
+  if (index < 0) index += static_cast<int>(metadata.size);
   if (index < 0 || index >= static_cast<int>(metadata.size)) return 
rocksdb::Status::NotFound();
 
   rocksdb::ReadOptions read_options;
@@ -414,7 +414,7 @@ rocksdb::Status List::Set(const Slice &user_key, int index, 
Slice elem) {
   ListMetadata metadata(false);
   rocksdb::Status s = GetMetadata(ns_key, &metadata);
   if (!s.ok()) return s;
-  if (index < 0) index = metadata.size + index;
+  if (index < 0) index += static_cast<int>(metadata.size);
   if (index < 0 || index >= static_cast<int>(metadata.size)) {
     return rocksdb::Status::InvalidArgument("index out of range");
   }
@@ -597,8 +597,8 @@ rocksdb::Status List::Trim(const Slice &user_key, int 
start, int stop) {
   rocksdb::Status s = GetMetadata(ns_key, &metadata);
   if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
 
-  if (start < 0) start = metadata.size + start;
-  if (stop < 0) stop = static_cast<int>(metadata.size) >= -1 * stop ? 
metadata.size + stop : -1;
+  if (start < 0) start += static_cast<int>(metadata.size);
+  if (stop < 0) stop = static_cast<int>(metadata.size) >= -1 * stop ? 
static_cast<int>(metadata.size) + stop : -1;
   // the result will be empty list when start > stop,
   // or start is larger than the end of list
   if (start > stop) {
diff --git a/src/types/redis_set.cc b/src/types/redis_set.cc
index 363e380d..ffcb182c 100644
--- a/src/types/redis_set.cc
+++ b/src/types/redis_set.cc
@@ -129,7 +129,7 @@ rocksdb::Status Set::Card(const Slice &user_key, int *ret) {
   SetMetadata metadata(false);
   rocksdb::Status s = GetMetadata(ns_key, &metadata);
   if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
-  *ret = metadata.size;
+  *ret = static_cast<int>(metadata.size);
   return rocksdb::Status::OK();
 }
 
diff --git a/src/types/redis_sortedint.cc b/src/types/redis_sortedint.cc
index bd4d1031..a79a1ac6 100644
--- a/src/types/redis_sortedint.cc
+++ b/src/types/redis_sortedint.cc
@@ -107,7 +107,7 @@ rocksdb::Status Sortedint::Card(const Slice &user_key, int 
*ret) {
   SortedintMetadata metadata(false);
   rocksdb::Status s = GetMetadata(ns_key, &metadata);
   if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
-  *ret = metadata.size;
+  *ret = static_cast<int>(metadata.size);
   return rocksdb::Status::OK();
 }
 
diff --git a/src/types/redis_string.cc b/src/types/redis_string.cc
index df665223..faa96fbb 100644
--- a/src/types/redis_string.cc
+++ b/src/types/redis_string.cc
@@ -148,10 +148,10 @@ rocksdb::Status String::Get(const std::string &user_key, 
std::string *value) {
 }
 
 rocksdb::Status String::GetEx(const std::string &user_key, std::string *value, 
int ttl) {
-  uint32_t expire = 0;
+  int expire = 0;
   if (ttl > 0) {
     int64_t now = Util::GetTimeStamp();
-    expire = uint32_t(now) + ttl;
+    expire = int(now) + ttl;
   }
   std::string ns_key;
   AppendNamespacePrefix(user_key, &ns_key);
@@ -219,10 +219,10 @@ rocksdb::Status String::SetNX(const std::string 
&user_key, const std::string &va
 rocksdb::Status String::SetXX(const std::string &user_key, const std::string 
&value, int ttl, int *ret) {
   *ret = 0;
   int exists = 0;
-  uint32_t expire = 0;
+  int expire = 0;
   if (ttl > 0) {
     int64_t now = Util::GetTimeStamp();
-    expire = uint32_t(now) + ttl;
+    expire = int(now) + ttl;
   }
 
   std::string ns_key;
@@ -358,10 +358,10 @@ rocksdb::Status String::IncrByFloat(const std::string 
&user_key, double incremen
 }
 
 rocksdb::Status String::MSet(const std::vector<StringPair> &pairs, int ttl) {
-  uint32_t expire = 0;
+  int expire = 0;
   if (ttl > 0) {
     int64_t now = Util::GetTimeStamp();
-    expire = uint32_t(now) + ttl;
+    expire = int(now) + ttl;
   }
 
   // Data race, key string maybe overwrite by other key while didn't lock the 
key here,
@@ -388,10 +388,10 @@ rocksdb::Status String::MSet(const 
std::vector<StringPair> &pairs, int ttl) {
 rocksdb::Status String::MSetNX(const std::vector<StringPair> &pairs, int ttl, 
int *ret) {
   *ret = 0;
 
-  uint32_t expire = 0;
+  int expire = 0;
   if (ttl > 0) {
     int64_t now = Util::GetTimeStamp();
-    expire = uint32_t(now) + ttl;
+    expire = int(now) + ttl;
   }
 
   int exists = 0;
@@ -453,11 +453,11 @@ rocksdb::Status String::CAS(const std::string &user_key, 
const std::string &old_
 
   if (old_value == current_value) {
     std::string raw_value;
-    uint32_t expire = 0;
+    int expire = 0;
     Metadata metadata(kRedisString, false);
     if (ttl > 0) {
       int64_t now = Util::GetTimeStamp();
-      expire = uint32_t(now) + ttl;
+      expire = int(now) + ttl;
     }
     metadata.expire = expire;
     metadata.Encode(&raw_value);
diff --git a/src/types/redis_zset.cc b/src/types/redis_zset.cc
index cdaa72d6..57aecd71 100644
--- a/src/types/redis_zset.cc
+++ b/src/types/redis_zset.cc
@@ -142,7 +142,7 @@ rocksdb::Status ZSet::Card(const Slice &user_key, int *ret) 
{
   ZSetMetadata metadata(false);
   rocksdb::Status s = GetMetadata(ns_key, &metadata);
   if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
-  *ret = metadata.size;
+  *ret = static_cast<int>(metadata.size);
   return rocksdb::Status::OK();
 }
 
@@ -172,7 +172,7 @@ rocksdb::Status ZSet::Pop(const Slice &user_key, int count, 
bool min, std::vecto
   rocksdb::Status s = GetMetadata(ns_key, &metadata);
   if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
   if (count <= 0) return rocksdb::Status::OK();
-  if (count > static_cast<int>(metadata.size)) count = metadata.size;
+  if (count > static_cast<int>(metadata.size)) count = 
static_cast<int>(metadata.size);
 
   std::string score_bytes;
   double score = min ? kMinScore : kMaxScore;
@@ -237,8 +237,8 @@ rocksdb::Status ZSet::Range(const Slice &user_key, int 
start, int stop, uint8_t
   ZSetMetadata metadata(false);
   rocksdb::Status s = GetMetadata(ns_key, &metadata);
   if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
-  if (start < 0) start += metadata.size;
-  if (stop < 0) stop += metadata.size;
+  if (start < 0) start += static_cast<int>(metadata.size);
+  if (stop < 0) stop += static_cast<int>(metadata.size);
   if (start < 0) start = 0;
   if (stop < 0 || start > stop) {
     return rocksdb::Status::OK();
@@ -704,7 +704,7 @@ rocksdb::Status ZSet::InterStore(const Slice &dst, const 
std::vector<KeyWeight>
       if (member_counters[iter.first] != keys_weights.size()) continue;
       mscores.emplace_back(MemberScore{iter.first, iter.second});
     }
-    if (size) *size = mscores.size();
+    if (size) *size = static_cast<int>(mscores.size());
     Overwrite(dst, mscores);
   }
 
@@ -754,7 +754,7 @@ rocksdb::Status ZSet::UnionStore(const Slice &dst, const 
std::vector<KeyWeight>
     for (const auto &iter : dst_zset) {
       mscores.emplace_back(MemberScore{iter.first, iter.second});
     }
-    if (size) *size = mscores.size();
+    if (size) *size = static_cast<int>(mscores.size());
     Overwrite(dst, mscores);
   }
 

Reply via email to