about summary refs log tree commit diff
path: root/third_party/nix/src/libutil/hash.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-20T21·27+0100
committerVincent Ambo <tazjin@google.com>2020-05-20T21·27+0100
commit689ef502f5b0655c9923ed77da2ae3504630f473 (patch)
tree3e331c153646f136875f047cc3b9f0aad8c86341 /third_party/nix/src/libutil/hash.cc
parentd331d3a0b5c497a46e2636f308234be66566c04c (diff)
refactor(3p/nix): Apply clang-tidy's readability-* fixes r/788
This applies the readability fixes listed here:

https://clang.llvm.org/extra/clang-tidy/checks/list.html
Diffstat (limited to 'third_party/nix/src/libutil/hash.cc')
-rw-r--r--third_party/nix/src/libutil/hash.cc10
1 files changed, 6 insertions, 4 deletions
diff --git a/third_party/nix/src/libutil/hash.cc b/third_party/nix/src/libutil/hash.cc
index e33c76cc9093..81d8628e972b 100644
--- a/third_party/nix/src/libutil/hash.cc
+++ b/third_party/nix/src/libutil/hash.cc
@@ -193,7 +193,7 @@ Hash::Hash(const std::string& s, HashType type) : type(type) {
       if (i < hashSize - 1) {
         hash[i + 1] |= digit >> (8 - j);
       } else {
-        if (digit >> (8 - j)) {
+        if ((digit >> (8 - j)) != 0) {
           throw BadHash("invalid base-32 hash '%s'", s);
         }
       }
@@ -280,7 +280,7 @@ Hash hashFile(HashType ht, const Path& path) {
 
   std::vector<unsigned char> buf(8192);
   ssize_t n;
-  while ((n = read(fd.get(), buf.data(), buf.size()))) {
+  while ((n = read(fd.get(), buf.data(), buf.size())) != 0) {
     checkInterrupt();
     if (n == -1) {
       throw SysError(format("reading file '%1%'") % path);
@@ -341,7 +341,8 @@ Hash compressHash(const Hash& hash, unsigned int newSize) {
 HashType parseHashType(const string& s) {
   if (s == "md5") {
     return htMD5;
-  } else if (s == "sha1") {
+  }
+  if (s == "sha1") {
     return htSHA1;
   } else if (s == "sha256") {
     return htSHA256;
@@ -355,7 +356,8 @@ HashType parseHashType(const string& s) {
 string printHashType(HashType ht) {
   if (ht == htMD5) {
     return "md5";
-  } else if (ht == htSHA1) {
+  }
+  if (ht == htSHA1) {
     return "sha1";
   } else if (ht == htSHA256) {
     return "sha256";