From 53cfb62a19fd6e712ff874e153720e0590f4cf20 Mon Sep 17 00:00:00 2001 From: Tita Wang Date: Wed, 8 Jul 2026 20:23:41 +0000 Subject: [PATCH] Hoist CropAndResize index offset to a named int64_t Replace the inline `static_cast(...)` around the per-channel base offset in CropAndResizeForward with a named `int64_t bottom_data_offset` local in both the bilinear and nearest branches. Initializing an `int64_t` directly from the `SafeInt` expression is unambiguous and keeps the SafeInt overflow checking on the offset computation, while reading more clearly than the previous inline cast. No behavior change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Tita Wang --- onnxruntime/contrib_ops/cpu/crop_and_resize.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/onnxruntime/contrib_ops/cpu/crop_and_resize.cc b/onnxruntime/contrib_ops/cpu/crop_and_resize.cc index 47f164fde8322..5da7d5e3c016a 100644 --- a/onnxruntime/contrib_ops/cpu/crop_and_resize.cc +++ b/onnxruntime/contrib_ops/cpu/crop_and_resize.cc @@ -149,9 +149,8 @@ void CropAndResizeForward(const TensorShape& output_shape, for (auto c = 0; c < channels; c++) { int64_t index_n_c = index_n + c * pooled_width * pooled_height; int64_t index = index_n_c + ph * pooled_width + pw; - const T* offset_bottom_data = - bottom_data + - static_cast((SafeInt(roi_batch_ind) * channels + c) * height * width); + const int64_t bottom_data_offset = (SafeInt(roi_batch_ind) * channels + c) * height * width; + const T* offset_bottom_data = bottom_data + bottom_data_offset; const float top_left(static_cast(offset_bottom_data[top_left_index])); const float top_right(static_cast(offset_bottom_data[top_right_index])); const float bottom_left(static_cast(offset_bottom_data[bottom_left_index])); @@ -169,9 +168,8 @@ void CropAndResizeForward(const TensorShape& output_shape, for (auto c = 0; c < channels; c++) { int64_t index_n_c = index_n + c * pooled_width * pooled_height; int64_t index = index_n_c + ph * pooled_width + pw; - const T* offset_bottom_data = - bottom_data + - static_cast((SafeInt(roi_batch_ind) * channels + c) * height * width); + const int64_t bottom_data_offset = (SafeInt(roi_batch_ind) * channels + c) * height * width; + const T* offset_bottom_data = bottom_data + bottom_data_offset; top_data[index] = static_cast(offset_bottom_data[closest_index]); } }