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

Fix checks for signed overflow #207

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

jefftrull
Copy link
Collaborator

@jefftrull jefftrull commented Feb 2, 2024

When verifying that code being preprocessed does not invoke undefined behavior, Wave does it itself.
This change performs tests on the operands in advance, instead.

Tests t_6_15, t_6_17, and t_6_18 (though not t_6_17, for some reason) signal errors in the absence of this fix with -fsanitize=signed-integer-overflow configured, but it does not cause the tests to fail, because these tests are expected to exit with an error anyway.

If merged, this will fix #197

@jefftrull jefftrull requested a review from hkaiser February 2, 2024 21:31
The previous code checked for signed overflow on +, -, and * by doing
the operation and checking the result, which can invoke undefined
behavior. This replaces that code with initial tests on the operands.

In addition, a test for the sole integer division overflow case (that
is not division by zero) was missing: INT_MIN / -1
It has now been added, along with a test case.
@jefftrull jefftrull force-pushed the bugfix/ub-signed-overflow branch from d6eb81a to df2125a Compare June 25, 2024 22:04
@jefftrull
Copy link
Collaborator Author

While reviewing this old PR I realized that we don't handle INT_MIN / -1 properly so I've added that.

@jefftrull jefftrull changed the title Avoid invoking UB when testing for signed overflow Fix checks for signed overflow Jun 25, 2024
@jefftrull jefftrull merged commit da98931 into boostorg:develop Jun 26, 2024
7 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.

Test for signed overflow occurs after UB invoked
1 participant