chore(3p/nix): apply google-readability-casting

Command run: jq <compile_commands.json -r 'map(.file)|.[]' | grep -v '/generated/' | parallel clang-tidy -p compile_commands.json -checks=-*,google-readability-casting --fix

Manual fixes applied in src/nix-env/nix-env.cc, src/libstore/store-api.cc

Change-Id: I406b4be9368c557ca59329bf6f7002704e955f8d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1557
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Kane York 2020-08-01 17:17:44 -07:00 committed by kanepyork
parent 053a138002
commit 1de00e6c42
40 changed files with 161 additions and 125 deletions

View file

@ -88,7 +88,7 @@ void BinaryCacheStore::getFile(const std::string& path, Sink& sink) {
}
}});
auto data = promise.get_future().get();
sink((unsigned char*)data->data(), data->size());
sink(reinterpret_cast<unsigned char*>(data->data()), data->size());
}
std::shared_ptr<std::string> BinaryCacheStore::getFile(
@ -206,7 +206,9 @@ void BinaryCacheStore::addToStore(const ValidPathInfo& info,
.count();
DLOG(INFO) << "copying path '" << narInfo->path << "' (" << narInfo->narSize
<< " bytes, compressed "
<< ((1.0 - (double)narCompressed->size() / nar->size()) * 100.0)
<< ((1.0 -
static_cast<double>(narCompressed->size()) / nar->size()) *
100.0)
<< "% in " << duration << "ms) to binary cache";
/* Atomically write the NAR file. */
@ -288,9 +290,8 @@ void BinaryCacheStore::queryPathInfoUncached(
stats.narInfoRead++;
(*callbackPtr)(
(std::shared_ptr<ValidPathInfo>)std::make_shared<NarInfo>(
*this, *data, narInfoFile));
(*callbackPtr)(std::shared_ptr<ValidPathInfo>(
std::make_shared<NarInfo>(*this, *data, narInfoFile)));
} catch (...) {
callbackPtr->rethrow();

View file

@ -1589,11 +1589,13 @@ MakeError(NotDeterministic, BuildError)
8ULL * 1024 * 1024; // FIXME: make configurable
struct statvfs st;
if (statvfs(worker.store.realStoreDir.c_str(), &st) == 0 &&
(unsigned long long)st.f_bavail * st.f_bsize < required) {
static_cast<unsigned long long>(st.f_bavail) * st.f_bsize <
required) {
diskFull = true;
}
if (statvfs(tmpDir.c_str(), &st) == 0 &&
(unsigned long long)st.f_bavail * st.f_bsize < required) {
static_cast<unsigned long long>(st.f_bavail) * st.f_bsize <
required) {
diskFull = true;
}
#endif
@ -1832,7 +1834,7 @@ void chmod_(const Path& path, mode_t mode) {
}
int childEntry(void* arg) {
((DerivationGoal*)arg)->runChild();
(static_cast<DerivationGoal*>(arg))->runChild();
return 1;
}
@ -2361,9 +2363,9 @@ void DerivationGoal::startBuilder() {
}
size_t stackSize = 1 * 1024 * 1024;
char* stack =
(char*)mmap(nullptr, stackSize, PROT_WRITE | PROT_READ,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
char* stack = static_cast<char*>(
mmap(nullptr, stackSize, PROT_WRITE | PROT_READ,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0));
if (stack == MAP_FAILED) {
throw SysError("allocating stack");
}
@ -4483,9 +4485,9 @@ void Worker::waitForInput() {
}
if (nearest != steady_time_point::max()) {
timeout.tv_sec = std::max(
1L,
(long)std::chrono::duration_cast<std::chrono::seconds>(nearest - before)
.count());
1L, static_cast<long>(std::chrono::duration_cast<std::chrono::seconds>(
nearest - before)
.count()));
useTimeout = true;
}
@ -4500,10 +4502,11 @@ void Worker::waitForInput() {
lastWokenUp = before;
}
timeout.tv_sec = std::max(
1L,
(long)std::chrono::duration_cast<std::chrono::seconds>(
lastWokenUp + std::chrono::seconds(settings.pollInterval) - before)
.count());
1L, static_cast<long>(std::chrono::duration_cast<std::chrono::seconds>(
lastWokenUp +
std::chrono::seconds(settings.pollInterval) -
before)
.count()));
} else {
lastWokenUp = steady_time_point::min();
}
@ -4568,7 +4571,7 @@ void Worker::waitForInput() {
}
} else {
DLOG(INFO) << goal->getName() << ": read " << rd << " bytes";
std::string data((char*)buffer.data(), rd);
std::string data(reinterpret_cast<char*>(buffer.data()), rd);
j->lastOutput = after;
goal->handleChildOutput(k, data);
}

View file

