Avoid UBSan report in arrayElement#19347
Merged
alexey-milovidov merged 4 commits intomasterfrom Jan 21, 2021
Merged
Conversation
a3e617f to
2cd04e8
Compare
tavplubix
approved these changes
Jan 21, 2021
| else if (index.getType() == Field::Types::Int64) | ||
| { | ||
| /// Cast to UInt64 before negation allows to avoid undefined behaviour for negation of the most negative number. | ||
| /// NOTE: this would be undefined behaviour in C++ sense, but nevertheless, compiler cannot see it on user provided data, |
Member
There was a problem hiding this comment.
AFAIK, it's never an undefined behaviour according to the standard. Conversion from negative signed to unsigned integer is defined as addition of 2^{N-1} and negation of unsigned integer value is defined as 2^N - value. Am I missing something?
Member
Author
There was a problem hiding this comment.
It is the comment explaining why do we have this code (this code prevents UB that will be otherwise possible).
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Avoid UBSan reports in
arrayElementfunction,substringandarraySum. Fixes #19305. Fixes #19287. This closes #19336.