Make clang -fsanitize=unsigned-integer-overflow happy #328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm integrating this fantastic library into a larger project (https://gdal.org) that has a CI configuration building with clang's
-fsanitize=unsigned-integer-overflow
mode, and it currently halts in a few places of argparse. This is apparently due to the std::map<> methods using unsigned integer overflow when they key is a std::string_view, at least with clang 10 on Ubuntu 20.04. Unsigned integer overflow is well defined behavior in C/C++, but I tend to think it is preferable to avoid it to be able to detect real bugs where the overflow is not desired. With those changes, argparse unit test now run fine with-fsanitize=unsigned-integer-overflow
I also find it quite fragile to use a std::string_view as the key of a map. This assumes that the key has a lifetime greater or equal to the instance of argparse (I actually got bitten by this in a customization of argparse, where I didn't realize I couldn't use an ephemeral string)