mirror of
https://github.com/opencv/opencv.git
synced 2026-09-11 12:52:33 -05:00
core: fix unsigned Rect intersection for disjoint rectangles (#11988) - #29069 Fixes #11988 ## Problem `Rect_<_Tp>::operator&` / `operator&=` returned a non-empty rectangle when two **unsigned** rectangles do not overlap. ### Example: ```cpp cv::Rect_<unsigned> r1(0, 0, 1, 1); cv::Rect_<unsigned> r2(2, 2, 1, 1); auto inter = r1 & r2; // was [1 x 1 from (2, 2)], expected empty ``` Root cause: the previous implementation subtracted edge coordinates before checking overlap. For `unsigned _Tp`, expressions like `width - (x_max - x_min)` can underflow when rectangles are disjoint. ### Solution Add a check for underflow ### Tests Added regression test `Core_Rect.test_unsigned_overflow in modules/core/test/test_misc.cpp`.