From 867055133d3f487e52dd44149f76347c2c28bf10 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 19 May 2020 18:55:58 +0100 Subject: style(3p/nix): Add braces around single-line conditionals 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 --- third_party/nix/src/libutil/serialise.cc | 44 ++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'third_party/nix/src/libutil/serialise.cc') diff --git a/third_party/nix/src/libutil/serialise.cc b/third_party/nix/src/libutil/serialise.cc index 079b88c1cfc4..760d19ed4cf3 100644 --- a/third_party/nix/src/libutil/serialise.cc +++ b/third_party/nix/src/libutil/serialise.cc @@ -11,7 +11,9 @@ namespace nix { void BufferedSink::operator()(const unsigned char* data, size_t len) { - if (!buffer) buffer = decltype(buffer)(new unsigned char[bufSize]); + if (!buffer) { + buffer = decltype(buffer)(new unsigned char[bufSize]); + } while (len) { /* Optimisation: bypass the buffer if the data exceeds the @@ -28,12 +30,16 @@ void BufferedSink::operator()(const unsigned char* data, size_t len) { data += n; bufPos += n; len -= n; - if (bufPos == bufSize) flush(); + if (bufPos == bufSize) { + flush(); + } } } void BufferedSink::flush() { - if (bufPos == 0) return; + if (bufPos == 0) { + return; + } size_t n = bufPos; bufPos = 0; // don't trigger the assert() in ~BufferedSink() write(buffer.get(), n); @@ -97,15 +103,21 @@ std::string Source::drain() { } size_t BufferedSource::read(unsigned char* data, size_t len) { - if (!buffer) buffer = decltype(buffer)(new unsigned char[bufSize]); + if (!buffer) { + buffer = decltype(buffer)(new unsigned char[bufSize]); + } - if (!bufPosIn) bufPosIn = readUnbuffered(buffer.get(), bufSize); + if (!bufPosIn) { + bufPosIn = readUnbuffered(buffer.get(), bufSize); + } /* Copy out the data in the buffer. */ size_t n = len > bufPosIn - bufPosOut ? bufPosIn - bufPosOut : len; memcpy(data, buffer.get() + bufPosOut, n); bufPosOut += n; - if (bufPosIn == bufPosOut) bufPosIn = bufPosOut = 0; + if (bufPosIn == bufPosOut) { + bufPosIn = bufPosOut = 0; + } return n; } @@ -132,7 +144,9 @@ size_t FdSource::readUnbuffered(unsigned char* data, size_t len) { bool FdSource::good() { return _good; } size_t StringSource::read(unsigned char* data, size_t len) { - if (pos == s.size()) throw EndOfFile("end of string reached"); + if (pos == s.size()) { + throw EndOfFile("end of string reached"); + } size_t n = s.copy((char*)data, len, pos); pos += n; return n; @@ -162,7 +176,9 @@ std::unique_ptr sinkToSource(std::function fun, if (!coro) coro = coro_t::pull_type([&](coro_t::push_type& yield) { LambdaSink sink([&](const unsigned char* data, size_t len) { - if (len) yield(std::string((const char*)data, len)); + if (len) { + yield(std::string((const char*)data, len)); + } }); fun(sink); }); @@ -232,13 +248,17 @@ void readPadding(size_t len, Source& source) { size_t n = 8 - (len % 8); source(zero, n); for (unsigned int i = 0; i < n; i++) - if (zero[i]) throw SerialisationError("non-zero padding"); + if (zero[i]) { + throw SerialisationError("non-zero padding"); + } } } size_t readString(unsigned char* buf, size_t max, Source& source) { auto len = readNum(source); - if (len > max) throw SerialisationError("string is too long"); + if (len > max) { + throw SerialisationError("string is too long"); + } source(buf, len); readPadding(len, source); return len; @@ -246,7 +266,9 @@ size_t readString(unsigned char* buf, size_t max, Source& source) { string readString(Source& source, size_t max) { auto len = readNum(source); - if (len > max) throw SerialisationError("string is too long"); + if (len > max) { + throw SerialisationError("string is too long"); + } std::string res(len, 0); source((unsigned char*)res.data(), len); readPadding(len, source); -- cgit 1.4.1