From 4181b8b6fe45aac7ae921be5cd7d24c21ad4982b Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Fri, 2 Aug 2019 07:56:59 -0700 Subject: [PATCH] Make explicit promotion in signed/unsigned comparison. As signed index is verified to be >= 0 at the point of compare with the unsigned size, we can make the compare explicitly an unsigned compare by casting index. Also avoids -Wsign-compare warning where enabled. PiperOrigin-RevId: 261321178 --- tensorflow/core/util/tensor_format.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tensorflow/core/util/tensor_format.h b/tensorflow/core/util/tensor_format.h index 82af5c545f7..c2cf52008ab 100644 --- a/tensorflow/core/util/tensor_format.h +++ b/tensorflow/core/util/tensor_format.h @@ -20,6 +20,7 @@ limitations under the License. #include #include "tensorflow/core/framework/tensor.h" +#include "tensorflow/core/lib/gtl/array_slice.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/platform/types.h" @@ -441,7 +442,9 @@ T GetFilterDim(gtl::ArraySlice dimension_attribute, filter_tensor_format) == 3) ? GetFilterDimIndex<3>(filter_tensor_format, dimension) : GetFilterDimIndex<2>(filter_tensor_format, dimension); - CHECK(index >= 0 && index < dimension_attribute.size()) + using size_type = typename gtl::ArraySlice::size_type; + CHECK(index >= 0 && + static_cast(index) < dimension_attribute.size()) << "Invalid index from the dimension: " << index << ", " << filter_tensor_format << ", " << dimension; return dimension_attribute[index];