Compare commits

...

2 commits

Author SHA1 Message Date
Lulu 6756a067c2 Fix gcc warning -Wmissing-field-initializers
Add the compile flag '-Wmissing-field-initializers' and adapt the code
to fix this warning.

The approach that was taken here was to add default values to the type
definitions rather than specified them whenever they were missing.

Change-Id: Ic223a964d67ab429e8da804c0721ba5e25d53012
2024-10-06 22:10:40 +02:00
Lulu 1224476def 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
2024-10-06 20:47:32 +02:00
11 changed files with 20 additions and 18 deletions

View file

@ -485,6 +485,8 @@ add_project_arguments(
# TODO(Qyriad): Yes this is how the autoconf+Make system did it. # TODO(Qyriad): Yes this is how the autoconf+Make system did it.
# It would be nice for our headers to be idempotent instead. # It would be nice for our headers to be idempotent instead.
'-include', 'config.h', '-include', 'config.h',
'-Wsign-compare',
'-Wmissing-field-initializers',
'-Wno-deprecated-declarations', '-Wno-deprecated-declarations',
'-Wimplicit-fallthrough', '-Wimplicit-fallthrough',
'-Werror=switch', '-Werror=switch',

View file

@ -47,7 +47,7 @@ struct BuildResult
* @todo This should be an entire ErrorInfo object, not just a * @todo This should be an entire ErrorInfo object, not just a
* string, for richer information. * string, for richer information.
*/ */
std::string errorMsg; std::string errorMsg = {};
std::string toString() const { std::string toString() const {
auto strStatus = [&]() { auto strStatus = [&]() {
@ -90,7 +90,7 @@ struct BuildResult
* For derivations, a mapping from the names of the wanted outputs * For derivations, a mapping from the names of the wanted outputs
* to actual paths. * to actual paths.
*/ */
SingleDrvOutputs builtOutputs; SingleDrvOutputs builtOutputs = {};
/** /**
* The start/stop times of the build (or one of the rounds, if it * The start/stop times of the build (or one of the rounds, if it

View file

@ -63,7 +63,7 @@ struct InitialOutputStatus {
struct InitialOutput { struct InitialOutput {
bool wanted; bool wanted;
Hash outputHash; Hash outputHash;
std::optional<InitialOutputStatus> known; std::optional<InitialOutputStatus> known = {};
}; };
/** /**

View file

@ -88,8 +88,8 @@ protected:
public: public:
struct [[nodiscard]] WorkResult { struct [[nodiscard]] WorkResult {
ExitCode exitCode; ExitCode exitCode;
BuildResult result; BuildResult result = {};
std::shared_ptr<Error> ex; std::shared_ptr<Error> ex = {};
bool permanentFailure = false; bool permanentFailure = false;
bool timedOut = false; bool timedOut = false;
bool hashMismatch = false; bool hashMismatch = false;

View file

@ -247,7 +247,7 @@ Worker::Results Worker::run(std::function<Targets (GoalFactory &)> req)
.exclusiveJoin(std::move(onInterrupt.promise)); .exclusiveJoin(std::move(onInterrupt.promise));
// TODO GC interface? // TODO GC interface?
if (auto localStore = dynamic_cast<LocalStore *>(&store); localStore && settings.minFree != 0) { if (auto localStore = dynamic_cast<LocalStore *>(&store); localStore && settings.minFree != 0u) {
// Periodically wake up to see if we need to run the garbage collector. // Periodically wake up to see if we need to run the garbage collector.
promise = promise.exclusiveJoin(boopGC(*localStore)); promise = promise.exclusiveJoin(boopGC(*localStore));
} }

View file

@ -20,10 +20,10 @@ struct NarMember
file in the NAR. */ file in the NAR. */
uint64_t start = 0, size = 0; uint64_t start = 0, size = 0;
std::string target; std::string target = {};
/* If this is a directory, all the children of the directory. */ /* If this is a directory, all the children of the directory. */
std::map<std::string, NarMember> children; std::map<std::string, NarMember> children = {};
}; };
struct NarAccessor : public FSAccessor struct NarAccessor : public FSAccessor

View file

@ -17,7 +17,7 @@ namespace nix {
struct StorePathWithOutputs struct StorePathWithOutputs
{ {
StorePath path; StorePath path;
std::set<std::string> outputs; std::set<std::string> outputs = {};
std::string to_string(const Store & store) const; std::string to_string(const Store & store) const;

View file

@ -50,7 +50,7 @@ struct Realisation {
DrvOutput id; DrvOutput id;
StorePath outPath; StorePath outPath;
StringSet signatures; StringSet signatures = {};
/** /**
* The realisations that are required for the current one to be valid. * The realisations that are required for the current one to be valid.
@ -58,7 +58,7 @@ struct Realisation {
* When importing this realisation, the store will first check that all its * When importing this realisation, the store will first check that all its
* dependencies exist, and map to the correct output path * dependencies exist, and map to the correct output path
*/ */
std::map<DrvOutput, StorePath> dependentRealisations; std::map<DrvOutput, StorePath> dependentRealisations = {};
nlohmann::json toJSON() const; nlohmann::json toJSON() const;
static Realisation fromJSON(const nlohmann::json& json, const std::string& whence); static Realisation fromJSON(const nlohmann::json& json, const std::string& whence);

View file

@ -829,7 +829,7 @@ StorePathSet Store::queryValidPaths(const StorePathSet & paths, SubstituteFlag m
{ {
size_t left; size_t left;
StorePathSet valid; StorePathSet valid;
std::exception_ptr exc; std::exception_ptr exc = {};
}; };
Sync<State> state_(State{paths.size(), StorePathSet()}); Sync<State> state_(State{paths.size(), StorePathSet()});

View file

@ -78,11 +78,11 @@ struct RunOptions
{ {
Path program; Path program;
bool searchPath = true; bool searchPath = true;
Strings args; Strings args = {};
std::optional<uid_t> uid; std::optional<uid_t> uid = {};
std::optional<uid_t> gid; std::optional<uid_t> gid = {};
std::optional<Path> chdir; std::optional<Path> chdir = {};
std::optional<std::map<std::string, std::string>> environment; std::optional<std::map<std::string, std::string>> environment = {};
bool captureStdout = false; bool captureStdout = false;
bool mergeStderrToStdout = false; bool mergeStderrToStdout = false;
bool isInteractive = false; bool isInteractive = false;

View file

@ -147,7 +147,7 @@ TEST_P(PerTypeNonNullCompressionTest, truncatedValidInput)
/* n.b. This also tests zero-length input, which is also invalid. /* 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 * As of the writing of this comment, it returns empty output, but is
* allowed to throw a compression error instead. */ * allowed to throw a compression error instead. */
for (int i = 0; i < compressed.length(); ++i) { for (int i = 0; i < (int) compressed.length(); ++i) {
auto newCompressed = compressed.substr(compressed.length() - i); auto newCompressed = compressed.substr(compressed.length() - i);
try { try {
decompress(method, newCompressed); decompress(method, newCompressed);