diff options
Diffstat (limited to 'third_party/nix/src/libstore/references.cc')
-rw-r--r-- | third_party/nix/src/libstore/references.cc | 24 |
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, |