fixed comparison to stop integer wrap around
authorEric Sommerlade <eric@robots.ox.ac.uk>
Tue, 26 Nov 2013 00:12:30 +0000 (00:12 +0000)
committerEric Sommerlade <eric@robots.ox.ac.uk>
Tue, 26 Nov 2013 00:12:30 +0000 (00:12 +0000)
modules/imgproc/src/samplers.cpp

index eb2f617..f1c1144 100644 (file)
@@ -97,7 +97,7 @@ icvAdjustRect( const void* srcptr, int src_step, int pix_size,
             rect.x = win_size.width;
     }
 
-    if( ip.x + win_size.width < src_size.width )
+    if( ip.x < src_size.width - win_size.width )
         rect.width = win_size.width;
     else
     {
@@ -118,7 +118,7 @@ icvAdjustRect( const void* srcptr, int src_step, int pix_size,
     else
         rect.y = -ip.y;
 
-    if( ip.y + win_size.height < src_size.height )
+    if( ip.y < src_size.height - win_size.height )
         rect.height = win_size.height;
     else
     {
@@ -164,8 +164,8 @@ CvStatus CV_STDCALL icvGetRectSubPix_##flavor##_C1R                         \
     src_step /= sizeof(src[0]);                                             \
     dst_step /= sizeof(dst[0]);                                             \
                                                                             \
-    if( 0 <= ip.x && ip.x + win_size.width < src_size.width &&              \
-        0 <= ip.y && ip.y + win_size.height < src_size.height )             \
+    if( 0 <= ip.x && ip.x < src_size.width - win_size.width &&              \
+        0 <= ip.y && ip.y < src_size.height - win_size.height )             \
     {                                                                       \
         /* extracted rectangle is totally inside the image */               \
         src += ip.y * src_step + ip.x;                                      \
@@ -270,8 +270,8 @@ static CvStatus CV_STDCALL icvGetRectSubPix_##flavor##_C3R                  \
     src_step /= sizeof( src[0] );                                           \
     dst_step /= sizeof( dst[0] );                                           \
                                                                             \
-    if( 0 <= ip.x && ip.x + win_size.width < src_size.width &&              \
-        0 <= ip.y && ip.y + win_size.height < src_size.height )             \
+    if( 0 <= ip.x && ip.x < src_size.width - win_size.width &&              \
+        0 <= ip.y && ip.y < src_size.height - win_size.height )             \
     {                                                                       \
         /* extracted rectangle is totally inside the image */               \
         src += ip.y * src_step + ip.x*3;                                    \
@@ -407,8 +407,8 @@ CvStatus CV_STDCALL icvGetRectSubPix_8u32f_C1R
     src_step /= sizeof(src[0]);
     dst_step /= sizeof(dst[0]);
 
-    if( 0 <= ip.x && ip.x + win_size.width < src_size.width &&
-        0 <= ip.y && ip.y + win_size.height < src_size.height )
+    if( 0 <= ip.x && ip.x < src_size.width - win_size.width &&
+        0 <= ip.y && ip.y < src_size.height - win_size.height )
     {
         // extracted rectangle is totally inside the image
         src += ip.y * src_step + ip.x;