Skip to content

Commit

Permalink
Various fixes to address compiler warnings:
Browse files Browse the repository at this point in the history
- 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 <cary@ilm.com>
  • Loading branch information
cary-ilm authored and kdt3rd committed Jul 1, 2019
1 parent 6ea36de commit cca4472
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 103 deletions.
4 changes: 2 additions & 2 deletions IlmBase/Imath/ImathFun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions IlmBase/Imath/ImathMatrixAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ procrustesRotationAndTranslation (const Vec3<T>* A, const Vec3<T>* 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];
Expand All @@ -124,7 +124,7 @@ procrustesRotationAndTranslation (const Vec3<T>* A, const Vec3<T>* 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;
Expand Down Expand Up @@ -152,12 +152,12 @@ procrustesRotationAndTranslation (const Vec3<T>* A, const Vec3<T>* 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);
Expand Down Expand Up @@ -197,12 +197,12 @@ procrustesRotationAndTranslation (const Vec3<T>* A, const Vec3<T>* 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();
}

Expand Down
42 changes: 2 additions & 40 deletions IlmBase/ImathTest/testBoxAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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 ()
{
Expand Down
1 change: 0 additions & 1 deletion IlmBase/ImathTest/testExtractEuler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion IlmBase/ImathTest/testExtractSHRT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions IlmBase/ImathTest/testJacobiEigenSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<T>::epsilon();
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion IlmBase/ImathTest/testLineAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ testIntersect ()
V3f p1 = v0 * b.x + v1 * b.y + v2 * b.z;

V3f p0;
int j = 0;

do
{
Expand Down
4 changes: 1 addition & 3 deletions IlmBase/ImathTest/testProcrustes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ void
verifyProcrustes (const std::vector<IMATH_INTERNAL_NAMESPACE::Vec3<T> >& from,
const std::vector<IMATH_INTERNAL_NAMESPACE::Vec3<T> >& to)
{
typedef IMATH_INTERNAL_NAMESPACE::Vec3<T> V3;

const T eps = std::sqrt(std::numeric_limits<T>::epsilon());

const size_t n = from.size();
Expand Down Expand Up @@ -242,7 +240,7 @@ verifyProcrustes (const std::vector<IMATH_INTERNAL_NAMESPACE::Vec3<T> >& 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;
Expand Down
1 change: 0 additions & 1 deletion IlmBase/ImathTest/testShear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion PyIlmBase/PyImath/PyImathAutovectorize.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ struct VectorizedVoidMaskableMemberFunction1 {
size_t len = cls.match_dimension(arg1, false);
op_precompute<Op>::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<Op,class_type,arg1_type> vop(cls,arg1);
Expand Down
2 changes: 1 addition & 1 deletion PyIlmBase/PyImath/PyImathBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ box_extendBy(IMATH_NAMESPACE::Box<T> &box, const PyImath::FixedArray<T> &points)
std::vector<IMATH_NAMESPACE::Box<T> > boxes(numBoxes);
ExtendByTask<T> task(boxes,points);
dispatchTask(task,points.len());
for (int i=0; i<numBoxes; ++i) {
for (size_t i=0; i<numBoxes; ++i) {
box.extendBy(boxes[i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion PyIlmBase/PyImath/PyImathBoxArrayImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ setItemTuple(FixedArray<IMATH_NAMESPACE::Box<T> > &va, Py_ssize_t index, const t
Box<T> v;
v.min = extract<T>(t[0]);
v.max = extract<T>(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");
Expand Down
4 changes: 4 additions & 0 deletions PyIlmBase/PyImath/PyImathEuler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ static std::string nameOfOrder(typename IMATH_NAMESPACE::Euler<T>::Order order)
return "EULER_ZYZr";
case IMATH_NAMESPACE::Euler<T>::ZXZr:
return "EULER_ZXZr";
default:
break;
}

return "";
Expand Down Expand Up @@ -306,6 +308,8 @@ static typename Euler<T>::Order interpretOrder(typename IMATH_NAMESPACE::Eulerf:
{
o = Euler<T>::ZXZr;
}break;
default:
break;
}

return o;
Expand Down
16 changes: 8 additions & 8 deletions PyIlmBase/PyImath/PyImathFixedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class FixedArray
}
boost::shared_array<T> a(new T[length]);
T tmp = FixedArrayDefaultValue<T>::value();
for (size_t i=0; i<length; ++i) a[i] = tmp;
for (Py_ssize_t i=0; i<length; ++i) a[i] = tmp;
_handle = a;
_ptr = a.get();
}
Expand All @@ -139,7 +139,7 @@ class FixedArray
throw IEX_NAMESPACE::LogicExc("Fixed array length must be non-negative");
}
boost::shared_array<T> a(new T[length]);
for (size_t i=0; i<length; ++i) a[i] = initialValue;
for (Py_ssize_t i=0; i<length; ++i) a[i] = initialValue;
_handle = a;
_ptr = a.get();
}
Expand Down Expand Up @@ -229,8 +229,8 @@ class FixedArray
//
size_t canonical_index(Py_ssize_t index) const
{
if (index < 0) index += _length;
if (index >= _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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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];
Expand All @@ -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");
}

Expand Down Expand Up @@ -493,7 +493,7 @@ class FixedArray
throwExc = true;
else if (_indices)
{
if (_unmaskedLength != a1.len())
if (_unmaskedLength != (size_t) a1.len())
throwExc = true;
}
else
Expand Down

0 comments on commit cca4472

Please sign in to comment.