Merge pull request #13889 from mshabunin:enable-narrowing-warning
authorMaksim Shabunin <maksim.shabunin@gmail.com>
Tue, 26 Feb 2019 10:15:59 +0000 (13:15 +0300)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Tue, 26 Feb 2019 10:15:59 +0000 (13:15 +0300)
* 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
modules/python/src2/cv2.cpp
modules/videoio/src/cap_v4l.cpp

index a4b2c8f..872d601 100644 (file)
@@ -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)
index 13a6100..17abbc5 100644 (file)
@@ -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));
   }
 
 }
index 228c7ba..7cf985a 100644 (file)
@@ -226,6 +226,7 @@ make & enjoy!
 #include <assert.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <limits>
 
 #ifdef HAVE_CAMV4L2
 #include <asm/types.h>          /* 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<int>::max());
+    CV_Assert(form.fmt.pix.height <= (uint)std::numeric_limits<int>::max());
+    CvSize size = {(int)form.fmt.pix.width, (int)form.fmt.pix.height};
     int channels = 3;
     int depth = IPL_DEPTH_8U;