From 8c1e0537ecf1be2224f5a224f8f1aac40b2f5a02 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Tue, 26 Feb 2019 13:15:59 +0300 Subject: [PATCH] Merge pull request #13889 from mshabunin:enable-narrowing-warning * Enabled -Wnarrowing warning * Fixed type narrowing issues * Cast python constants * Use long long for python constants * Use int for python constants with fallback to long * Update cv2.cpp --- cmake/OpenCVCompilerOptions.cmake | 1 - modules/python/src2/cv2.cpp | 4 ++-- modules/videoio/src/cap_v4l.cpp | 5 ++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index a4b2c8f..872d601 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -119,7 +119,6 @@ if(CV_GCC OR CV_CLANG) add_extra_compiler_option(-Wcast-align) add_extra_compiler_option(-Wstrict-aliasing=2) else() - add_extra_compiler_option(-Wno-narrowing) add_extra_compiler_option(-Wno-delete-non-virtual-dtor) add_extra_compiler_option(-Wno-unnamed-type-template-args) add_extra_compiler_option(-Wno-comment) diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 13a6100..17abbc5 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -1838,7 +1838,7 @@ static PyMethodDef special_methods[] = { struct ConstDef { const char * name; - long val; + long long val; }; static void init_submodule(PyObject * root, const char * name, PyMethodDef * methods, ConstDef * consts) @@ -1877,7 +1877,7 @@ static void init_submodule(PyObject * root, const char * name, PyMethodDef * met } for (ConstDef * c = consts; c->name != NULL; ++c) { - PyDict_SetItemString(d, c->name, PyInt_FromLong(c->val)); + PyDict_SetItemString(d, c->name, PyLong_FromLongLong(c->val)); } } diff --git a/modules/videoio/src/cap_v4l.cpp b/modules/videoio/src/cap_v4l.cpp index 228c7ba..7cf985a 100644 --- a/modules/videoio/src/cap_v4l.cpp +++ b/modules/videoio/src/cap_v4l.cpp @@ -226,6 +226,7 @@ make & enjoy! #include #include #include +#include #ifdef HAVE_CAMV4L2 #include /* for videodev2.h */ @@ -538,7 +539,9 @@ bool CvCaptureCAM_V4L::convertableToRgb() const void CvCaptureCAM_V4L::v4l2_create_frame() { - CvSize size = {form.fmt.pix.width, form.fmt.pix.height}; + CV_Assert(form.fmt.pix.width <= (uint)std::numeric_limits::max()); + CV_Assert(form.fmt.pix.height <= (uint)std::numeric_limits::max()); + CvSize size = {(int)form.fmt.pix.width, (int)form.fmt.pix.height}; int channels = 3; int depth = IPL_DEPTH_8U; -- 2.7.4