From 2519a219353a78c6286d915da5a5e8b47153b90f Mon Sep 17 00:00:00 2001 From: peng xiao Date: Fri, 23 Aug 2013 15:35:55 +0800 Subject: [PATCH] Fix a potential bug of ParallelLoopBodyWrapper::operator(Range) On a 32-bit compiler the calculation may result in data (size_t) overflow when running some paralleled algorithms (which can safely run on a 64-bit compiler). This bug is found when running OpenCV's Retina tutorial on 32bit VS2010. --- modules/core/src/parallel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/parallel.cpp b/modules/core/src/parallel.cpp index 1ae8c96314..27d7ecc038 100644 --- a/modules/core/src/parallel.cpp +++ b/modules/core/src/parallel.cpp @@ -144,9 +144,9 @@ namespace { cv::Range r; r.start = (int)(wholeRange.start + - ((size_t)sr.start*(wholeRange.end - wholeRange.start) + nstripes/2)/nstripes); + ((uint64)sr.start*(wholeRange.end - wholeRange.start) + nstripes/2)/nstripes); r.end = sr.end >= nstripes ? wholeRange.end : (int)(wholeRange.start + - ((size_t)sr.end*(wholeRange.end - wholeRange.start) + nstripes/2)/nstripes); + ((uint64)sr.end*(wholeRange.end - wholeRange.start) + nstripes/2)/nstripes); (*body)(r); } cv::Range stripeRange() const { return cv::Range(0, nstripes); }