Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make clang -fsanitize=unsigned-integer-overflow happy #328

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

rouault
Copy link
Contributor

@rouault rouault commented Mar 11, 2024

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)

rouault added 2 commits March 11, 2024 22:09
…g to make clang -fsanitize=unsigned-integer-overflow happy
@p-ranav p-ranav merged commit 20f0196 into p-ranav:master Mar 12, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants