about summary refs log tree commit diff
path: root/third_party/nix/src/libstore/references.cc
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-07-25T04·09-0700
committerkanepyork <rikingcoding@gmail.com>2020-07-27T21·16+0000
commitef54f5da9fa30b5c302f2a49595ee5d041f9706a (patch)
tree8d1da709a2e2d3b135d1e84eda9c402bde467726 /third_party/nix/src/libstore/references.cc
parent69f402563a14d4b668980e4228d033d80e3bb05d (diff)
fix(3p/nix): apply all clang-tidy fixes r/1495
Change-Id: I265e763393422ee1881653527c91024458060825
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1432
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'third_party/nix/src/libstore/references.cc')
-rw-r--r--third_party/nix/src/libstore/references.cc24
1 files changed, 13 insertions, 11 deletions
diff --git a/third_party/nix/src/libstore/references.cc b/third_party/nix/src/libstore/references.cc
index ea9ce44275a0..b70d282e8df8 100644
--- a/third_party/nix/src/libstore/references.cc
+++ b/third_party/nix/src/libstore/references.cc
@@ -22,16 +22,16 @@ static void search(const unsigned char* s, size_t len, StringSet& hashes,
       i = false;
     }
     for (char base32Char : base32Chars) {
-      isBase32[(unsigned char)base32Char] = true;
+      isBase32[static_cast<unsigned char>(base32Char)] = true;
     }
     initialised = true;
   }
 
   for (size_t i = 0; i + refLength <= len;) {
-    int j;
+    int j = 0;
     bool match = true;
     for (j = refLength - 1; j >= 0; --j) {
-      if (!isBase32[(unsigned char)s[i + j]]) {
+      if (!isBase32[s[i + j]]) {
         i += j + 1;
         match = false;
         break;
@@ -40,7 +40,7 @@ static void search(const unsigned char* s, size_t len, StringSet& hashes,
     if (!match) {
       continue;
     }
-    std::string ref((const char*)s + i, refLength);
+    std::string ref(reinterpret_cast<const char*>(s) + i, refLength);
     if (hashes.find(ref) != hashes.end()) {
       DLOG(INFO) << "found reference to '" << ref << "' at offset " << i;
       seen.insert(ref);
@@ -68,17 +68,19 @@ void RefScanSink::operator()(const unsigned char* data, size_t len) {
   /* It's possible that a reference spans the previous and current
      fragment, so search in the concatenation of the tail of the
      previous fragment and the start of the current fragment. */
-  std::string s =
-      tail + std::string((const char*)data, len > refLength ? refLength : len);
-  search((const unsigned char*)s.data(), s.size(), hashes, seen);
+  std::string s = tail + std::string(reinterpret_cast<const char*>(data),
+                                     len > refLength ? refLength : len);
+  search(reinterpret_cast<const unsigned char*>(s.data()), s.size(), hashes,
+         seen);
 
   search(data, len, hashes, seen);
 
   size_t tailLen = len <= refLength ? len : refLength;
-  tail = std::string(tail, tail.size() < refLength - tailLen
-                               ? 0
-                               : tail.size() - (refLength - tailLen)) +
-         std::string((const char*)data + len - tailLen, tailLen);
+  tail =
+      std::string(tail, tail.size() < refLength - tailLen
+                            ? 0
+                            : tail.size() - (refLength - tailLen)) +
+      std::string(reinterpret_cast<const char*>(data) + len - tailLen, tailLen);
 }
 
 PathSet scanForReferences(const std::string& path, const PathSet& refs,