From f3cb5084cf1ede04a287766f539ab00162c0eb68 Mon Sep 17 00:00:00 2001 From: Juha Reunanen Date: Sun, 29 Jan 2017 17:32:40 +0200 Subject: [PATCH] Fix #8093: CV_DbgAssert that the result of area() fits in the return value --- modules/core/include/opencv2/core/types.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp index d5c64ca787..13cbe68981 100644 --- a/modules/core/include/opencv2/core/types.hpp +++ b/modules/core/include/opencv2/core/types.hpp @@ -1592,7 +1592,10 @@ Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz) template inline _Tp Size_<_Tp>::area() const { - return width * height; + const _Tp result = width * height; + CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer + || width == 0 || result / width == height); // make sure the result fits in the return value + return result; } template static inline @@ -1731,7 +1734,10 @@ Size_<_Tp> Rect_<_Tp>::size() const template inline _Tp Rect_<_Tp>::area() const { - return width * height; + const _Tp result = width * height; + CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer + || width == 0 || result / width == height); // make sure the result fits in the return value + return result; } template template inline