Merge "tree-wide: fix a pile of lints" into main

This commit is contained in:
jade 2024-12-10 20:29:53 +00:00 committed by Gerrit Code Review
commit 9a96086381
19 changed files with 17 additions and 38 deletions

View file

@ -16,6 +16,8 @@ Checks:
- -bugprone-unchecked-optional-access
# many warnings, seems like a questionable lint
- -bugprone-branch-clone
# extremely noisy before clang 19: https://github.com/llvm/llvm-project/issues/93959
- -bugprone-multi-level-implicit-pointer-conversion
# all thrown exceptions must derive from std::exception
- hicpp-exception-baseclass
# capturing async lambdas are dangerous
@ -33,3 +35,4 @@ Checks:
CheckOptions:
bugprone-reserved-identifier.AllowedIdentifiers: '__asan_default_options'
bugprone-unused-return-value.AllowCastToVoid: true

View file

@ -1326,7 +1326,7 @@ static void opSwitchGeneration(Globals & globals, Strings opFlags, Strings opArg
throw UsageError("exactly one argument expected");
if (auto dstGen = string2Int<GenerationNumber>(opArgs.front()))
switchGeneration(globals.profile, *dstGen, globals.dryRun);
switchGeneration(globals.profile, dstGen, globals.dryRun);
else
throw UsageError("expected a generation number");
}

View file

@ -120,7 +120,6 @@ std::pair<SourcePath, uint32_t> findPackageFilename(EvalState & state, Value & v
try {
auto colon = fn.rfind(':');
if (colon == std::string::npos) fail();
std::string filename(fn, 0, colon);
auto lineno = std::stoi(std::string(fn, colon + 1, std::string::npos));
return {CanonPath(fn.substr(0, colon)), lineno};
} catch (std::invalid_argument & e) {

View file

@ -263,9 +263,7 @@ std::optional<Hash> Input::getNarHash() const
std::optional<std::string> Input::getRef() const
{
if (auto s = maybeGetStrAttr(attrs, "ref"))
return *s;
return {};
return maybeGetStrAttr(attrs, "ref");
}
std::optional<Hash> Input::getRev() const
@ -286,16 +284,12 @@ std::optional<Hash> Input::getRev() const
std::optional<uint64_t> Input::getRevCount() const
{
if (auto n = maybeGetIntAttr(attrs, "revCount"))
return *n;
return {};
return maybeGetIntAttr(attrs, "revCount");
}
std::optional<time_t> Input::getLastModified() const
{
if (auto n = maybeGetIntAttr(attrs, "lastModified"))
return *n;
return {};
return maybeGetIntAttr(attrs, "lastModified");
}
ParsedURL InputScheme::toURL(const Input & input) const

View file

@ -132,7 +132,7 @@ std::optional<std::string> readHeadCached(const std::string & actualUrl)
// This function must behave the same way, so we return the expired
// cached ref here.
warn("could not get HEAD ref for repository '%s'; using expired cached ref '%s'", actualUrl, *cachedRef);
return *cachedRef;
return cachedRef;
}
return std::nullopt;

View file

@ -1286,7 +1286,7 @@ HookReply DerivationGoal::tryBuildHook()
hook->toHook.reset();
/* Create the log file and pipe. */
Path logFile = openLogFile();
openLogFile();
builderOutFD = &hook->builderOut;
return HookReply::Accept{handleChildOutput()};

View file

@ -707,7 +707,7 @@ kj::Promise<Outcome<void, Goal::WorkResult>> LocalDerivationGoal::startBuilder()
printMsg(lvlVomit, "setting builder env variable '%1%'='%2%'", i.first, i.second);
/* Create the log file. */
Path logFile = openLogFile();
openLogFile();
/* Create a pseudoterminal to get the output of the builder. */
builderOutPTY = AutoCloseFD{posix_openpt(O_RDWR | O_NOCTTY)};

View file

@ -93,7 +93,7 @@ WireFormatGenerator CommonProto::Serialise<std::optional<ContentAddress>>::write
{
return [](std::string s) -> WireFormatGenerator {
co_yield s;
}(caOpt ? renderContentAddress(*caOpt) : "");
}(caOpt ? renderContentAddress(caOpt) : "");
}
}

View file

