[SYCL] Prevent unintended sign extensions #15230
Merged
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.
This is to resolve a Coverity hit, pointing out that a potentially unintended sign extension is possible:
SectionHeaderNum
andSectionHeaderSize
are unsigned i16.SectionHeaderNum * SectionHeaderSize
results in a signed i32 value.SectionHeaderOffset
is i64, so the i32 product is promoted to i64 via sign extensionSectionHeaderNum * SectionHeaderSize
results in a number greater than 0x7FFFFF (greatest signed i32 number), then the upper bits get set to 1, producing the wrong result.This PR adds a cast to ensure the promotions do not result in unexpected sign extensions: While I recognize that the odds of
SectionHeaderNum
andSectionHeaderSize
getting as big as sqrt(0x7FFFFFF) is rather unlikely, this change does not hurt or slow down the code, and is probably the safer thing to do anyway. If it is decided that this change is not necessarily, feel free to close the PR, and I will fix the Coverity triage to reflect the decision.