From 5474935a8180f51eee32de7a4174c280b015fff4 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 28 Jan 2014 20:22:56 +0400 Subject: [PATCH 1/3] fixes for defects from code coverity --- modules/core/src/ocl.cpp | 3 ++- modules/imgproc/src/filter.cpp | 2 +- modules/java/generator/gen_java.py | 4 ++-- modules/java/generator/src/cpp/Mat.cpp | 2 +- modules/java/generator/src/cpp/utils.cpp | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 7201fca71..1a2714d05 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -3673,6 +3673,7 @@ struct PlatformInfo2::Impl { Impl(void* id) { + refcount = 1; handle = *(cl_platform_id*)id; getDevices(devices, handle); } @@ -3713,7 +3714,7 @@ int PlatformInfo2::deviceNumber() const void PlatformInfo2::getDevice(Device& device, int d) const { - CV_Assert(d < (int)p->devices.size() ); + CV_Assert(p && d < (int)p->devices.size() ); if(p) device.set(p->devices[d]); } diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 8c11c62db..d644f2348 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -3508,7 +3508,7 @@ static bool ocl_sepFilter2D( InputArray _src, OutputArray _dst, int ddepth, int type = _src.type(); if ( !( (CV_8UC1 == type || CV_8UC4 == type || CV_32FC1 == type || CV_32FC4 == type) && - (ddepth == CV_32F || ddepth == CV_8U) ) ) + (ddepth == CV_32F || ddepth == CV_8U || ddepth < 0) ) ) return false; int cn = CV_MAT_CN(type); diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index 23ed3a9a1..cce270828 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -398,7 +398,7 @@ JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Core_n_1minMaxLocManual return result; - } catch(cv::Exception e) { + } catch(const cv::Exception& e) { LOGD("Core::n_1minMaxLoc() catched cv::Exception: %s", e.what()); jclass je = env->FindClass("org/opencv/core/CvException"); if(!je) je = env->FindClass("java/lang/Exception"); @@ -471,7 +471,7 @@ JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Core_n_1getTextSize return result; - } catch(cv::Exception e) { + } catch(const cv::Exception& e) { LOGD("Core::n_1getTextSize() catched cv::Exception: %s", e.what()); jclass je = env->FindClass("org/opencv/core/CvException"); if(!je) je = env->FindClass("java/lang/Exception"); diff --git a/modules/java/generator/src/cpp/Mat.cpp b/modules/java/generator/src/cpp/Mat.cpp index b3b0f66e7..185cb2de9 100644 --- a/modules/java/generator/src/cpp/Mat.cpp +++ b/modules/java/generator/src/cpp/Mat.cpp @@ -467,7 +467,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1dims LOGD("%s", method_name); Mat* me = (Mat*) self; //TODO: check for NULL return me->dims; - } catch(cv::Exception e) { + } catch(const cv::Exception& e) { throwJavaException(env, &e, method_name); } catch (...) { throwJavaException(env, 0, method_name); diff --git a/modules/java/generator/src/cpp/utils.cpp b/modules/java/generator/src/cpp/utils.cpp index 40811e8f9..2d409c863 100644 --- a/modules/java/generator/src/cpp/utils.cpp +++ b/modules/java/generator/src/cpp/utils.cpp @@ -48,7 +48,7 @@ JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nBitmapToMat2 } AndroidBitmap_unlockPixels(env, bitmap); return; - } catch(cv::Exception e) { + } catch(const cv::Exception& e) { AndroidBitmap_unlockPixels(env, bitmap); LOGE("nBitmapToMat catched cv::Exception: %s", e.what()); jclass je = env->FindClass("org/opencv/core/CvException"); @@ -130,7 +130,7 @@ JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nMatToBitmap2 } AndroidBitmap_unlockPixels(env, bitmap); return; - } catch(cv::Exception e) { + } catch(const cv::Exception& e) { AndroidBitmap_unlockPixels(env, bitmap); LOGE("nMatToBitmap catched cv::Exception: %s", e.what()); jclass je = env->FindClass("org/opencv/core/CvException"); From f91f55927e2fcee80d407b4501aa1f705e39e8da Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 29 Jan 2014 17:37:52 +0400 Subject: [PATCH 2/3] fix memory management problem --- modules/core/include/opencv2/core/ocl.hpp | 3 +++ modules/core/src/ocl.cpp | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/modules/core/include/opencv2/core/ocl.hpp b/modules/core/include/opencv2/core/ocl.hpp index 850a2e60e..3b790af98 100644 --- a/modules/core/include/opencv2/core/ocl.hpp +++ b/modules/core/include/opencv2/core/ocl.hpp @@ -561,6 +561,9 @@ public: explicit PlatformInfo2(void* id); ~PlatformInfo2(); + PlatformInfo2(const PlatformInfo2& i); + PlatformInfo2& operator =(const PlatformInfo2& i); + String name() const; String vendor() const; String version() const; diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 1a2714d05..d1e13a8a3 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -3707,6 +3707,26 @@ PlatformInfo2::~PlatformInfo2() p->release(); } +PlatformInfo2::PlatformInfo2(const PlatformInfo2& i) +{ + if (i.p) + i.p->addref(); + this->p = i.p; +} + +PlatformInfo2& PlatformInfo2::operator =(const PlatformInfo2& i) +{ + if (i.p != this->p) + { + if (i.p) + i.p->addref(); + if (this->p) + this->p->release(); + this->p = i.p; + } + return *this; +} + int PlatformInfo2::deviceNumber() const { return p ? (int)p->devices.size() : 0; From 6fa49f6e806c452a7fdc032591a3a9eab0550d52 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 29 Jan 2014 18:58:27 +0400 Subject: [PATCH 3/3] fix unintialized fields --- modules/video/src/lkpyramid.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index 382914b2d..598e69c88 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -598,6 +598,7 @@ namespace cv struct dim3 { unsigned int x, y, z; + dim3() : x(0), y(0), z(0) { } }; public: PyrLKOpticalFlow() @@ -607,6 +608,8 @@ namespace cv iters = 30; derivLambda = 0.5; useInitialFlow = false; + + waveSize = 0; } bool checkParam()