Skip to content

Commit

Permalink
fix(libmain/common-args): do not exceed maximum allowed verbosity
Browse files Browse the repository at this point in the history
This patch gets rid of UB when verbosity exceeds the maximum logging value of `lvlVomit = 7` and
reaches invalid values (e.g. 8). This is actually triggered in functional tests.
There are too many occurrences to list, but here's one from the UBSAN log:

../src/libstore/gc.cc:610:5: runtime error: load of value 8, which is not a valid value for type 'Verbosity'

(cherry picked from commit b9f8c4a)
  • Loading branch information
xokdvium authored and mergify[bot] committed Jan 10, 2025
1 parent e0c8b0f commit dea80c4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/libmain/common-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ MixCommonArgs::MixCommonArgs(const std::string & programName)
.shortName = 'v',
.description = "Increase the logging verbosity level.",
.category = loggingCategory,
.handler = {[]() { verbosity = (Verbosity) (verbosity + 1); }},
.handler = {[]() {
verbosity = (Verbosity) std::min<std::underlying_type_t<Verbosity>>(verbosity + 1, lvlVomit);
}},
});

addFlag({
Expand Down

0 comments on commit dea80c4

Please sign in to comment.