diff options
author | Kane York <kanepyork@gmail.com> | 2020-07-25T04·09-0700 |
---|---|---|
committer | kanepyork <rikingcoding@gmail.com> | 2020-07-27T21·16+0000 |
commit | ef54f5da9fa30b5c302f2a49595ee5d041f9706a (patch) | |
tree | 8d1da709a2e2d3b135d1e84eda9c402bde467726 /third_party/nix/src/libstore/download.cc | |
parent | 69f402563a14d4b668980e4228d033d80e3bb05d (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/download.cc')
-rw-r--r-- | third_party/nix/src/libstore/download.cc | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/third_party/nix/src/libstore/download.cc b/third_party/nix/src/libstore/download.cc index e73181e73109..dfa72e3eb09f 100644 --- a/third_party/nix/src/libstore/download.cc +++ b/third_party/nix/src/libstore/download.cc @@ -160,7 +160,7 @@ struct CurlDownloader : public Downloader { decompressionSink = makeDecompressionSink(encoding, finalSink); } - (*decompressionSink)((unsigned char*)contents, realSize); + (*decompressionSink)(static_cast<unsigned char*>(contents), realSize); return realSize; } catch (...) { @@ -171,12 +171,13 @@ struct CurlDownloader : public Downloader { static size_t writeCallbackWrapper(void* contents, size_t size, size_t nmemb, void* userp) { - return ((DownloadItem*)userp)->writeCallback(contents, size, nmemb); + return (static_cast<DownloadItem*>(userp)) + ->writeCallback(contents, size, nmemb); } size_t headerCallback(void* contents, size_t size, size_t nmemb) { size_t realSize = size * nmemb; - std::string line((char*)contents, realSize); + std::string line(static_cast<char*>(contents), realSize); DLOG(INFO) << "got header for '" << request.uri << "': " << absl::StripAsciiWhitespace(line); if (line.compare(0, 5, "HTTP/") == 0) { // new response starts @@ -218,7 +219,8 @@ struct CurlDownloader : public Downloader { static size_t headerCallbackWrapper(void* contents, size_t size, size_t nmemb, void* userp) { - return ((DownloadItem*)userp)->headerCallback(contents, size, nmemb); + return (static_cast<DownloadItem*>(userp)) + ->headerCallback(contents, size, nmemb); } static int debugCallback(CURL* handle, curl_infotype type, char* data, @@ -245,7 +247,8 @@ struct CurlDownloader : public Downloader { static size_t readCallbackWrapper(char* buffer, size_t size, size_t nitems, void* userp) { - return ((DownloadItem*)userp)->readCallback(buffer, size, nitems); + return (static_cast<DownloadItem*>(userp)) + ->readCallback(buffer, size, nitems); } void init() { @@ -337,7 +340,7 @@ struct CurlDownloader : public Downloader { long httpStatus = 0; curl_easy_getinfo(req, CURLINFO_RESPONSE_CODE, &httpStatus); - char* effectiveUriCStr; + char* effectiveUriCStr = nullptr; curl_easy_getinfo(req, CURLINFO_EFFECTIVE_URL, &effectiveUriCStr); if (effectiveUriCStr != nullptr) { result.effectiveUri = effectiveUriCStr; @@ -546,7 +549,7 @@ struct CurlDownloader : public Downloader { checkInterrupt(); /* Let curl do its thing. */ - int running; + int running = 0; CURLMcode mc = curl_multi_perform(curlm, &running); if (mc != CURLM_OK) { throw nix::Error( @@ -555,8 +558,8 @@ struct CurlDownloader : public Downloader { } /* Set the promises of any finished requests. */ - CURLMsg* msg; - int left; + CURLMsg* msg = nullptr; + int left = 0; while ((msg = curl_multi_info_read(curlm, &left)) != nullptr) { if (msg->msg == CURLMSG_DONE) { auto i = items.find(msg->easy_handle); @@ -579,9 +582,10 @@ struct CurlDownloader : public Downloader { nextWakeup != std::chrono::steady_clock::time_point() ? std::max( 0, - (int)std::chrono::duration_cast<std::chrono::milliseconds>( - nextWakeup - std::chrono::steady_clock::now()) - .count()) + static_cast<int>( + std::chrono::duration_cast<std::chrono::milliseconds>( + nextWakeup - std::chrono::steady_clock::now()) + .count())) : maxSleepTimeMs; DLOG(INFO) << "download thread waiting for " << sleepTimeMs << " ms"; mc = curl_multi_wait(curlm, extraFDs, 1, sleepTimeMs, &numfds); @@ -844,7 +848,7 @@ void Downloader::download(DownloadRequest&& request, Sink& sink) { if it's blocked on a full buffer. We don't hold the state lock while doing this to prevent blocking the download thread if sink() takes a long time. */ - sink((unsigned char*)chunk.data(), chunk.size()); + sink(reinterpret_cast<unsigned char*>(chunk.data()), chunk.size()); } } @@ -898,9 +902,10 @@ CachedDownloadResult Downloader::downloadCached( std::vector<std::string> ss = absl::StrSplit(readFile(dataFile), absl::ByChar('\n')); if (ss.size() >= 3 && ss[0] == url) { - time_t lastChecked; + time_t lastChecked = 0; if (absl::SimpleAtoi(ss[2], &lastChecked) && - (uint64_t)lastChecked + request.ttl >= (uint64_t)time(nullptr)) { + static_cast<uint64_t>(lastChecked) + request.ttl >= + static_cast<uint64_t>(time(nullptr))) { skip = true; result.effectiveUri = request.uri; result.etag = ss[1]; |