From cca4472ae27e785b5d918af1877505fad390bed5 Mon Sep 17 00:00:00 2001 From: Cary Phillips Date: Mon, 24 Jun 2019 17:20:02 -0700 Subject: [PATCH] Various fixes to address compiler warnings: - removed unused variables and functions - added default cases to switch statements - member initialization order in class constructors - lots of signed/unsigned comparisons fixed either by changing a loop iterator from int to size_t, or by selective type casting. Signed-off-by: Cary Phillips --- IlmBase/Imath/ImathFun.cpp | 4 +- IlmBase/Imath/ImathMatrixAlgo.cpp | 12 +++--- IlmBase/ImathTest/testBoxAlgo.cpp | 42 +-------------------- IlmBase/ImathTest/testExtractEuler.cpp | 1 - IlmBase/ImathTest/testExtractSHRT.cpp | 1 - IlmBase/ImathTest/testJacobiEigenSolver.cpp | 16 ++++---- IlmBase/ImathTest/testLineAlgo.cpp | 1 - IlmBase/ImathTest/testProcrustes.cpp | 4 +- IlmBase/ImathTest/testShear.cpp | 1 - PyIlmBase/PyImath/PyImathAutovectorize.h | 2 +- PyIlmBase/PyImath/PyImathBox.cpp | 2 +- PyIlmBase/PyImath/PyImathBoxArrayImpl.h | 2 +- PyIlmBase/PyImath/PyImathEuler.cpp | 4 ++ PyIlmBase/PyImath/PyImathFixedArray.h | 16 ++++---- PyIlmBase/PyImath/PyImathFixedArray2D.h | 32 ++++++++-------- PyIlmBase/PyImath/PyImathFixedVArray.cpp | 12 +++--- PyIlmBase/PyImath/PyImathFixedVArray.h | 4 +- PyIlmBase/PyImath/PyImathStringArray.cpp | 6 +-- PyIlmBase/PyImath/imathmodule.cpp | 4 +- 19 files changed, 63 insertions(+), 103 deletions(-) diff --git a/IlmBase/Imath/ImathFun.cpp b/IlmBase/Imath/ImathFun.cpp index 65cf6202..0fe9f041 100644 --- a/IlmBase/Imath/ImathFun.cpp +++ b/IlmBase/Imath/ImathFun.cpp @@ -41,7 +41,7 @@ IMATH_INTERNAL_NAMESPACE_SOURCE_ENTER float succf (float f) { - union {float f; int i;} u; + union {float f; unsigned int i;} u; u.f = f; if ((u.i & 0x7f800000) == 0x7f800000) @@ -76,7 +76,7 @@ succf (float f) float predf (float f) { - union {float f; int i;} u; + union {float f; unsigned int i;} u; u.f = f; if ((u.i & 0x7f800000) == 0x7f800000) diff --git a/IlmBase/Imath/ImathMatrixAlgo.cpp b/IlmBase/Imath/ImathMatrixAlgo.cpp index 0cafd5c0..3f639687 100644 --- a/IlmBase/Imath/ImathMatrixAlgo.cpp +++ b/IlmBase/Imath/ImathMatrixAlgo.cpp @@ -115,7 +115,7 @@ procrustesRotationAndTranslation (const Vec3* A, const Vec3* B, const T* w if (weights == 0) { - for (int i = 0; i < numPoints; ++i) + for (size_t i = 0; i < numPoints; ++i) { Acenter += (V3d) A[i]; Bcenter += (V3d) B[i]; @@ -124,7 +124,7 @@ procrustesRotationAndTranslation (const Vec3* A, const Vec3* B, const T* w } else { - for (int i = 0; i < numPoints; ++i) + for (size_t i = 0; i < numPoints; ++i) { const double w = weights[i]; weightsSum += w; @@ -152,12 +152,12 @@ procrustesRotationAndTranslation (const Vec3* A, const Vec3* B, const T* w M33d C (0.0); if (weights == 0) { - for (int i = 0; i < numPoints; ++i) + for (size_t i = 0; i < numPoints; ++i) C += outerProduct ((V3d) B[i] - Bcenter, (V3d) A[i] - Acenter); } else { - for (int i = 0; i < numPoints; ++i) + for (size_t i = 0; i < numPoints; ++i) { const double w = weights[i]; C += outerProduct (w * ((V3d) B[i] - Bcenter), (V3d) A[i] - Acenter); @@ -197,12 +197,12 @@ procrustesRotationAndTranslation (const Vec3* A, const Vec3* B, const T* w KahanSum traceATA; if (weights == 0) { - for (int i = 0; i < numPoints; ++i) + for (size_t i = 0; i < numPoints; ++i) traceATA += ((V3d) A[i] - Acenter).length2(); } else { - for (int i = 0; i < numPoints; ++i) + for (size_t i = 0; i < numPoints; ++i) traceATA += ((double) weights[i]) * ((V3d) A[i] - Acenter).length2(); } diff --git a/IlmBase/ImathTest/testBoxAlgo.cpp b/IlmBase/ImathTest/testBoxAlgo.cpp index 9be1b7c2..9eceba35 100644 --- a/IlmBase/ImathTest/testBoxAlgo.cpp +++ b/IlmBase/ImathTest/testBoxAlgo.cpp @@ -356,7 +356,7 @@ entryAndExitPoints1 () Box3f () }; - for (int i = 0; i < sizeof (boxes) / sizeof (boxes[0]); ++i) + for (size_t i = 0; i < sizeof (boxes) / sizeof (boxes[0]); ++i) testEntryAndExitPoints (boxes[i]); } @@ -738,7 +738,7 @@ rayBoxIntersection1 () Box3f () }; - for (int i = 0; i < sizeof (boxes) / sizeof (boxes[0]); ++i) + for (size_t i = 0; i < sizeof (boxes) / sizeof (boxes[0]); ++i) testRayBoxIntersection (boxes[i]); } @@ -910,44 +910,6 @@ boxMatrixTransform () } -void -pointInBox () -{ - cout << " closest point in box" << endl; - - Box3f box (V3f (1, 2, 3), V3f (5, 4, 6)); - - // - // Points outside the box - // - - assert (closestPointInBox (V3f (0, 0, 0), box) == V3f (1, 2, 3)); - assert (closestPointInBox (V3f (7, 7, 7), box) == V3f (5, 4, 6)); - - assert (closestPointInBox (V3f (2, 3, 0), box) == V3f (2, 3, 3)); - assert (closestPointInBox (V3f (2, 3, 7), box) == V3f (2, 3, 6)); - - assert (closestPointInBox (V3f (2, 0, 4), box) == V3f (2, 2, 4)); - assert (closestPointInBox (V3f (2, 7, 4), box) == V3f (2, 4, 4)); - - assert (closestPointInBox (V3f (0, 3, 4), box) == V3f (1, 3, 4)); - assert (closestPointInBox (V3f (7, 3, 4), box) == V3f (5, 3, 4)); - - // - // Points inside the box - // - - assert (closestPointInBox (V3f (1.5, 3, 5), box) == V3f (1.5, 3, 5)); - assert (closestPointInBox (V3f (4.5, 3, 5), box) == V3f (4.5, 3, 5)); - - assert (closestPointInBox (V3f (2, 2.5, 4), box) == V3f (2, 2.5, 4)); - assert (closestPointInBox (V3f (2, 3.5, 4), box) == V3f (2, 3.5, 4)); - - assert (closestPointInBox (V3f (2, 3, 3.5), box) == V3f (2, 3, 3.5)); - assert (closestPointInBox (V3f (2, 3, 5.5), box) == V3f (2, 3, 5.5)); -} - - void pointInAndOnBox () { diff --git a/IlmBase/ImathTest/testExtractEuler.cpp b/IlmBase/ImathTest/testExtractEuler.cpp index 1a8e9205..311c01e3 100644 --- a/IlmBase/ImathTest/testExtractEuler.cpp +++ b/IlmBase/ImathTest/testExtractEuler.cpp @@ -48,7 +48,6 @@ using namespace IMATH_INTERNAL_NAMESPACE; namespace { float rad (float deg) {return deg * (M_PI / 180);} -float deg (float rad) {return rad * (180 / M_PI);} M44f diff --git a/IlmBase/ImathTest/testExtractSHRT.cpp b/IlmBase/ImathTest/testExtractSHRT.cpp index 97401a26..6661f6f0 100644 --- a/IlmBase/ImathTest/testExtractSHRT.cpp +++ b/IlmBase/ImathTest/testExtractSHRT.cpp @@ -57,7 +57,6 @@ using namespace IMATH_INTERNAL_NAMESPACE; namespace { float rad (float deg) {return deg * (M_PI / 180);} -float deg (float rad) {return rad * (180 / M_PI);} void diff --git a/IlmBase/ImathTest/testJacobiEigenSolver.cpp b/IlmBase/ImathTest/testJacobiEigenSolver.cpp index 93eb29e0..e2e5f140 100644 --- a/IlmBase/ImathTest/testJacobiEigenSolver.cpp +++ b/IlmBase/ImathTest/testJacobiEigenSolver.cpp @@ -85,8 +85,8 @@ void verifyOrthonormal (const TM& A, const typename TM::BaseType threshold) { const TM prod = A * A.transposed(); - for (int i = 0; i < TM::dimensions(); ++i) - for (int j = 0; j < TM::dimensions(); ++j) + for (size_t i = 0; i < TM::dimensions(); ++i) + for (size_t j = 0; j < TM::dimensions(); ++j) if (i == j) assert (std::abs (prod[i][j] - 1) < threshold); else @@ -100,8 +100,8 @@ computeThreshold(const TM& A) typedef typename TM::BaseType T; T maxAbsEntry(0); - for (int i = 0; i < TM::dimensions(); ++i) - for (int j = 0; j < TM::dimensions(); ++j) + for (size_t i = 0; i < TM::dimensions(); ++i) + for (size_t j = 0; j < TM::dimensions(); ++j) maxAbsEntry = std::max (maxAbsEntry, std::abs(A[i][j])); const T eps = std::numeric_limits::epsilon(); @@ -135,8 +135,8 @@ testJacobiEigenSolver(const TM& A) // Determinant of A and S TM MS; - for (int i = 0; i < TM::dimensions(); ++i) - for (int j = 0; j < TM::dimensions(); ++j) + for (size_t i = 0; i < TM::dimensions(); ++i) + for (size_t j = 0; j < TM::dimensions(); ++j) if(i == j) MS[i][j] = S[i]; else @@ -148,8 +148,8 @@ testJacobiEigenSolver(const TM& A) // A = V * S * V^T TM MA = V * MS * V.transposed(); - for (int i = 0; i < TM::dimensions(); ++i) - for (int j =0; j < TM::dimensions(); ++j) + for (size_t i = 0; i < TM::dimensions(); ++i) + for (size_t j =0; j < TM::dimensions(); ++j) assert(abs(A[i][j]-MA[i][j]) < threshold); } diff --git a/IlmBase/ImathTest/testLineAlgo.cpp b/IlmBase/ImathTest/testLineAlgo.cpp index ad79c587..21a642c0 100644 --- a/IlmBase/ImathTest/testLineAlgo.cpp +++ b/IlmBase/ImathTest/testLineAlgo.cpp @@ -399,7 +399,6 @@ testIntersect () V3f p1 = v0 * b.x + v1 * b.y + v2 * b.z; V3f p0; - int j = 0; do { diff --git a/IlmBase/ImathTest/testProcrustes.cpp b/IlmBase/ImathTest/testProcrustes.cpp index 71cfe10b..7e86d41c 100644 --- a/IlmBase/ImathTest/testProcrustes.cpp +++ b/IlmBase/ImathTest/testProcrustes.cpp @@ -151,8 +151,6 @@ void verifyProcrustes (const std::vector >& from, const std::vector >& to) { - typedef IMATH_INTERNAL_NAMESPACE::Vec3 V3; - const T eps = std::sqrt(std::numeric_limits::epsilon()); const size_t n = from.size(); @@ -242,7 +240,7 @@ verifyProcrustes (const std::vector >& from, IMATH_INTERNAL_NAMESPACE::V3d netForce(0); IMATH_INTERNAL_NAMESPACE::V3d netTorque(0); - for (int iPoint = 0; iPoint < n; ++iPoint) + for (size_t iPoint = 0; iPoint < n; ++iPoint) { const IMATH_INTERNAL_NAMESPACE::V3d force = weights[iPoint] * (from[iPoint]*m - to[iPoint]); netForce += force; diff --git a/IlmBase/ImathTest/testShear.cpp b/IlmBase/ImathTest/testShear.cpp index 17832b1f..7783f7d4 100644 --- a/IlmBase/ImathTest/testShear.cpp +++ b/IlmBase/ImathTest/testShear.cpp @@ -54,7 +54,6 @@ testShear () const float epsilon = IMATH_INTERNAL_NAMESPACE::limits< float >::epsilon(); - float array[6] = { 1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F }; IMATH_INTERNAL_NAMESPACE::Shear6f testConstructor1; IMATH_INTERNAL_NAMESPACE::Shear6f testConstructor2( testConstructor1 ); diff --git a/PyIlmBase/PyImath/PyImathAutovectorize.h b/PyIlmBase/PyImath/PyImathAutovectorize.h index e9df0b62..f9e9542e 100644 --- a/PyIlmBase/PyImath/PyImathAutovectorize.h +++ b/PyIlmBase/PyImath/PyImathAutovectorize.h @@ -738,7 +738,7 @@ struct VectorizedVoidMaskableMemberFunction1 { size_t len = cls.match_dimension(arg1, false); op_precompute::apply(len); - if (cls.isMaskedReference() && arg1.len() == cls.unmaskedLength()) + if (cls.isMaskedReference() && (size_t) arg1.len() == cls.unmaskedLength()) { // class is masked, and the unmasked length matches the right hand side VectorizedMaskedVoidOperation1 vop(cls,arg1); diff --git a/PyIlmBase/PyImath/PyImathBox.cpp b/PyIlmBase/PyImath/PyImathBox.cpp index baea0e8d..910f7438 100644 --- a/PyIlmBase/PyImath/PyImathBox.cpp +++ b/PyIlmBase/PyImath/PyImathBox.cpp @@ -316,7 +316,7 @@ box_extendBy(IMATH_NAMESPACE::Box &box, const PyImath::FixedArray &points) std::vector > boxes(numBoxes); ExtendByTask task(boxes,points); dispatchTask(task,points.len()); - for (int i=0; i > &va, Py_ssize_t index, const t Box v; v.min = extract(t[0]); v.max = extract(t[1]); - va[va.canonical_index(index)] = v; + va[(size_t)va.canonical_index(index)] = v; } else THROW(IEX_NAMESPACE::LogicExc, "tuple of length 2 expected"); diff --git a/PyIlmBase/PyImath/PyImathEuler.cpp b/PyIlmBase/PyImath/PyImathEuler.cpp index b18cae32..18e44cc0 100644 --- a/PyIlmBase/PyImath/PyImathEuler.cpp +++ b/PyIlmBase/PyImath/PyImathEuler.cpp @@ -113,6 +113,8 @@ static std::string nameOfOrder(typename IMATH_NAMESPACE::Euler::Order order) return "EULER_ZYZr"; case IMATH_NAMESPACE::Euler::ZXZr: return "EULER_ZXZr"; + default: + break; } return ""; @@ -306,6 +308,8 @@ static typename Euler::Order interpretOrder(typename IMATH_NAMESPACE::Eulerf: { o = Euler::ZXZr; }break; + default: + break; } return o; diff --git a/PyIlmBase/PyImath/PyImathFixedArray.h b/PyIlmBase/PyImath/PyImathFixedArray.h index 6a9d034a..819d7273 100644 --- a/PyIlmBase/PyImath/PyImathFixedArray.h +++ b/PyIlmBase/PyImath/PyImathFixedArray.h @@ -116,7 +116,7 @@ class FixedArray } boost::shared_array a(new T[length]); T tmp = FixedArrayDefaultValue::value(); - for (size_t i=0; i a(new T[length]); - for (size_t i=0; i= _length || index < 0) { + if (index < 0) index += len(); + if (index >= len() || index < 0) { PyErr_SetString(PyExc_IndexError, "Index out of range"); boost::python::throw_error_already_set(); } @@ -345,7 +345,7 @@ class FixedArray extract_slice_indices(index,start,end,step,slicelength); // we have a valid range of indices - if (data.len() != slicelength) { + if ((size_t)data.len() != slicelength) { PyErr_SetString(PyExc_IndexError, "Dimensions of source do not match destination"); boost::python::throw_error_already_set(); } @@ -374,7 +374,7 @@ class FixedArray } size_t len = match_dimension(mask); - if (data.len() == len) + if ((size_t)data.len() == len) { for (size_t i = 0; i < len; ++i) if (mask[i]) _ptr[i*_stride] = data[i]; @@ -385,7 +385,7 @@ class FixedArray for (size_t i = 0; i < len; ++i) if (mask[i]) count++; - if (data.len() != count) { + if ((size_t)data.len() != count) { throw IEX_NAMESPACE::ArgExc("Dimensions of source data do not match destination either masked or unmasked"); } @@ -493,7 +493,7 @@ class FixedArray throwExc = true; else if (_indices) { - if (_unmaskedLength != a1.len()) + if (_unmaskedLength != (size_t) a1.len()) throwExc = true; } else diff --git a/PyIlmBase/PyImath/PyImathFixedArray2D.h b/PyIlmBase/PyImath/PyImathFixedArray2D.h index 8c628f16..19969e3b 100644 --- a/PyIlmBase/PyImath/PyImathFixedArray2D.h +++ b/PyIlmBase/PyImath/PyImathFixedArray2D.h @@ -183,7 +183,7 @@ class FixedArray2D size_t canonical_index(Py_ssize_t index, size_t length) const { if (index < 0) index += length; - if (index >= length || index < 0) { + if ((size_t) index >= length || index < 0) { PyErr_SetString(PyExc_IndexError, "Index out of range"); boost::python::throw_error_already_set(); } @@ -355,7 +355,7 @@ class FixedArray2D setitem_array1d_mask(const FixedArray2D &mask, const FixedArray &data) { IMATH_NAMESPACE::Vec2 len = match_dimension(mask); - if (data.len() == len.x*len.y) { + if ((size_t) data.len() == len.x*len.y) { for (size_t j = 0, z = 0; j < len.y; j++) for (size_t i=0; i apply_array2d_unary_op(const FixedArray2D &a1) { IMATH_NAMESPACE::Vec2 len = a1.len(); FixedArray2D retval(len.x,len.y); - for (int j=0; j::apply(a1(i,j)); } } @@ -503,8 +503,8 @@ FixedArray2D apply_array2d_array2d_binary_op(const FixedArray2D &a1, co { IMATH_NAMESPACE::Vec2 len = a1.match_dimension(a2); FixedArray2D retval(len.x,len.y); - for (int j=0; j::apply(a1(i,j),a2(i,j)); } } @@ -516,8 +516,8 @@ FixedArray2D apply_array2d_scalar_binary_op(const FixedArray2D &a1, con { IMATH_NAMESPACE::Vec2 len = a1.len(); FixedArray2D retval(len.x,len.y); - for (int j=0; j::apply(a1(i,j),a2); } } @@ -529,8 +529,8 @@ FixedArray2D apply_array2d_scalar_binary_rop(const FixedArray2D &a1, co { IMATH_NAMESPACE::Vec2 len = a1.len(); FixedArray2D retval(len.x,len.y); - for (int j=0; j::apply(a2,a1(i,j)); } } @@ -542,8 +542,8 @@ template