@@ -284,10 +284,13 @@ cvStartFindContours( void* _img, CvMemStorage* storage,
284
284
scanner->cinfo_storage );
285
285
}
286
286
287
+ CV_Assert (step >= 0 );
288
+ CV_Assert (size.height >= 1 );
289
+
287
290
/* make zero borders */
288
291
int esz = CV_ELEM_SIZE (mat->type );
289
292
memset ( img, 0 , size.width *esz );
290
- memset ( img + step * (size.height - 1 ), 0 , size.width *esz );
293
+ memset ( img + static_cast < size_t >( step) * (size.height - 1 ), 0 , size.width *esz );
291
294
292
295
img += step;
293
296
for ( int y = 1 ; y < size.height - 1 ; y++, img += step )
@@ -989,6 +992,8 @@ cvFindNextContour( CvContourScanner scanner )
989
992
{
990
993
if ( !scanner )
991
994
CV_Error ( CV_StsNullPtr, " " );
995
+ CV_Assert (scanner->img_step >= 0 );
996
+
992
997
icvEndProcessContour ( scanner );
993
998
994
999
/* initialize local state */
@@ -1063,7 +1068,7 @@ cvFindNextContour( CvContourScanner scanner )
1063
1068
is_hole = 1 ;
1064
1069
}
1065
1070
1066
- if ( mode == 0 && (is_hole || img0[lnbd.y * step + lnbd.x ] > 0 ) )
1071
+ if ( mode == 0 && (is_hole || img0[lnbd.y * static_cast < size_t >( step) + lnbd.x ] > 0 ) )
1067
1072
goto resume_scan;
1068
1073
1069
1074
origin.y = y;
@@ -1077,8 +1082,8 @@ cvFindNextContour( CvContourScanner scanner )
1077
1082
else
1078
1083
{
1079
1084
int lval = (img0_i ?
1080
- img0_i[lnbd.y * step_i + lnbd.x ] :
1081
- (int )img0[lnbd.y * step + lnbd.x ]) & 0x7f ;
1085
+ img0_i[lnbd.y * static_cast < size_t >( step_i) + lnbd.x ] :
1086
+ (int )img0[lnbd.y * static_cast < size_t >( step) + lnbd.x ]) & 0x7f ;
1082
1087
_CvContourInfo *cur = scanner->cinfo_table [lval];
1083
1088
1084
1089
/* find the first bounding contour */
@@ -1090,11 +1095,11 @@ cvFindNextContour( CvContourScanner scanner )
1090
1095
if ( par_info )
1091
1096
{
1092
1097
if ( (img0_i &&
1093
- icvTraceContour_32s ( img0_i + par_info->origin .y * step_i +
1098
+ icvTraceContour_32s ( img0_i + par_info->origin .y * static_cast < size_t >( step_i) +
1094
1099
par_info->origin .x , step_i, img_i + lnbd.x ,
1095
1100
par_info->is_hole ) > 0 ) ||
1096
1101
(!img0_i &&
1097
- icvTraceContour ( img0 + par_info->origin .y * step +
1102
+ icvTraceContour ( img0 + par_info->origin .y * static_cast < size_t >( step) +
1098
1103
par_info->origin .x , step, img + lnbd.x ,
1099
1104
par_info->is_hole ) > 0 ) )
1100
1105
break ;
0 commit comments