about summary refs log tree commit diff
path: root/third_party/nix/src/libutil/util.cc
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-08-02T00·17-0700
committerkanepyork <rikingcoding@gmail.com>2020-08-08T22·16+0000
commit1de00e6c42ee6beaaa490104888ef09be1d4a0d4 (patch)
treed98a37ae13525510e3b76feed56b3865360374d1 /third_party/nix/src/libutil/util.cc
parent053a1380023591e8eb3f514b4214226c95da207d (diff)
chore(3p/nix): apply google-readability-casting r/1619
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>
Diffstat (limited to 'third_party/nix/src/libutil/util.cc')
-rw-r--r--third_party/nix/src/libutil/util.cc15
1 files changed, 8 insertions, 7 deletions
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++;
       }