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

Integer overflow is undefined behavior #289

Closed
jamesjer opened this issue Jun 8, 2019 · 0 comments
Closed

Integer overflow is undefined behavior #289

jamesjer opened this issue Jun 8, 2019 · 0 comments

Comments

@jamesjer
Copy link

jamesjer commented Jun 8, 2019

While building CL11 1.8.0 on an x86_64 machine with gcc 9.1.1 (Fedora Rawhide), this test in HelpersTest fails:

[----------] 4 tests from CheckedMultiply
[ RUN ] CheckedMultiply.Int
/builddir/build/BUILD/CLI11-1.8.0/tests/HelpersTest.cpp:398: Failure
Value of: CLI::detail::checked_multiply(a, b)
Actual: true
Expected: false
[ FAILED ] CheckedMultiply.Int (0 ms)

The issue is that checked_multiply relies on integer overflow wrapping around, but that is undefined behavior according to the standard. When compiling with gcc, -fwrapv must be passed to the compiler so that it doesn't optimize away such code. I have verified that the test passes after adding that option to the build flags.

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

No branches or pull requests

2 participants