Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Prevent unintended sign extensions (#15230)
This is to resolve a Coverity hit, pointing out that a potentially unintended sign extension is possible: - `SectionHeaderNum` and `SectionHeaderSize` are unsigned i16. - By C++ promotion rules, `SectionHeaderNum * SectionHeaderSize` results in a signed i32 value. - However, `SectionHeaderOffset` is i64, so the i32 product is promoted to i64 via sign extension - If `SectionHeaderNum * 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` and `SectionHeaderSize` 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.
- Loading branch information