From f1528ea50f618bbdc9ad7ce54eac52d7061505ed Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Wed, 24 Aug 2022 18:27:30 -0700 Subject: [PATCH] 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). --- onnxruntime/core/providers/cuda/math/binary_elementwise_ops.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/cuda/math/binary_elementwise_ops.h b/onnxruntime/core/providers/cuda/math/binary_elementwise_ops.h index fcab87c193..c07324a8ac 100644 --- a/onnxruntime/core/providers/cuda/math/binary_elementwise_ops.h +++ b/onnxruntime/core/providers/cuda/math/binary_elementwise_ops.h @@ -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(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(dim_C) + 1) : 1); std::vector new_output_dims; if (N == 1) {