@ -13,14 +13,9 @@ void Store::exportPaths(const StorePathSet & paths, Sink & sink)
auto sorted = topoSortPaths(paths);
std::reverse(sorted.begin(), sorted.end());
std::string doneLabel("paths exported");
//logger->incExpected(doneLabel, sorted.size());
for (auto & path : sorted) {
//Activity act(*logger, lvlInfo, "exporting path '%s'", path);
sink << 1;
exportPath(path, sink);
//logger->incProgress(doneLabel);
}
sink << 0;

View file

@ -145,7 +145,6 @@ struct NarAccessor : public FSAccessor
NarMember * find(const Path & path)
{
Path canon = path == "" ? "" : canonPath(path);
NarMember * current = &root;
auto end = path.end();
for (auto it = path.begin(); it != end; ) {

View file

@ -120,7 +120,7 @@ std::string NarInfo::to_string(const Store & store) const
res += "Sig: " + sig + "\n";
if (ca)
res += "CA: " + renderContentAddress(*ca) + "\n";
res += "CA: " + renderContentAddress(ca) + "\n";
return res;
}

View file

@ -1365,8 +1365,7 @@ std::optional<StorePath> Store::getBuildDerivationPath(const StorePath & path)
if (!path.isDerivation()) {
try {
auto info = queryPathInfo(path);
if (!info->deriver) return std::nullopt;
return *info->deriver;
return info->deriver;
} catch (InvalidPath &) {
return std::nullopt;
}

View file

@ -25,7 +25,7 @@ std::string hiliteMatches(
out.append(s.substr(last_end, m.position() - last_end));
// Merge continous matches
ssize_t end = start + m.length();
while (++it != matches.end() && (*it).position() <= end) {
for (++it; it != matches.end() && (*it).position() <= end; ++it) {
auto n = *it;
ssize_t nend = start + (n.position() - start + n.length());
if (nend > end)

View file

@ -116,7 +116,6 @@ void Source::operator () (char * data, size_t len)
void Source::drainInto(Sink & sink)
{
std::string s;
std::array<char, 8192> buf;
while (true) {
size_t n;
@ -297,7 +296,7 @@ Error readError(Source & source)
auto type = readString(source);
assert(type == "Error");
auto level = (Verbosity) readInt(source);
auto name = readString(source); // removed
readString(source); // removed (name)
auto msg = readString(source);
ErrorInfo info {
.level = level,

View file

@ -34,7 +34,7 @@ bool shouldANSI(StandardOutputStream fileno)
// FIXME(jade): replace with TerminalCodeEater. wowie this is evil code.
std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int width, bool eatTabs)
{
std::string t, e;
std::string t;
size_t w = 0;
auto i = s.begin();

View file

@ -117,8 +117,6 @@ struct CmdBundle : InstallableCommand
},
});
auto outPathS = store->printStorePath(outPath);
if (!outLink) {
auto * attr = vRes->attrs->get(evaluator->s.name);
if (!attr)

View file

@ -118,7 +118,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
std::cout << '\t';
Strings ss;
if (info->ultimate) ss.push_back("ultimate");
if (info->ca) ss.push_back("ca:" + renderContentAddress(*info->ca));
if (info->ca) ss.push_back("ca:" + renderContentAddress(info->ca));
for (auto & sig : info->sigs) ss.push_back(sig);
std::cout << concatStringsSep(" ", ss);
}

View file

@ -159,7 +159,6 @@ struct CmdSearch : InstallableCommand, MixJSON
{"description", description},
};
} else {
auto name2 = hiliteMatches(name.name, nameMatches, ANSI_GREEN, "\e[0;2m");
if (results > 1) logger->cout("");
logger->cout(
"* %s%s",

View file

@ -40,13 +40,9 @@ struct CmdCopySigs : StorePathsCommand
ThreadPool pool{"CopySigs pool"};
std::string doneLabel = "done";
std::atomic<size_t> added{0};
//logger->setExpected(doneLabel, storePaths.size());
auto doPath = [&](const Path & storePathS) {
//Activity act(*logger, lvlInfo, "getting signatures for '%s'", storePath);
checkInterrupt();
@ -78,8 +74,6 @@ struct CmdCopySigs : StorePathsCommand
store->addSignatures(storePath, newSigs);
added += newSigs.size();
}
//logger->incProgress(doneLabel);
};
for (auto & storePath : storePaths)