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 ce886b8 commit c8a7f6a
Show file tree
Hide file tree
Showing 27 changed files with 79 additions and 167 deletions.
4 changes: 2 additions & 2 deletions IlmBase/IlmThread/IlmThreadPool.cpp
Expand Up @@ -156,8 +156,8 @@ struct ThreadPool::Data
ThreadPoolProvider *provider;
ThreadPoolProvider *oldprovider;
#else
std::atomic<ThreadPoolProvider *> provider;
std::atomic<int> provUsers;
std::atomic<ThreadPoolProvider *> provider;
#endif
};

Expand Down Expand Up @@ -459,7 +459,7 @@ class NullThreadPoolProvider : public ThreadPoolProvider
// struct TaskGroup::Data
//

TaskGroup::Data::Data (): isEmpty (1), numPending (0)
TaskGroup::Data::Data () : numPending (0), isEmpty (1)
{
// empty
}
Expand Down
4 changes: 2 additions & 2 deletions IlmBase/Imath/ImathFun.cpp
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
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
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
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
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
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
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
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
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
55 changes: 1 addition & 54 deletions OpenEXR/IlmImf/ImfDeepTiledInputFile.cpp
Expand Up @@ -458,59 +458,6 @@ readTileData (InputStreamMutex *streamData,
}


void
readNextTileData (InputStreamMutex *streamData,
DeepTiledInputFile::Data *ifd,
int &dx, int &dy,
int &lx, int &ly,
char * & buffer,
Int64 &dataSize,
Int64 &unpackedDataSize)
{
//
// Read the next tile block from the file
//

//
// Read the first few bytes of the tile (the header).
//

Xdr::read <StreamIO> (*streamData->is, dx);
Xdr::read <StreamIO> (*streamData->is, dy);
Xdr::read <StreamIO> (*streamData->is, lx);
Xdr::read <StreamIO> (*streamData->is, ly);

Int64 tableSize;
Xdr::read <StreamIO> (*streamData->is, tableSize);

Xdr::read <StreamIO> (*streamData->is, dataSize);
Xdr::read <StreamIO> (*streamData->is, unpackedDataSize);

//
// Skip the pixel sample count table because we have read this data.
//

Xdr::skip <StreamIO> (*streamData->is, tableSize);

//
// Read the pixel data.
//

streamData->is->read (buffer, dataSize);

//
// Keep track of which tile is the next one in
// the file, so that we can avoid redundant seekg()
// operations (seekg() can be fairly expensive).
//

streamData->currentPosition += 4 * Xdr::size<int>() +
3 * Xdr::size<Int64>() +
tableSize +
dataSize;
}


//
// A TileBufferTask encapsulates the task of uncompressing
// a single tile and copying it into the frame buffer.
Expand Down Expand Up @@ -1957,7 +1904,7 @@ DeepTiledInputFile::totalTiles() const
for (int i_lx = 0; i_lx < numXLevels (); ++i_lx)
numAllTiles += numXTiles (i_lx) * numYTiles (i_ly);

break;
break;

default:

Expand Down
2 changes: 0 additions & 2 deletions OpenEXR/IlmImf/ImfDeepTiledOutputFile.cpp
Expand Up @@ -1465,13 +1465,11 @@ DeepTiledOutputFile::writeTiles (int dx1, int dx2, int dy1, int dy2,
swap (dy1, dy2);

int dyStart = dy1;
int dyStop = dy2 + 1;
int dY = 1;

if (_data->lineOrder == DECREASING_Y)
{
dyStart = dy2;
dyStop = dy1 - 1;
dY = -1;
}

Expand Down
4 changes: 2 additions & 2 deletions OpenEXR/IlmImf/ImfDwaCompressorSimd.h
Expand Up @@ -87,7 +87,7 @@ class SimdAlignedBuffer64
alloc();
}

SimdAlignedBuffer64(const SimdAlignedBuffer64 &rhs): _handle(0)
SimdAlignedBuffer64(const SimdAlignedBuffer64 &rhs): _buffer (0), _handle(0)
{
alloc();
memcpy (_buffer, rhs._buffer, 64 * sizeof (T));
Expand All @@ -101,7 +101,7 @@ class SimdAlignedBuffer64

#if __cplusplus >= 201103L
SimdAlignedBuffer64(SimdAlignedBuffer64 &&rhs) noexcept
: _handle(rhs._handle), _buffer(rhs._buffer)
: _buffer(rhs._buffer), _handle(rhs._handle)
{
rhs._handle = nullptr;
rhs._buffer = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion OpenEXR/IlmImf/ImfRgbaFile.cpp
Expand Up @@ -167,9 +167,10 @@ cachePadding (ptrdiff_t size)
// we are running on. (It is ok if CACHE_LINE_SIZE is larger
// than a real cache line.)
//
// CACHE_LINE_SIZE = (1 << LOG2_CACHE_LINE_SIZE)
//

static int LOG2_CACHE_LINE_SIZE = 8;
static const ptrdiff_t CACHE_LINE_SIZE = (1 << LOG2_CACHE_LINE_SIZE);

int i = LOG2_CACHE_LINE_SIZE + 2;

Expand Down
8 changes: 8 additions & 0 deletions OpenEXR/IlmImf/ImfScanLineInputFile.cpp
Expand Up @@ -1418,6 +1418,10 @@ ScanLineInputFile::setFrameBuffer (const FrameBuffer &frameBuffer)
case OPENEXR_IMF_INTERNAL_NAMESPACE::UINT :
offset+=2;
break;
case OPENEXR_IMF_INTERNAL_NAMESPACE::NUM_PIXELTYPES:
default:
// not possible.
break;
}
++i;
}
Expand Down Expand Up @@ -1488,6 +1492,10 @@ ScanLineInputFile::setFrameBuffer (const FrameBuffer &frameBuffer)
case OPENEXR_IMF_INTERNAL_NAMESPACE::UINT :
offset+=2;
break;
case OPENEXR_IMF_INTERNAL_NAMESPACE::NUM_PIXELTYPES:
default:
// not possible.
break;
}
}

Expand Down
2 changes: 0 additions & 2 deletions OpenEXR/IlmImf/ImfTiledOutputFile.cpp
Expand Up @@ -1230,13 +1230,11 @@ TiledOutputFile::writeTiles (int dx1, int dx2, int dy1, int dy2,
swap (dy1, dy2);

int dyStart = dy1;
int dyStop = dy2 + 1;
int dY = 1;

if (_data->lineOrder == DECREASING_Y)
{
dyStart = dy2;
dyStop = dy1 - 1;
dY = -1;
}

Expand Down
2 changes: 1 addition & 1 deletion PyIlmBase/PyIex/PyIexTypeTranslator.h
Expand Up @@ -306,7 +306,7 @@ TypeTranslator<BaseClass>::ClassDesc::ClassDesc
template <class BaseClass>
TypeTranslator<BaseClass>::ClassDesc::~ClassDesc ()
{
for (int i = 0; i < _derivedClasses.size(); ++i)
for (size_t i = 0; i < _derivedClasses.size(); ++i)
delete _derivedClasses[i];
}

Expand Down

0 comments on commit c8a7f6a

Please sign in to comment.