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-19T17·55+0100
committerVincent Ambo <tazjin@google.com>2020-05-19T17·55+0100
commit867055133d3f487e52dd44149f76347c2c28bf10 (patch)
treec367803ad94f024b0052727a2c7a037af169169a /third_party/nix/src/libutil/hash.cc
parentc6a31838cd7e88ebcb01422b329a499d04ab4b6b (diff)
style(3p/nix): Add braces around single-line conditionals r/771
These were not caught by the previous clang-tidy invocation, but were
instead sorted out using amber[0] as such:

    ambr --regex 'if (\(.+\))\s([a-z].*;)' 'if $1 { $2 }'

[0]: https://github.com/dalance/amber
Diffstat (limited to 'third_party/nix/src/libutil/hash.cc')
-rw-r--r--third_party/nix/src/libutil/hash.cc24
1 files changed, 18 insertions, 6 deletions
diff --git a/third_party/nix/src/libutil/hash.cc b/third_party/nix/src/libutil/hash.cc
index d303a4f5b9..0a0869dd4e 100644
--- a/third_party/nix/src/libutil/hash.cc
+++ b/third_party/nix/src/libutil/hash.cc
@@ -139,7 +139,9 @@ Hash::Hash(const std::string& s, HashType type) : type(type) {
   if (sep != string::npos) {
     string hts = string(s, 0, sep);
     this->type = parseHashType(hts);
-    if (this->type == htUnknown) throw BadHash("unknown hash type '%s'", hts);
+    if (this->type == htUnknown) {
+      throw BadHash("unknown hash type '%s'", hts);
+    }
     if (type != htUnknown && type != this->type)
       throw BadHash("hash '%s' should have type '%s'", s, printHashType(type));
     pos = sep + 1;
@@ -174,8 +176,12 @@ Hash::Hash(const std::string& s, HashType type) : type(type) {
       char c = s[pos + size - n - 1];
       unsigned char digit;
       for (digit = 0; digit < base32Chars.size(); ++digit) /* !!! slow */
-        if (base32Chars[digit] == c) break;
-      if (digit >= 32) throw BadHash("invalid base-32 hash '%s'", s);
+        if (base32Chars[digit] == c) {
+          break;
+        }
+      if (digit >= 32) {
+        throw BadHash("invalid base-32 hash '%s'", s);
+      }
       unsigned int b = n * 5;
       unsigned int i = b / 8;
       unsigned int j = b % 8;
@@ -184,7 +190,9 @@ 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)) throw BadHash("invalid base-32 hash '%s'", s);
+        if (digit >> (8 - j)) {
+          throw BadHash("invalid base-32 hash '%s'", s);
+        }
       }
     }
   }
@@ -258,13 +266,17 @@ Hash hashFile(HashType ht, const Path& path) {
   start(ht, ctx);
 
   AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
-  if (!fd) throw SysError(format("opening file '%1%'") % path);
+  if (!fd) {
+    throw SysError(format("opening file '%1%'") % path);
+  }
 
   std::vector<unsigned char> buf(8192);
   ssize_t n;
   while ((n = read(fd.get(), buf.data(), buf.size()))) {
     checkInterrupt();
-    if (n == -1) throw SysError(format("reading file '%1%'") % path);
+    if (n == -1) {
+      throw SysError(format("reading file '%1%'") % path);
+    }
     update(ht, ctx, buf.data(), n);
   }