From 39087321811e81e26a1a47d6967df1088dcf0e95 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 19 May 2020 20:47:23 +0100 Subject: style(3p/nix): Final act in the brace-wrapping saga This last change set was generated by a full clang-tidy run (including compilation): clang-tidy -p ~/projects/nix-build/ \ -checks=-*,readability-braces-around-statements -fix src/*/*.cc Actually running clang-tidy requires some massaging to make it play nice with Nix + meson, I'll be adding a wrapper or something for that soon. --- third_party/nix/src/libutil/compression.cc | 49 ++++++++++++++++++------------ 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'third_party/nix/src/libutil/compression.cc') diff --git a/third_party/nix/src/libutil/compression.cc b/third_party/nix/src/libutil/compression.cc index 219d9046fa65..e13ffcec74d8 100644 --- a/third_party/nix/src/libutil/compression.cc +++ b/third_party/nix/src/libutil/compression.cc @@ -49,8 +49,9 @@ struct XzDecompressionSink : CompressionSink { XzDecompressionSink(Sink& nextSink) : nextSink(nextSink) { lzma_ret ret = lzma_stream_decoder(&strm, UINT64_MAX, LZMA_CONCATENATED); - if (ret != LZMA_OK) + if (ret != LZMA_OK) { throw CompressionError("unable to initialise lzma decoder"); + } strm.next_out = outbuf; strm.avail_out = sizeof(outbuf); @@ -71,8 +72,9 @@ struct XzDecompressionSink : CompressionSink { checkInterrupt(); lzma_ret ret = lzma_code(&strm, data ? LZMA_RUN : LZMA_FINISH); - if (ret != LZMA_OK && ret != LZMA_STREAM_END) + if (ret != LZMA_OK && ret != LZMA_STREAM_END) { throw CompressionError("error %d while decompressing xz file", ret); + } finished = ret == LZMA_STREAM_END; @@ -93,8 +95,9 @@ struct BzipDecompressionSink : ChunkedCompressionSink { BzipDecompressionSink(Sink& nextSink) : nextSink(nextSink) { memset(&strm, 0, sizeof(strm)); int ret = BZ2_bzDecompressInit(&strm, 0, 0); - if (ret != BZ_OK) + if (ret != BZ_OK) { throw CompressionError("unable to initialise bzip2 decoder"); + } strm.next_out = (char*)outbuf; strm.avail_out = sizeof(outbuf); @@ -117,8 +120,9 @@ struct BzipDecompressionSink : ChunkedCompressionSink { checkInterrupt(); int ret = BZ2_bzDecompress(&strm); - if (ret != BZ_OK && ret != BZ_STREAM_END) + if (ret != BZ_OK && ret != BZ_STREAM_END) { throw CompressionError("error while decompressing bzip2 file"); + } finished = ret == BZ_STREAM_END; @@ -160,8 +164,9 @@ struct BrotliDecompressionSink : ChunkedCompressionSink { checkInterrupt(); if (!BrotliDecoderDecompressStream(state, &avail_in, &next_in, &avail_out, - &next_out, nullptr)) + &next_out, nullptr)) { throw CompressionError("error while decompressing brotli file"); + } if (avail_out < sizeof(outbuf) || avail_in == 0) { nextSink(outbuf, sizeof(outbuf) - avail_out); @@ -184,16 +189,17 @@ ref decompress(const std::string& method, const std::string& in) { ref makeDecompressionSink(const std::string& method, Sink& nextSink) { - if (method == "none" || method == "") + if (method == "none" || method == "") { return make_ref(nextSink); - else if (method == "xz") + } else if (method == "xz") { return make_ref(nextSink); - else if (method == "bzip2") + } else if (method == "bzip2") { return make_ref(nextSink); - else if (method == "br") + } else if (method == "br") { return make_ref(nextSink); - else + } else { throw UnknownCompressionMethod("unknown compression method '%s'", method); + } } struct XzCompressionSink : CompressionSink { @@ -258,8 +264,9 @@ struct XzCompressionSink : CompressionSink { checkInterrupt(); lzma_ret ret = lzma_code(&strm, data ? LZMA_RUN : LZMA_FINISH); - if (ret != LZMA_OK && ret != LZMA_STREAM_END) + if (ret != LZMA_OK && ret != LZMA_STREAM_END) { throw CompressionError("error %d while compressing xz file", ret); + } finished = ret == LZMA_STREAM_END; @@ -280,8 +287,9 @@ struct BzipCompressionSink : ChunkedCompressionSink { BzipCompressionSink(Sink& nextSink) : nextSink(nextSink) { memset(&strm, 0, sizeof(strm)); int ret = BZ2_bzCompressInit(&strm, 9, 0, 30); - if (ret != BZ_OK) + if (ret != BZ_OK) { throw CompressionError("unable to initialise bzip2 encoder"); + } strm.next_out = (char*)outbuf; strm.avail_out = sizeof(outbuf); @@ -304,8 +312,9 @@ struct BzipCompressionSink : ChunkedCompressionSink { checkInterrupt(); int ret = BZ2_bzCompress(&strm, data ? BZ_RUN : BZ_FINISH); - if (ret != BZ_RUN_OK && ret != BZ_FINISH_OK && ret != BZ_STREAM_END) + if (ret != BZ_RUN_OK && ret != BZ_FINISH_OK && ret != BZ_STREAM_END) { throw CompressionError("error %d while compressing bzip2 file", ret); + } finished = ret == BZ_STREAM_END; @@ -349,8 +358,9 @@ struct BrotliCompressionSink : ChunkedCompressionSink { if (!BrotliEncoderCompressStream( state, data ? BROTLI_OPERATION_PROCESS : BROTLI_OPERATION_FINISH, - &avail_in, &next_in, &avail_out, &next_out, nullptr)) + &avail_in, &next_in, &avail_out, &next_out, nullptr)) { throw CompressionError("error while compressing brotli compression"); + } if (avail_out < sizeof(outbuf) || avail_in == 0) { nextSink(outbuf, sizeof(outbuf) - avail_out); @@ -365,17 +375,18 @@ struct BrotliCompressionSink : ChunkedCompressionSink { ref makeCompressionSink(const std::string& method, Sink& nextSink, const bool parallel) { - if (method == "none") + if (method == "none") { return make_ref(nextSink); - else if (method == "xz") + } else if (method == "xz") { return make_ref(nextSink, parallel); - else if (method == "bzip2") + } else if (method == "bzip2") { return make_ref(nextSink); - else if (method == "br") + } else if (method == "br") { return make_ref(nextSink); - else + } else { throw UnknownCompressionMethod(format("unknown compression method '%s'") % method); + } } ref compress(const std::string& method, const std::string& in, -- cgit 1.4.1