-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(libmain/common-args): don't overflow verbosity
This patch gets rid of UB when verbosity overflows to 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' Verbosity is now a strong type instead of a plain enum (which is mostly indistinguishable from the underlying type). The type still for all intents and purposes looks like an enumeration, can be used in switches, provides static constexpr member types, but also has member functions. This makes it very unlikely that we'll have such problems in the future, since now `Verbosity` has a saturating contract for increment/decrement. Regarding the implementation. This might look like witchcraft, but is completely legal. I've tested that this code (the `Verbosity` static const member pattern) compiles when going back to GCC 7.1.0, Clang 5.0.0 and MSVC 19.21.
- Loading branch information
Showing
3 changed files
with
99 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters