From 2bf63f4c33e8fa3815cca74e03760eb23f17a7c0 Mon Sep 17 00:00:00 2001 From: Gabor Buella Date: Sat, 2 Feb 2019 07:33:55 +0100 Subject: [PATCH] Fix std::abs usage in memory_optimize_pass.cc (#15627) test=develop size_t is an unsigned integer, with a conversion rank larger than int, therefore in the following expression the int value was promoted to size_t, making it a subtraction of unsigned values. The result of such a subtraction is also an unsigned value. --- .../inference/analysis/passes/memory_optimize_pass.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/inference/analysis/passes/memory_optimize_pass.cc b/paddle/fluid/inference/analysis/passes/memory_optimize_pass.cc index 3d1be9196..4b0a9d9b1 100644 --- a/paddle/fluid/inference/analysis/passes/memory_optimize_pass.cc +++ b/paddle/fluid/inference/analysis/passes/memory_optimize_pass.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include "paddle/fluid/framework/ir/graph_helper.h" @@ -168,7 +169,11 @@ bool FindSuitableTensorToReuse( if (!cluster->count(candidate)) continue; size_t space = space_table.at(candidate); - size_t space_diff = std::abs(space - space_required); + PADDLE_ENFORCE( + space <= std::numeric_limits::type>::max(), + "space overload"); + size_t space_diff = + std::abs((std::make_signed::type)space - space_required); if (space_diff < best_fit.second) { best_fit.first = candidate; best_fit.second = space_diff; -- GitLab