From 3db533c637cf644725e279f878d6ee5bf50adc26 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sat, 6 Dec 2025 18:09:53 +0100 Subject: [PATCH] clang-tidy: enable bugprone-implicit-widening-of-multiplication-result Change-Id: I7c7bae6c27aa59da23097ec89305cfc60ec9e8e3 --- .clang-tidy | 2 -- lix/libexpr/eval.cc | 4 ++-- lix/libmain/stack.cc | 2 +- lix/libstore/derivations.cc | 2 +- lix/libstore/filetransfer.cc | 2 +- lix/libstore/profiles.cc | 2 +- lix/libstore/s3-binary-cache-store.cc | 11 +++++++---- lix/libutil/async-io.hh | 4 ++-- lix/libutil/compression.cc | 4 ++-- lix/libutil/file-descriptor.cc | 2 +- lix/libutil/file-system.cc | 6 +++--- lix/libutil/hash.cc | 5 ++--- lix/libutil/io-buffer.hh | 2 +- lix/libutil/logging-rpc.cc | 4 ++-- lix/libutil/processes.cc | 2 +- lix/libutil/serialise.hh | 4 ++-- lix/nix/diff-closures.cc | 2 +- lix/nix/main.cc | 2 +- tests/unit/libstore/filetransfer.cc | 2 +- 19 files changed, 32 insertions(+), 32 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index d6ab4412f..665f88a1f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -8,8 +8,6 @@ Checks: - -bugprone-narrowing-conversions # kind of nonsense - -bugprone-easily-swappable-parameters - # too many warnings for now - - -bugprone-implicit-widening-of-multiplication-result # Lix's exception handling is Questionable - -bugprone-empty-catch # many warnings diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index aff596108..3e6c003ed 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -210,9 +210,9 @@ void initLibExpr() (resident) memory to be allocated. This might be a problem on systems that don't overcommit. */ if (!getEnv("GC_INITIAL_HEAP_SIZE")) { - int64_t size = 32 * 1024 * 1024; + int64_t size = 32l * 1024 * 1024; #if HAVE_SYSCONF && defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES) - int64_t maxSize = 384 * 1024 * 1024; + int64_t maxSize = 384l * 1024 * 1024; int64_t pageSize = sysconf(_SC_PAGESIZE); int64_t pages = sysconf(_SC_PHYS_PAGES); if (pageSize != -1) { diff --git a/lix/libmain/stack.cc b/lix/libmain/stack.cc index e777764a6..e692d0a69 100644 --- a/lix/libmain/stack.cc +++ b/lix/libmain/stack.cc @@ -48,7 +48,7 @@ void detectStackOverflow() requires an alternative stack, otherwise the signal cannot be delivered when we're out of stack space. */ stack_t stack; - stack.ss_size = 4096 * 4 + MINSIGSTKSZ; + stack.ss_size = 4096ul * 4 + MINSIGSTKSZ; static auto stackBuf = std::make_unique>(stack.ss_size); stack.ss_sp = stackBuf->data(); if (!stack.ss_sp) throw Error("cannot allocate alternative stack"); diff --git a/lix/libstore/derivations.cc b/lix/libstore/derivations.cc index 22f524fb0..11d2dd1f4 100644 --- a/lix/libstore/derivations.cc +++ b/lix/libstore/derivations.cc @@ -352,7 +352,7 @@ Derivation parseDerivation( */ static void printString(std::string & res, std::string_view s) { - boost::container::small_vector buffer; + boost::container::small_vector buffer; buffer.reserve(s.size() * 2 + 2); char * buf = buffer.data(); char * p = buf; diff --git a/lix/libstore/filetransfer.cc b/lix/libstore/filetransfer.cc index 3a1374b29..8dc5275d2 100644 --- a/lix/libstore/filetransfer.cc +++ b/lix/libstore/filetransfer.cc @@ -333,7 +333,7 @@ struct TransferItem // when the buffer is full (as determined by a historical magic value) we // pause the transfer and wait for the receiver to unpause it when ready. - if (successfulStatuses.count(getHTTPStatus()) && state->data.size() > 1024 * 1024) { + if (successfulStatuses.count(getHTTPStatus()) && state->data.size() > 1024ul * 1024) { return CURL_WRITEFUNC_PAUSE; } diff --git a/lix/libstore/profiles.cc b/lix/libstore/profiles.cc index 296040c05..e79aef301 100644 --- a/lix/libstore/profiles.cc +++ b/lix/libstore/profiles.cc @@ -253,7 +253,7 @@ time_t parseOlderThanTimeSpec(std::string_view timeSpec) time_t curTime = time(0); auto strDays = timeSpec.substr(0, timeSpec.size() - 1); - auto days = string2Int(strDays); + auto days = string2Int(strDays); if (!days || *days < 1) throw UsageError("invalid number of days specifier '%1%'", timeSpec); diff --git a/lix/libstore/s3-binary-cache-store.cc b/lix/libstore/s3-binary-cache-store.cc index 24fbcd9fa..721257992 100644 --- a/lix/libstore/s3-binary-cache-store.cc +++ b/lix/libstore/s3-binary-cache-store.cc @@ -195,8 +195,8 @@ ref S3Helper::makeConfig( if (!endpoint.empty()) { res->endpointOverride = endpoint; } - res->requestTimeoutMs = 600 * 1000; - res->connectTimeoutMs = 5 * 1000; + res->requestTimeoutMs = 600l * 1000; + res->connectTimeoutMs = 5l * 1000; res->retryStrategy = std::make_shared(); res->caFile = settings.caFile; // Use the system proxy env-vars in curl for s3, which is off by default for some reason @@ -312,8 +312,11 @@ struct S3BinaryCacheStoreConfig final : BinaryCacheStoreConfig "Whether to use multi-part uploads."}; const Setting bufferSize{ - this, 5 * 1024 * 1024, "buffer-size", - "Size (in bytes) of each part in multi-part uploads."}; + this, + 5ul * 1024 * 1024, + "buffer-size", + "Size (in bytes) of each part in multi-part uploads." + }; const std::string name() override { return "S3 Binary Cache Store"; } diff --git a/lix/libutil/async-io.hh b/lix/libutil/async-io.hh index 7210a1ec4..064231e9c 100644 --- a/lix/libutil/async-io.hh +++ b/lix/libutil/async-io.hh @@ -121,7 +121,7 @@ public: { } - AsyncBufferedInputStream(AsyncInputStream & inner, size_t bufSize = 32 * 1024) + AsyncBufferedInputStream(AsyncInputStream & inner, size_t bufSize = 32ul * 1024) : AsyncBufferedInputStream(inner, make_ref(bufSize)) { } @@ -173,7 +173,7 @@ public: { } - AsyncBufferedOutputStream(AsyncOutputStream & inner, size_t bufSize = 32 * 1024) + AsyncBufferedOutputStream(AsyncOutputStream & inner, size_t bufSize = 32ul * 1024) : AsyncBufferedOutputStream(inner, make_ref(bufSize)) { } diff --git a/lix/libutil/compression.cc b/lix/libutil/compression.cc index 483c6d5b1..0e99b62c7 100644 --- a/lix/libutil/compression.cc +++ b/lix/libutil/compression.cc @@ -38,7 +38,7 @@ static const int COMPRESSION_LEVEL_DEFAULT = -1; // Don't feed brotli too much at once. struct ChunkedCompressionSink : CompressionSink { - uint8_t outbuf[32 * 1024]; + uint8_t outbuf[32ul * 1024]; void writeUnbuffered(std::string_view data) override { @@ -167,7 +167,7 @@ struct NoneSink : CompressionSink struct BrotliDecompressionSource : Source { - static constexpr size_t BUF_SIZE = 32 * 1024; + static constexpr size_t BUF_SIZE = 32ul * 1024; std::unique_ptr buf; size_t avail_in = 0; const uint8_t * next_in; diff --git a/lix/libutil/file-descriptor.cc b/lix/libutil/file-descriptor.cc index 9287a8d0b..33f261aa3 100644 --- a/lix/libutil/file-descriptor.cc +++ b/lix/libutil/file-descriptor.cc @@ -133,7 +133,7 @@ Generator drainFDSource(int fd, bool block) } }); - std::array buf; + std::array buf; while (1) { checkInterrupt(); ssize_t rd = read(fd, buf.data(), buf.size()); diff --git a/lix/libutil/file-system.cc b/lix/libutil/file-system.cc index 0d054e6cf..1beccf7ee 100644 --- a/lix/libutil/file-system.cc +++ b/lix/libutil/file-system.cc @@ -443,7 +443,7 @@ void writeFile(const Path & path, Source & source, mode_t mode) { AutoCloseFD fd = openForWrite(path, mode); - std::vector buf(64 * 1024); + std::vector buf(64ul * 1024); try { while (true) { @@ -463,7 +463,7 @@ void writeFileExcl(const Path & path, Source & source, mode_t mode) { AutoCloseFD fd = openForWriteExcl(path, mode); - std::vector buf(64 * 1024); + std::vector buf(64ul * 1024); try { while (true) { @@ -483,7 +483,7 @@ kj::Promise> writeFile(const Path & path, AsyncInputStream & source try { AutoCloseFD fd = openForWrite(path, mode); - std::vector buf(64 * 1024); + std::vector buf(64ul * 1024); try { while (true) { diff --git a/lix/libutil/hash.cc b/lix/libutil/hash.cc index f4b1f70be..ea792c932 100644 --- a/lix/libutil/hash.cc +++ b/lix/libutil/hash.cc @@ -191,9 +191,8 @@ Hash::Hash(std::string_view rest, HashType type, bool isSRI) }; for (unsigned int i = 0; i < hashSize; i++) { - hash[i] = - parseHexDigit(rest[i * 2]) << 4 - | parseHexDigit(rest[i * 2 + 1]); + const size_t j = i << 1; + hash[i] = parseHexDigit(rest[j]) << 4 | parseHexDigit(rest[j + 1]); } } diff --git a/lix/libutil/io-buffer.hh b/lix/libutil/io-buffer.hh index 0c4414658..af41ccf39 100644 --- a/lix/libutil/io-buffer.hh +++ b/lix/libutil/io-buffer.hh @@ -19,7 +19,7 @@ class IoBuffer std::unique_ptr buffer; public: - explicit IoBuffer(size_t bufSize = 32 * 1024) : bufSize(bufSize) {} + explicit IoBuffer(size_t bufSize = 32ul * 1024) : bufSize(bufSize) {} size_t size() const { diff --git a/lix/libutil/logging-rpc.cc b/lix/libutil/logging-rpc.cc index 46a9e4c10..73ef578d0 100644 --- a/lix/libutil/logging-rpc.cc +++ b/lix/libutil/logging-rpc.cc @@ -107,8 +107,8 @@ struct RpcLogger : Logger } buffer->sizeEstimate += sizeof(e) + extraSize; buffer->items.emplace_back(std::move(e)); - return buffer->sizeEstimate >= 1024 * 1024 ? BufferState::NeedsFlush - : BufferState::HasSpace; + return buffer->sizeEstimate >= static_cast(1024 * 1024) ? BufferState::NeedsFlush + : BufferState::HasSpace; } BufferState log(Verbosity lvl, std::string_view s) override diff --git a/lix/libutil/processes.cc b/lix/libutil/processes.cc index 0eea7c3c5..34de355de 100644 --- a/lix/libutil/processes.cc +++ b/lix/libutil/processes.cc @@ -214,7 +214,7 @@ Pid startProcess(std::function fun, const ProcessOptions & options) // Not supported, since then we don't know when to free the stack. assert(!(options.cloneFlags & CLONE_VM)); - size_t stackSize = 1 * 1024 * 1024; + size_t stackSize = 1ul * 1024 * 1024; auto stack = static_cast(mmap(0, stackSize, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0)); if (stack == MAP_FAILED) throw SysError("allocating stack"); diff --git a/lix/libutil/serialise.hh b/lix/libutil/serialise.hh index bffedc3f6..dc7edc7b8 100644 --- a/lix/libutil/serialise.hh +++ b/lix/libutil/serialise.hh @@ -53,7 +53,7 @@ struct BufferedSink : virtual Sink { ref buffer; - BufferedSink(size_t bufSize = 32 * 1024) : buffer(make_ref(bufSize)) {} + BufferedSink(size_t bufSize = 32ul * 1024) : buffer(make_ref(bufSize)) {} explicit BufferedSink(ref buffer) : buffer(std::move(buffer)) {} void operator () (std::string_view data) override; @@ -105,7 +105,7 @@ struct BufferedSource : Source { ref buffer; - BufferedSource(size_t bufSize = 32 * 1024) : buffer(make_ref(bufSize)) {} + BufferedSource(size_t bufSize = 32ul * 1024) : buffer(make_ref(bufSize)) {} explicit BufferedSource(ref buffer) : buffer(std::move(buffer)) {} size_t read(char * data, size_t len) override; diff --git a/lix/nix/diff-closures.cc b/lix/nix/diff-closures.cc index 288724287..77837e4d4 100644 --- a/lix/nix/diff-closures.cc +++ b/lix/nix/diff-closures.cc @@ -152,7 +152,7 @@ void renderDiffInfo( const std::string_view indent) { for (auto & [name, item] : diff) { - auto showDelta = std::abs(item.sizeDelta) >= 8 * 1024; + auto showDelta = std::abs(item.sizeDelta) >= 8l * 1024; std::vector line; if (!item.removedVersions.empty() || !item.addedVersions.empty()) diff --git a/lix/nix/main.cc b/lix/nix/main.cc index ad84d041f..d0178473b 100644 --- a/lix/nix/main.cc +++ b/lix/nix/main.cc @@ -659,7 +659,7 @@ int main(int argc, char * * argv) // Increase the default stack size for the evaluator and for // libstdc++'s std::regex. - nix::setStackSize(64 * 1024 * 1024); + nix::setStackSize(64ul * 1024 * 1024); return nix::handleExceptions(argv[0], [&]() { nix::AsyncIoRoot aio; diff --git a/tests/unit/libstore/filetransfer.cc b/tests/unit/libstore/filetransfer.cc index 92f47a1f1..cceb59a86 100644 --- a/tests/unit/libstore/filetransfer.cc +++ b/tests/unit/libstore/filetransfer.cc @@ -256,7 +256,7 @@ TEST(FileTransfer, NOT_ON_DARWIN(defersFailures)) // initial wait for header data will also wait for the the response to // complete (the source is only woken when curl returns data, and curl // might only do so once its internal buffer has already been filled.) - return std::string(1024 * 1024, ' '); + return std::string(static_cast(1024 * 1024), ' '); }); AsyncIoRoot aio; auto ft = makeFileTransfer(0);