From d6e1b11d3e91abc4194744310f36e37a57dd6e1d Mon Sep 17 00:00:00 2001 From: Lulu Date: Sun, 6 Oct 2024 20:47:32 +0200 Subject: [PATCH] Fix gcc warning -Wsign-compare Add the compile flag '-Wsign-compare' and adapt the code to fix all cases of this warning. Change-Id: I26b08fa5a03e4ac294daf697d32cf9140d84350d --- meson.build | 1 + src/libstore/build/worker.cc | 2 +- tests/unit/libutil/compression.cc | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index a8c6b9621..fca9f4ed3 100644 --- a/meson.build +++ b/meson.build @@ -485,6 +485,7 @@ add_project_arguments( # TODO(Qyriad): Yes this is how the autoconf+Make system did it. # It would be nice for our headers to be idempotent instead. '-include', 'config.h', + '-Wsign-compare', '-Wno-deprecated-declarations', '-Wimplicit-fallthrough', '-Werror=switch', diff --git a/src/libstore/build/worker.cc b/src/libstore/build/worker.cc index 7fc6198cf..d1c1abdf8 100644 --- a/src/libstore/build/worker.cc +++ b/src/libstore/build/worker.cc @@ -247,7 +247,7 @@ Worker::Results Worker::run(std::function req) .exclusiveJoin(std::move(onInterrupt.promise)); // TODO GC interface? - if (auto localStore = dynamic_cast(&store); localStore && settings.minFree != 0) { + if (auto localStore = dynamic_cast(&store); localStore && settings.minFree != 0u) { // Periodically wake up to see if we need to run the garbage collector. promise = promise.exclusiveJoin(boopGC(*localStore)); } diff --git a/tests/unit/libutil/compression.cc b/tests/unit/libutil/compression.cc index 8d181f53d..6dd8c96df 100644 --- a/tests/unit/libutil/compression.cc +++ b/tests/unit/libutil/compression.cc @@ -1,4 +1,5 @@ #include "compression.hh" +#include #include namespace nix { @@ -147,7 +148,7 @@ TEST_P(PerTypeNonNullCompressionTest, truncatedValidInput) /* n.b. This also tests zero-length input, which is also invalid. * As of the writing of this comment, it returns empty output, but is * allowed to throw a compression error instead. */ - for (int i = 0; i < compressed.length(); ++i) { + for (size_t i = 0u; i < compressed.length(); ++i) { auto newCompressed = compressed.substr(compressed.length() - i); try { decompress(method, newCompressed);