Skip to content

Commit 48f7cbe

Browse files
committed
Merge pull request opencv#8107 from reunanen:fix8093
2 parents a2fed4c + f3cb508 commit 48f7cbe

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

modules/core/include/opencv2/core/types.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,10 @@ Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz)
15921592
template<typename _Tp> inline
15931593
_Tp Size_<_Tp>::area() const
15941594
{
1595-
return width * height;
1595+
const _Tp result = width * height;
1596+
CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer
1597+
|| width == 0 || result / width == height); // make sure the result fits in the return value
1598+
return result;
15961599
}
15971600

15981601
template<typename _Tp> static inline
@@ -1731,7 +1734,10 @@ Size_<_Tp> Rect_<_Tp>::size() const
17311734
template<typename _Tp> inline
17321735
_Tp Rect_<_Tp>::area() const
17331736
{
1734-
return width * height;
1737+
const _Tp result = width * height;
1738+
CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer
1739+
|| width == 0 || result / width == height); // make sure the result fits in the return value
1740+
return result;
17351741
}
17361742

17371743
template<typename _Tp> template<typename _Tp2> inline

0 commit comments

Comments
 (0)