diff options
Diffstat (limited to 'third_party/nix/src/libutil')
-rw-r--r-- | third_party/nix/src/libutil/archive.cc | 6 | ||||
-rw-r--r-- | third_party/nix/src/libutil/args.cc | 4 | ||||
-rw-r--r-- | third_party/nix/src/libutil/compression.cc | 8 | ||||
-rw-r--r-- | third_party/nix/src/libutil/hash.cc | 7 | ||||
-rw-r--r-- | third_party/nix/src/libutil/json.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/libutil/serialise.cc | 16 | ||||
-rw-r--r-- | third_party/nix/src/libutil/util.cc | 15 |
7 files changed, 30 insertions, 28 deletions
diff --git a/third_party/nix/src/libutil/archive.cc b/third_party/nix/src/libutil/archive.cc index 40898093212a..4489b7d2a8c5 100644 --- a/third_party/nix/src/libutil/archive.cc +++ b/third_party/nix/src/libutil/archive.cc @@ -80,7 +80,7 @@ static void dump(const Path& path, Sink& sink, PathFilter& filter) { sink << "executable" << ""; } - dumpContents(path, (size_t)st.st_size, sink); + dumpContents(path, static_cast<size_t>(st.st_size), sink); } else if (S_ISDIR(st.st_mode)) { @@ -170,7 +170,7 @@ static void parseContents(ParseSink& sink, Source& source, const Path& path) { while (left != 0u) { checkInterrupt(); auto n = buf.size(); - if ((unsigned long long)n > left) { + if (static_cast<unsigned long long>(n) > left) { n = left; } source(buf.data(), n); @@ -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((char)0) != std::string::npos) { + name.find(static_cast<char>(0)) != std::string::npos) { throw Error(format("NAR contains invalid file name '%1%'") % name); } if (name <= prevName) { diff --git a/third_party/nix/src/libutil/args.cc b/third_party/nix/src/libutil/args.cc index c56383ef88cc..2be8a1b0ce2a 100644 --- a/third_party/nix/src/libutil/args.cc +++ b/third_party/nix/src/libutil/args.cc @@ -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; diff --git a/third_party/nix/src/libutil/compression.cc b/third_party/nix/src/libutil/compression.cc index 779d326eb204..d0895ca5fda4 100644 --- a/third_party/nix/src/libutil/compression.cc +++ b/third_party/nix/src/libutil/compression.cc @@ -99,7 +99,7 @@ struct BzipDecompressionSink : ChunkedCompressionSink { throw CompressionError("unable to initialise bzip2 decoder"); } - strm.next_out = (char*)outbuf; + strm.next_out = reinterpret_cast<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 = (char*)outbuf; + strm.next_out = reinterpret_cast<char*>(outbuf); strm.avail_out = sizeof(outbuf); } } @@ -287,7 +287,7 @@ struct BzipCompressionSink : ChunkedCompressionSink { throw CompressionError("unable to initialise bzip2 encoder"); } - strm.next_out = (char*)outbuf; + strm.next_out = reinterpret_cast<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 = (char*)outbuf; + strm.next_out = reinterpret_cast<char*>(outbuf); strm.avail_out = sizeof(outbuf); } } diff --git a/third_party/nix/src/libutil/hash.cc b/third_party/nix/src/libutil/hash.cc index f7ee44728f60..426096e73af8 100644 --- a/third_party/nix/src/libutil/hash.cc +++ b/third_party/nix/src/libutil/hash.cc @@ -166,7 +166,7 @@ static std::string printHash32(const Hash& hash) { std::string s; s.reserve(len); - for (int n = (int)len - 1; n >= 0; n--) { + for (int n = static_cast<int>(len) - 1; n >= 0; n--) { unsigned int b = n * 5; unsigned int i = b / 8; unsigned int j = b % 8; @@ -199,7 +199,8 @@ std::string Hash::to_string(Base base, bool includeType) const { case Base64: case SRI: std::string b64; - absl::Base64Escape(std::string((const char*)hash, hashSize), &b64); + absl::Base64Escape( + std::string(reinterpret_cast<const char*>(hash), hashSize), &b64); s += b64; break; } @@ -366,7 +367,7 @@ Hash hashString(HashType ht, const std::string& s) { hash::Ctx ctx{}; Hash hash(ht); start(ht, ctx); - update(ht, ctx, (const unsigned char*)s.data(), s.length()); + update(ht, ctx, reinterpret_cast<const unsigned char*>(s.data()), s.length()); finish(ht, ctx, hash.hash); return hash; } diff --git a/third_party/nix/src/libutil/json.cc b/third_party/nix/src/libutil/json.cc index da636e7be9c3..59ff74f5796f 100644 --- a/third_party/nix/src/libutil/json.cc +++ b/third_party/nix/src/libutil/json.cc @@ -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 - << (uint16_t)*i << std::dec; + << static_cast<uint16_t>(*i) << std::dec; } else { str << *i; } diff --git a/third_party/nix/src/libutil/serialise.cc b/third_party/nix/src/libutil/serialise.cc index d02a0205af0d..288255089bb6 100644 --- a/third_party/nix/src/libutil/serialise.cc +++ b/third_party/nix/src/libutil/serialise.cc @@ -96,7 +96,7 @@ std::string Source::drain() { size_t n; try { n = read(buf.data(), buf.size()); - s.append((char*)buf.data(), n); + s.append(reinterpret_cast<char*>(buf.data()), n); } catch (EndOfFile&) { break; } @@ -129,7 +129,7 @@ size_t FdSource::readUnbuffered(unsigned char* data, size_t len) { ssize_t n; do { checkInterrupt(); - n = ::read(fd, (char*)data, len); + n = ::read(fd, reinterpret_cast<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((char*)data, len, pos); + size_t n = s.copy(reinterpret_cast<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((const char*)data, len)); + yield(std::string(reinterpret_cast<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, (unsigned char*)cur.data() + pos, n); + memcpy(data, reinterpret_cast<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((const unsigned char*)s.data(), s.size(), sink); + writeString(reinterpret_cast<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((unsigned char*)res.data(), len); + source(reinterpret_cast<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((const char*)data, len); + s->append(reinterpret_cast<const char*>(data), len); } } // namespace nix diff --git a/third_party/nix/src/libutil/util.cc b/third_party/nix/src/libutil/util.cc index 3e88fd29b9f0..c93570d7b0a4 100644 --- a/third_party/nix/src/libutil/util.cc +++ b/third_party/nix/src/libutil/util.cc @@ -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((char*)buf.data(), st.st_size); + return std::string(reinterpret_cast<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(), (unsigned char*)buf.data(), n); + writeFull(fd.get(), static_cast<unsigned char*>(buf.data()), n); } catch (EndOfFile&) { break; } @@ -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, (char*)buf, count); + ssize_t res = read(fd, reinterpret_cast<char*>(buf), count); if (res == -1) { if (errno == EINTR) { continue; @@ -652,7 +652,8 @@ void writeFull(int fd, const unsigned char* buf, size_t count, } void writeFull(int fd, const std::string& s, bool allowInterrupts) { - writeFull(fd, (const unsigned char*)s.data(), s.size(), allowInterrupts); + writeFull(fd, reinterpret_cast<const unsigned char*>(s.data()), s.size(), + allowInterrupts); } std::string drainFD(int fd, bool block) { @@ -954,7 +955,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((char*)s.c_str()); + res.push_back(const_cast<char*>(s.c_str())); } res.push_back(nullptr); return res; @@ -1270,7 +1271,7 @@ std::string filterANSIEscapes(const std::string& s, bool filterAll, size_t w = 0; auto i = s.begin(); - while (w < (size_t)width && i != s.end()) { + while (w < static_cast<size_t>(width) && i != s.end()) { if (*i == '\e') { std::string e; e += *i++; @@ -1305,7 +1306,7 @@ std::string filterANSIEscapes(const std::string& s, bool filterAll, i++; t += ' '; w++; - while (w < (size_t)width && ((w % 8) != 0u)) { + while (w < static_cast<size_t>(width) && ((w % 8) != 0u)) { t += ' '; w++; } |