diff --git a/modules/core/src/drawing.cpp b/modules/core/src/drawing.cpp index c8fbc3c533..56cac1515a 100644 --- a/modules/core/src/drawing.cpp +++ b/modules/core/src/drawing.cpp @@ -2033,12 +2033,14 @@ cvDrawContours( void* _img, CvSeq* contour, scalarToRawData( externalColor, ext_buf, img.type(), 0 ); scalarToRawData( holeColor, hole_buf, img.type(), 0 ); + maxLevel = MAX(maxLevel, INT_MIN-2); + maxLevel = MIN(maxLevel, INT_MAX-1); + if( maxLevel < 0 ) { h_next = contour->h_next; contour->h_next = 0; maxLevel = -maxLevel+1; - maxLevel -= maxLevel < 0; } cvInitTreeNodeIterator( &iterator, contour, maxLevel );