Fix arithmetic overflow warning. (#12712)

Fix arithmetic overflow warning. Suggested fix by static analysis tool
Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value.
Cast the value to the wider type before calling operator '+' to avoid overflow (io.2).
This commit is contained in:
Pranav Sharma 2022-08-24 18:27:30 -07:00 committed by GitHub
parent 7927d525a7
commit f1528ea50f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,7 +57,7 @@ struct BinaryElementwisePreparation {
[&C](int64_t dim) { if (dim != 1) C = dim; return (dim != 1); })) {
int32_t dim_C = gsl::narrow_cast<int32_t>(std::find(rhs_dims.begin(), rhs_dims.end(), C) - rhs_dims.begin() + output_shape.NumDimensions() - rhs_shape.NumDimensions());
int64_t N = output_shape.SizeToDimension(dim_C);
int64_t H = (dim_C < out_rank - 1 ? output_shape.SizeFromDimension(dim_C + 1) : 1);
int64_t H = (dim_C < out_rank - 1 ? output_shape.SizeFromDimension(static_cast<size_t>(dim_C) + 1) : 1);
std::vector<int64_t> new_output_dims;
if (N == 1) {