From ef54f5da9fa30b5c302f2a49595ee5d041f9706a Mon Sep 17 00:00:00 2001 From: Kane York Date: Fri, 24 Jul 2020 21:09:44 -0700 Subject: fix(3p/nix): apply all clang-tidy fixes Change-Id: I265e763393422ee1881653527c91024458060825 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1432 Tested-by: BuildkiteCI Reviewed-by: tazjin --- third_party/nix/src/libstore/references.cc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'third_party/nix/src/libstore/references.cc') diff --git a/third_party/nix/src/libstore/references.cc b/third_party/nix/src/libstore/references.cc index ea9ce44275..b70d282e8d 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(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(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(data), + len > refLength ? refLength : len); + search(reinterpret_cast(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(data) + len - tailLen, tailLen); } PathSet scanForReferences(const std::string& path, const PathSet& refs, -- cgit 1.4.1