@ -58,7 +58,8 @@ std::string SecretKey::signDetached(const std::string& data) const {
unsigned long long sigLen;
crypto_sign_detached(sig, &sigLen, (unsigned char*)data.data(), data.size(),
(unsigned char*)key.data());
return name + ":" + absl::Base64Escape(std::string((char*)sig, sigLen));
return name + ":" +
absl::Base64Escape(std::string(reinterpret_cast<char*>(sig), sigLen));
#else
noSodium();
#endif
@ -68,7 +69,8 @@ PublicKey SecretKey::toPublicKey() const {
#if HAVE_SODIUM
unsigned char pk[crypto_sign_PUBLICKEYBYTES];
crypto_sign_ed25519_sk_to_pk(pk, (unsigned char*)key.data());
return PublicKey(name, std::string((char*)pk, crypto_sign_PUBLICKEYBYTES));
return PublicKey(name, std::string(reinterpret_cast<char*>(pk),
crypto_sign_PUBLICKEYBYTES));
#else
noSodium();
#endif
@ -102,8 +104,9 @@ bool verifyDetached(const std::string& data, const std::string& sig,
}
return crypto_sign_verify_detached(
(unsigned char*)sig2.data(), (unsigned char*)data.data(),
data.size(), (unsigned char*)key->second.key.data()) == 0;
reinterpret_cast<unsigned char*>(sig2.data()),
(unsigned char*)data.data(), data.size(),
(unsigned char*)key->second.key.data()) == 0;
#else
noSodium();
#endif

View file

@ -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
@ -219,7 +220,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,
@ -246,7 +248,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() {
@ -580,9 +583,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);
@ -846,7 +850,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());
}
}
@ -902,7 +906,8 @@ CachedDownloadResult Downloader::downloadCached(
if (ss.size() >= 3 && ss[0] == url) {
time_t lastChecked;
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];

View file

@ -241,7 +241,8 @@ void LocalStore::findTempRoots(FDs& fds, Roots& tempRoots, bool censor) {
std::string::size_type pos = 0;
std::string::size_type end;
while ((end = contents.find((char)0, pos)) != std::string::npos) {
while ((end = contents.find(static_cast<char>(0), pos)) !=
std::string::npos) {
Path root(contents, pos, end - pos);
DLOG(INFO) << "got temporary root " << root;
assertStorePath(root);
@ -916,7 +917,7 @@ void LocalStore::autoGC(bool sync) {
throw SysError("getting filesystem info about '%s'", realStoreDir);
}
return (uint64_t)st.f_bavail * st.f_bsize;
return static_cast<uint64_t>(st.f_bavail) * st.f_bsize;
};
std::shared_future<void> future;

View file

@ -214,7 +214,7 @@ struct LegacySSHStore : public Store {
conn->to.flush();
BuildResult status;
status.status = (BuildResult::Status)readInt(conn->from);
status.status = static_cast<BuildResult::Status>(readInt(conn->from));
conn->from >> status.errorMsg;
if (GET_PROTOCOL_MINOR(conn->remoteVersion) >= 3) {

View file

@ -41,7 +41,7 @@ struct LocalStoreAccessor : public FSAccessor {
return {S_ISREG(st.st_mode)
? Type::tRegular
: S_ISLNK(st.st_mode) ? Type::tSymlink : Type::tDirectory,
S_ISREG(st.st_mode) ? (uint64_t)st.st_size : 0,
S_ISREG(st.st_mode) ? static_cast<uint64_t>(st.st_size) : 0,
S_ISREG(st.st_mode) && ((st.st_mode & S_IXUSR) != 0u)};
}

View file

@ -350,7 +350,8 @@ void LocalStore::openDB(State& state, bool create) {
if (sqlite3_step(stmt) != SQLITE_ROW) {
throwSQLiteError(db, "querying journal mode");
}
prevMode = std::string((const char*)sqlite3_column_text(stmt, 0));
prevMode = std::string(
reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
}
if (prevMode != mode &&
sqlite3_exec(db, ("pragma main.journal_mode = " + mode + ";").c_str(),
@ -489,7 +490,7 @@ static void canonicalisePathMetaData_(const Path& path, uid_t fromUid,
However, ignore files that we chown'ed ourselves previously to
ensure that we don't fail on hard links within the same build
(i.e. "touch $out/foo; ln $out/foo $out/bar"). */
if (fromUid != (uid_t)-1 && st.st_uid != fromUid) {
if (fromUid != static_cast<uid_t>(-1) && st.st_uid != fromUid) {
if (S_ISDIR(st.st_mode)) {
throw BuildError(format("invalid file '%1%': is a directory") % path);
}
@ -690,7 +691,8 @@ void LocalStore::queryPathInfoUncached(
info->registrationTime = useQueryPathInfo.getInt(2);
auto s = (const char*)sqlite3_column_text(state->stmtQueryPathInfo, 3);
auto s = reinterpret_cast<const char*>(
sqlite3_column_text(state->stmtQueryPathInfo, 3));
if (s != nullptr) {
info->deriver = s;
}
@ -700,12 +702,14 @@ void LocalStore::queryPathInfoUncached(
info->ultimate = useQueryPathInfo.getInt(5) == 1;
s = (const char*)sqlite3_column_text(state->stmtQueryPathInfo, 6);
s = reinterpret_cast<const char*>(
sqlite3_column_text(state->stmtQueryPathInfo, 6));
if (s != nullptr) {
info->sigs = absl::StrSplit(s, absl::ByChar(' '), absl::SkipEmpty());
}
s = (const char*)sqlite3_column_text(state->stmtQueryPathInfo, 7);
s = reinterpret_cast<const char*>(
sqlite3_column_text(state->stmtQueryPathInfo, 7));
if (s != nullptr) {
info->ca = s;
}
@ -860,8 +864,8 @@ Path LocalStore::queryPathFromHashPart(const std::string& hashPart) {
return "";
}
const char* s =
(const char*)sqlite3_column_text(state->stmtQueryPathFromHashPart, 0);
const char* s = reinterpret_cast<const char*>(
sqlite3_column_text(state->stmtQueryPathFromHashPart, 0));
return (s != nullptr) &&
prefix.compare(0, prefix.size(), s, prefix.size()) == 0
? s

View file

@ -76,7 +76,7 @@ struct NarAccessor : public FSAccessor {
void preallocateContents(unsigned long long size) override {
currentStart = std::string(s, pos, 16);
assert(size <= std::numeric_limits<size_t>::max());
parents.top()->size = (size_t)size;
parents.top()->size = static_cast<size_t>(size);
parents.top()->start = pos;
}

View file

@ -164,8 +164,9 @@ class NarInfoDiskCacheImpl final : public NarInfoDiskCache {
static_cast<int64_t>(wantMassQuery))(priority)
.exec();
assert(sqlite3_changes(state->db) == 1);
state->caches[uri] = Cache{(int)sqlite3_last_insert_rowid(state->db),
storeDir, wantMassQuery, priority};
state->caches[uri] =
Cache{static_cast<int>(sqlite3_last_insert_rowid(state->db)),
storeDir, wantMassQuery, priority};
});
}
@ -181,8 +182,9 @@ class NarInfoDiskCacheImpl final : public NarInfoDiskCache {
return false;
}
state->caches.emplace(
uri, Cache{(int)queryCache.getInt(0), queryCache.getStr(1),
queryCache.getInt(2) != 0, (int)queryCache.getInt(3)});
uri, Cache{static_cast<int>(queryCache.getInt(0)),
queryCache.getStr(1), queryCache.getInt(2) != 0,
static_cast<int>(queryCache.getInt(3))});
}
auto& cache(getCache(*state, uri));

View file

@ -75,12 +75,14 @@ std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path& path_) {
throw SysError("opening NAR cache file '%s'", cacheFile);
}
if (lseek(fd.get(), offset, SEEK_SET) != (off_t)offset) {
if (lseek(fd.get(), offset, SEEK_SET) !=
static_cast<off_t>(offset)) {
throw SysError("seeking in '%s'", cacheFile);
}
std::string buf(length, 0);
readFull(fd.get(), (unsigned char*)buf.data(), length);
readFull(fd.get(), reinterpret_cast<unsigned char*>(buf.data()),
length);
return buf;
});

View file

@ -546,7 +546,7 @@ BuildResult RemoteStore::buildDerivation(const Path& drvPath,
BuildResult res;
unsigned int status;
conn->from >> status >> res.errorMsg;
res.status = (BuildResult::Status)status;
res.status = static_cast<BuildResult::Status>(status);
return res;
}

View file

@ -133,7 +133,7 @@ bool SQLiteStmt::Use::next() {
}
std::string SQLiteStmt::Use::getStr(int col) {
auto s = (const char*)sqlite3_column_text(stmt, col);
auto s = reinterpret_cast<const char*>(sqlite3_column_text(stmt, col));
assert(s);
return s;
}

View file

@ -111,7 +111,7 @@ Path SSHMaster::startMaster() {
state->tmpDir =
std::make_unique<AutoDelete>(createTempDir("", "nix", true, true, 0700));
state->socketPath = (Path)*state->tmpDir + "/ssh.sock";
state->socketPath = Path(*state->tmpDir) + "/ssh.sock";
Pipe out;
out.create();

View file

@ -304,8 +304,8 @@ Path Store::makeFixedOutputPath(bool recursive, const Hash& hash,
"output:out",
hashString(
htSHA256,
"fixed:out:" + (recursive ? (std::string) "r:" : "") +
hash.to_string(Base16) + ":"),
absl::StrCat("fixed:out:", (recursive ? "r:" : ""),
hash.to_string(Base16), ":")),
name);
}
@ -926,7 +926,7 @@ Strings ValidPathInfo::shortRefs() const {
}
std::string makeFixedOutputCA(bool recursive, const Hash& hash) {
return "fixed:" + (recursive ? (std::string) "r:" : "") + hash.to_string();
return "fixed:" + (recursive ? std::string("r:") : "") + hash.to_string();
}
void Store::addToStore(const ValidPathInfo& info, Source& narSource,