fix(3p/nix): revert "apply all clang-tidy fixes"

This reverts commit ef54f5da9f.

Resolved conflicts:
	third_party/nix/src/libexpr/eval.cc
	third_party/nix/src/libstore/builtins/fetchurl.cc
	third_party/nix/src/libstore/references.cc
	third_party/nix/src/libutil/hash.cc
	third_party/nix/src/nix-daemon/nix-daemon.cc

Change-Id: Ib9cf6e96a79a23bde3983579ced3f92e530cb011
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1547
Reviewed-by: glittershark <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Kane York 2020-08-01 15:32:00 -07:00 committed by kanepyork
parent cc3c45f739
commit 72fc2fd27e
64 changed files with 479 additions and 555 deletions

View file

@ -66,7 +66,7 @@ static void dumpContents(const Path& path, size_t size, Sink& sink) {
static void dump(const Path& path, Sink& sink, PathFilter& filter) {
checkInterrupt();
struct stat st {};
struct stat st;
if (lstat(path.c_str(), &st) != 0) {
throw SysError(format("getting attributes of path '%1%'") % path);
}
@ -80,7 +80,7 @@ static void dump(const Path& path, Sink& sink, PathFilter& filter) {
sink << "executable"
<< "";
}
dumpContents(path, static_cast<size_t>(st.st_size), sink);
dumpContents(path, (size_t)st.st_size, sink);
}
else if (S_ISDIR(st.st_mode)) {
@ -159,7 +159,7 @@ static void skipGeneric(Source & source)
}
#endif
static void parseContents(ParseSink& sink, Source& source) {
static void parseContents(ParseSink& sink, Source& source, const Path& path) {
unsigned long long size = readLongLong(source);
sink.preallocateContents(size);
@ -170,7 +170,7 @@ static void parseContents(ParseSink& sink, Source& source) {
while (left != 0u) {
checkInterrupt();
auto n = buf.size();
if (static_cast<unsigned long long>(n) > left) {
if ((unsigned long long)n > left) {
n = left;
}
source(buf.data(), n);
@ -235,7 +235,7 @@ static void parse(ParseSink& sink, Source& source, const Path& path) {
}
else if (s == "contents" && type == tpRegular) {
parseContents(sink, source);
parseContents(sink, source, path);
}
else if (s == "executable" && type == tpRegular) {
@ -267,7 +267,7 @@ static void parse(ParseSink& sink, Source& source, const Path& path) {
name = readString(source);
if (name.empty() || name == "." || name == ".." ||
name.find('/') != std::string::npos ||
name.find('\0') != std::string::npos) {
name.find((char)0) != std::string::npos) {
throw Error(format("NAR contains invalid file name '%1%'") % name);
}
if (name <= prevName) {
@ -341,7 +341,7 @@ struct RestoreSink : ParseSink {
}
void isExecutable() override {
struct stat st {};
struct stat st;
if (fstat(fd.get(), &st) == -1) {
throw SysError("fstat");
}

View file

@ -27,12 +27,12 @@ void Args::parseCmdline(const Strings& _cmdline) {
`-j3` -> `-j 3`). */
if (!dashDash && arg.length() > 2 && arg[0] == '-' && arg[1] != '-' &&
(isalpha(arg[1]) != 0)) {
*pos = std::string("-") + arg[1];
*pos = (std::string) "-" + arg[1];
auto next = pos;
++next;
for (unsigned int j = 2; j < arg.length(); j++) {
if (isalpha(arg[j]) != 0) {
cmdline.insert(next, std::string("-") + arg[j]);
cmdline.insert(next, (std::string) "-" + arg[j]);
} else {
cmdline.insert(next, std::string(arg, j));
break;

View file

@ -17,7 +17,7 @@ namespace nix {
// Don't feed brotli too much at once.
struct ChunkedCompressionSink : CompressionSink {
uint8_t outbuf[32 * 1024]{};
uint8_t outbuf[32 * 1024];
void write(const unsigned char* data, size_t len) override {
const size_t CHUNK_SIZE = sizeof(outbuf) << 2;
@ -43,7 +43,7 @@ struct NoneSink : CompressionSink {
struct XzDecompressionSink : CompressionSink {
Sink& nextSink;
uint8_t outbuf[BUFSIZ]{};
uint8_t outbuf[BUFSIZ];
lzma_stream strm = LZMA_STREAM_INIT;
bool finished = false;
@ -89,7 +89,7 @@ struct XzDecompressionSink : CompressionSink {
struct BzipDecompressionSink : ChunkedCompressionSink {
Sink& nextSink;
bz_stream strm{};
bz_stream strm;
bool finished = false;
explicit BzipDecompressionSink(Sink& nextSink) : nextSink(nextSink) {
@ -99,7 +99,7 @@ struct BzipDecompressionSink : ChunkedCompressionSink {
throw CompressionError("unable to initialise bzip2 decoder");
}
strm.next_out = reinterpret_cast<char*>(outbuf);
strm.next_out = (char*)outbuf;
strm.avail_out = sizeof(outbuf);
}
@ -128,7 +128,7 @@ struct BzipDecompressionSink : ChunkedCompressionSink {
if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) {
nextSink(outbuf, sizeof(outbuf) - strm.avail_out);
strm.next_out = reinterpret_cast<char*>(outbuf);
strm.next_out = (char*)outbuf;
strm.avail_out = sizeof(outbuf);
}
}
@ -205,12 +205,12 @@ ref<CompressionSink> makeDecompressionSink(const std::string& method,
struct XzCompressionSink : CompressionSink {
Sink& nextSink;
uint8_t outbuf[BUFSIZ]{};
uint8_t outbuf[BUFSIZ];
lzma_stream strm = LZMA_STREAM_INIT;
bool finished = false;
XzCompressionSink(Sink& nextSink, bool parallel) : nextSink(nextSink) {
lzma_ret ret{};
lzma_ret ret;
bool done = false;
if (parallel) {
@ -277,7 +277,7 @@ struct XzCompressionSink : CompressionSink {
struct BzipCompressionSink : ChunkedCompressionSink {
Sink& nextSink;
bz_stream strm{};
bz_stream strm;
bool finished = false;
explicit BzipCompressionSink(Sink& nextSink) : nextSink(nextSink) {
@ -287,7 +287,7 @@ struct BzipCompressionSink : ChunkedCompressionSink {
throw CompressionError("unable to initialise bzip2 encoder");
}
strm.next_out = reinterpret_cast<char*>(outbuf);
strm.next_out = (char*)outbuf;
strm.avail_out = sizeof(outbuf);
}
@ -316,7 +316,7 @@ struct BzipCompressionSink : ChunkedCompressionSink {
if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) {
nextSink(outbuf, sizeof(outbuf) - strm.avail_out);
strm.next_out = reinterpret_cast<char*>(outbuf);
strm.next_out = (char*)outbuf;
strm.avail_out = sizeof(outbuf);
}
}
@ -325,7 +325,7 @@ struct BzipCompressionSink : ChunkedCompressionSink {
struct BrotliCompressionSink : ChunkedCompressionSink {
Sink& nextSink;
uint8_t outbuf[BUFSIZ]{};
uint8_t outbuf[BUFSIZ];
BrotliEncoderState* state;
bool finished = false;

View file

@ -154,7 +154,7 @@ static std::string printHash32(const Hash& hash) {
std::string s;
s.reserve(len);
for (int n = static_cast<int>(len) - 1; n >= 0; n--) {
for (int n = (int)len - 1; n >= 0; n--) {
unsigned int b = n * 5;
unsigned int i = b / 8;
unsigned int j = b % 8;
@ -187,8 +187,7 @@ std::string Hash::to_string(Base base, bool includeType) const {
case Base64:
case SRI:
std::string b64;
absl::Base64Escape(
std::string(reinterpret_cast<const char*>(hash), hashSize), &b64);
absl::Base64Escape(std::string((const char*)hash, hashSize), &b64);
s += b64;
break;
}
@ -355,7 +354,7 @@ Hash hashString(HashType ht, const std::string& s) {
hash::Ctx ctx{};
Hash hash(ht);
start(ht, ctx);
update(ht, ctx, reinterpret_cast<const unsigned char*>(s.data()), s.length());
update(ht, ctx, (const unsigned char*)s.data(), s.length());
finish(ht, ctx, hash.hash);
return hash;
}
@ -371,7 +370,7 @@ Hash hashFile(HashType ht, const Path& path) {
}
std::vector<unsigned char> buf(8192);
ssize_t n = 0;
ssize_t n;
while ((n = read(fd.get(), buf.data(), buf.size())) != 0) {
checkInterrupt();
if (n == -1) {

View file

@ -18,7 +18,7 @@ void toJSON(std::ostream& str, const char* start, const char* end) {
str << "\\t";
} else if (*i >= 0 && *i < 32) {
str << "\\u" << std::setfill('0') << std::setw(4) << std::hex
<< static_cast<uint16_t>(*i) << std::dec;
<< (uint16_t)*i << std::dec;
} else {
str << *i;
}

View file

@ -93,10 +93,10 @@ std::string Source::drain() {
std::string s;
std::vector<unsigned char> buf(8192);
while (true) {
size_t n = 0;
size_t n;
try {
n = read(buf.data(), buf.size());
s.append(reinterpret_cast<char*>(buf.data()), n);
s.append((char*)buf.data(), n);
} catch (EndOfFile&) {
break;
}
@ -126,10 +126,10 @@ size_t BufferedSource::read(unsigned char* data, size_t len) {
bool BufferedSource::hasData() { return bufPosOut < bufPosIn; }
size_t FdSource::readUnbuffered(unsigned char* data, size_t len) {
ssize_t n = 0;
ssize_t n;
do {
checkInterrupt();
n = ::read(fd, reinterpret_cast<char*>(data), len);
n = ::read(fd, (char*)data, len);
} while (n == -1 && errno == EINTR);
if (n == -1) {
_good = false;
@ -149,7 +149,7 @@ size_t StringSource::read(unsigned char* data, size_t len) {
if (pos == s.size()) {
throw EndOfFile("end of string reached");
}
size_t n = s.copy(reinterpret_cast<char*>(data), len, pos);
size_t n = s.copy((char*)data, len, pos);
pos += n;
return n;
}
@ -179,7 +179,7 @@ std::unique_ptr<Source> sinkToSource(const std::function<void(Sink&)>& fun,
coro = coro_t::pull_type([&](coro_t::push_type& yield) {
LambdaSink sink([&](const unsigned char* data, size_t len) {
if (len != 0u) {
yield(std::string(reinterpret_cast<const char*>(data), len));
yield(std::string((const char*)data, len));
}
});
fun(sink);
@ -200,7 +200,7 @@ std::unique_ptr<Source> sinkToSource(const std::function<void(Sink&)>& fun,
}
auto n = std::min(cur.size() - pos, len);
memcpy(data, reinterpret_cast<unsigned char*>(cur.data()) + pos, n);
memcpy(data, (unsigned char*)cur.data() + pos, n);
pos += n;
return n;
@ -225,7 +225,7 @@ void writeString(const unsigned char* buf, size_t len, Sink& sink) {
}
Sink& operator<<(Sink& sink, const std::string& s) {
writeString(reinterpret_cast<const unsigned char*>(s.data()), s.size(), sink);
writeString((const unsigned char*)s.data(), s.size(), sink);
return sink;
}
@ -276,7 +276,7 @@ std::string readString(Source& source, size_t max) {
throw SerialisationError("string is too long");
}
std::string res(len, 0);
source(reinterpret_cast<unsigned char*>(res.data()), len);
source((unsigned char*)res.data(), len);
readPadding(len, source);
return res;
}
@ -305,7 +305,7 @@ void StringSink::operator()(const unsigned char* data, size_t len) {
warnLargeDump();
warned = true;
}
s->append(reinterpret_cast<const char*>(data), len);
s->append((const char*)data, len);
}
} // namespace nix

View file

@ -207,7 +207,7 @@ bool isDirOrInDir(const Path& path, const Path& dir) {
}
struct stat lstat(const Path& path) {
struct stat st {};
struct stat st;
if (lstat(path.c_str(), &st) != 0) {
throw SysError(format("getting status of '%1%'") % path);
}
@ -215,8 +215,8 @@ struct stat lstat(const Path& path) {
}
bool pathExists(const Path& path) {
int res = 0;
struct stat st {};
int res;
struct stat st;
res = lstat(path.c_str(), &st);
if (res == 0) {
return true;
@ -254,7 +254,7 @@ DirEntries readDirectory(DIR* dir, const Path& path) {
DirEntries entries;
entries.reserve(64);
struct dirent* dirent = nullptr;
struct dirent* dirent;
while (errno = 0, dirent = readdir(dir)) { /* sic */
checkInterrupt();
std::string name = dirent->d_name;
@ -300,7 +300,7 @@ unsigned char getFileType(const Path& path) {
}
std::string readFile(int fd) {
struct stat st {};
struct stat st;
if (fstat(fd, &st) == -1) {
throw SysError("statting file");
}
@ -308,7 +308,7 @@ std::string readFile(int fd) {
std::vector<unsigned char> buf(st.st_size);
readFull(fd, buf.data(), st.st_size);
return std::string(reinterpret_cast<char*>(buf.data()), st.st_size);
return std::string((char*)buf.data(), st.st_size);
}
std::string readFile(absl::string_view path, bool drain) {
@ -349,7 +349,7 @@ void writeFile(const Path& path, Source& source, mode_t mode) {
while (true) {
try {
auto n = source.read(buf.data(), buf.size());
writeFull(fd.get(), static_cast<unsigned char*>(buf.data()), n);
writeFull(fd.get(), (unsigned char*)buf.data(), n);
} catch (EndOfFile&) {
break;
}
@ -360,7 +360,7 @@ std::string readLine(int fd) {
std::string s;
while (true) {
checkInterrupt();
char ch = 0;
char ch;
// FIXME: inefficient
ssize_t rd = read(fd, &ch, 1);
if (rd == -1) {
@ -389,7 +389,7 @@ static void _deletePath(int parentfd, const Path& path,
std::string name(baseNameOf(path));
struct stat st {};
struct stat st;
if (fstatat(parentfd, name.c_str(), &st, AT_SYMLINK_NOFOLLOW) == -1) {
if (errno == ENOENT) {
return;
@ -449,7 +449,7 @@ static void _deletePath(const Path& path, unsigned long long& bytesFreed) {
}
void deletePath(const Path& path) {
unsigned long long dummy = 0;
unsigned long long dummy;
deletePath(path, dummy);
}
@ -514,8 +514,8 @@ static Lazy<Path> getHome2([]() {
Path homeDir = getEnv("HOME");
if (homeDir.empty()) {
std::vector<char> buf(16384);
struct passwd pwbuf {};
struct passwd* pw = nullptr;
struct passwd pwbuf;
struct passwd* pw;
if (getpwuid_r(geteuid(), &pwbuf, buf.data(), buf.size(), &pw) != 0 ||
(pw == nullptr) || (pw->pw_dir == nullptr) || (pw->pw_dir[0] == 0)) {
throw Error("cannot determine user's home directory");
@ -567,7 +567,7 @@ Paths createDirs(const Path& path) {
return created;
}
struct stat st {};
struct stat st;
if (lstat(path.c_str(), &st) == -1) {
created = createDirs(dirOf(path));
if (mkdir(path.c_str(), 0777) == -1 && errno != EEXIST) {
@ -619,7 +619,7 @@ void replaceSymlink(const Path& target, const Path& link) {
void readFull(int fd, unsigned char* buf, size_t count) {
while (count != 0u) {
checkInterrupt();
ssize_t res = read(fd, reinterpret_cast<char*>(buf), count);
ssize_t res = read(fd, (char*)buf, count);
if (res == -1) {
if (errno == EINTR) {
continue;
@ -652,8 +652,7 @@ void writeFull(int fd, const unsigned char* buf, size_t count,
}
void writeFull(int fd, const std::string& s, bool allowInterrupts) {
writeFull(fd, reinterpret_cast<const unsigned char*>(s.data()), s.size(),
allowInterrupts);
writeFull(fd, (const unsigned char*)s.data(), s.size(), allowInterrupts);
}
std::string drainFD(int fd, bool block) {
@ -663,7 +662,7 @@ std::string drainFD(int fd, bool block) {
}
void drainFD(int fd, Sink& sink, bool block) {
int saved = 0;
int saved;
Finally finally([&]() {
if (!block) {
@ -830,7 +829,7 @@ int Pid::kill() {
int Pid::wait() {
assert(pid != -1);
while (true) {
int status = 0;
int status;
int res = waitpid(pid, &status, 0);
if (res == pid) {
pid = -1;
@ -955,7 +954,7 @@ pid_t startProcess(std::function<void()> fun, const ProcessOptions& options) {
std::vector<char*> stringsToCharPtrs(const Strings& ss) {
std::vector<char*> res;
for (auto& s : ss) {
res.push_back(const_cast<char*>(s.c_str()));
res.push_back((char*)s.c_str());
}
res.push_back(nullptr);
return res;
@ -1086,7 +1085,7 @@ void runProgram2(const RunOptions& options) {
try {
std::vector<unsigned char> buf(8 * 1024);
while (true) {
size_t n = 0;
size_t n;
try {
n = source->read(buf.data(), buf.size());
} catch (EndOfFile&) {
@ -1145,7 +1144,7 @@ void closeMostFDs(const std::set<int>& exceptions) {
}
void closeOnExec(int fd) {
int prev = 0;
int prev;
if ((prev = fcntl(fd, F_GETFD, 0)) == -1 ||
fcntl(fd, F_SETFD, prev | FD_CLOEXEC) == -1) {
throw SysError("setting close-on-exec flag");
@ -1271,7 +1270,7 @@ std::string filterANSIEscapes(const std::string& s, bool filterAll,
size_t w = 0;
auto i = s.begin();
while (w < static_cast<size_t>(width) && i != s.end()) {
while (w < (size_t)width && i != s.end()) {
if (*i == '\e') {
std::string e;
e += *i++;
@ -1306,7 +1305,7 @@ std::string filterANSIEscapes(const std::string& s, bool filterAll,
i++;
t += ' ';
w++;
while (w < static_cast<size_t>(width) && ((w % 8) != 0u)) {
while (w < (size_t)width && ((w % 8) != 0u)) {
t += ' ';
w++;
}
@ -1338,7 +1337,7 @@ void callFailure(const std::function<void(std::exception_ptr exc)>& failure,
static Sync<std::pair<unsigned short, unsigned short>> windowSize{{0, 0}};
static void updateWindowSize() {
struct winsize ws {};
struct winsize ws;
if (ioctl(2, TIOCGWINSZ, &ws) == 0) {
auto windowSize_(windowSize.lock());
windowSize_->first = ws.ws_row;

View file

@ -163,7 +163,7 @@ void drainFD(int fd, Sink& sink, bool block = true);
class AutoDelete {
Path path;
bool del;
bool recursive{};
bool recursive;
public:
AutoDelete();