Skip to content

Commit

Permalink
codeql/cpp/integer-multiplication-cast-to-long (#175)
Browse files Browse the repository at this point in the history
* fix codeql/cpp/integer-multiplication-cast-to-long issues
  • Loading branch information
michaeldsmith authored Jan 26, 2025
1 parent 6cab16b commit c200162
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion OpenEXR_CTL/exr_ctl_exr/exrCtlExr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ exrCtlExr (const char inFileName[],
{
const Rgba *inPtr = &inPixels[0][0];
Rgba *outPtr = &outPixels[0][0];
size_t numPixels = w * h;
size_t numPixels = static_cast<size_t>(w) * h;

for (size_t i = 0; i < numPixels; ++i)
(outPtr++)->a = (inPtr++)->a;
Expand Down
2 changes: 1 addition & 1 deletion OpenEXR_CTL/exrdpx/exrToDpx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ writeHeader
setU32 (sizeof (header), header.fileInfo.offsetToImageData, BO_BIG);
strcpy (header.fileInfo.versionNumber, "V2.0");

setU32 (sizeof (header) + 4 * width * height,
setU32 (sizeof (header) + 4 * static_cast<unsigned long>(width) * height,
header.fileInfo.fileSize,
BO_BIG);

Expand Down
2 changes: 1 addition & 1 deletion ctlrender/tiff_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void tiff_read_failsafe(TIFF *t, float scale, ctl::dpx::fb<float> *pixels) {
TIFFGetFieldDefaulted(t, TIFFTAG_IMAGELENGTH, &h);
pixels->init(w, h, 4);

temp_buffer=(uint8_t *)alloca(w*h*4);
temp_buffer=(uint8_t *)alloca((uint64_t)w*h*4);
TIFFReadRGBAImage(t, w, h, (uint32_t *)temp_buffer, 0);

for(i=0; i<h; i++) {
Expand Down
4 changes: 2 additions & 2 deletions lib/IlmImfCtl/ImfCtlApplyTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ applyTransforms
// Determine how many samples we will process.
//

size_t totalSamples = (transformWindow.max.x - transformWindow.min.x + 1) *
(transformWindow.max.y - transformWindow.min.y + 1);
size_t totalSamples = static_cast<size_t>(transformWindow.max.x - transformWindow.min.x + 1) *
static_cast<size_t>(transformWindow.max.y - transformWindow.min.y + 1);

if (totalSamples <= 0)
return;
Expand Down
8 changes: 4 additions & 4 deletions lib/dpx/dpx.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void dpx::fb<T>::init(uint32_t width, uint32_t height, uint32_t depth) {

delete [] _data;

_length=_width*_height*_depth*sizeof(T);
_length=static_cast<uint64_t>(_width)*_height*_depth*sizeof(T);

_data=new T[width*height*depth];
}
Expand All @@ -107,12 +107,12 @@ uint64_t dpx::fb<T>::length(void) const {

template <class T>
uint64_t dpx::fb<T>::count(void) const {
return _width*_height*_depth;
return static_cast<uint64_t>(_width)*static_cast<uint64_t>(_height)*static_cast<uint64_t>(_depth);
}

template <class T>
uint64_t dpx::fb<T>::pixels(void) const {
return _width*_height;
return static_cast<uint64_t>(_width)*_height;
}

template <class T>
Expand Down Expand Up @@ -141,7 +141,7 @@ void dpx::fb<T>::swizzle(uint8_t descriptor, bool squish_alpha) {
T *i, *o;
T t;

count=width()*height();
count=static_cast<uint64_t>(width())*height();

i=_data;
o=_data;
Expand Down
2 changes: 1 addition & 1 deletion lib/dpx/dpx_read.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void unpack(dpx::fb<O> *out, const I *i, const rwinfo &ri) {
// XXX not supported
}

count=out->width()*out->depth();
count= static_cast<uint64_t>(out->width())*out->depth();
for(u=0; u<out->height(); u++) {
onbit=0;
for(v=0; v<count; v++) {
Expand Down
6 changes: 3 additions & 3 deletions unittest/IlmCtlMath/testGaussRec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ runTestGaussian(int numSamples, int numTests)
p[s][0][1] = (float) rand() / (float) RAND_MAX;
p[s][0][2] = (float) rand() / (float) RAND_MAX;

p[s][1][0] = exp( -p[s][0][0]*p[s][0][0] * var);
p[s][1][1] = exp( -p[s][0][1]*p[s][0][1] * var);
p[s][1][2] = exp( -p[s][0][2]*p[s][0][2] * var);
p[s][1][0] = exp( -static_cast<double>(p[s][0][0])*static_cast<double>(p[s][0][0]) * var);
p[s][1][1] = exp( -static_cast<double>(p[s][0][1])*static_cast<double>(p[s][0][1]) * var);
p[s][1][2] = exp( -static_cast<double>(p[s][0][2])*static_cast<double>(p[s][0][2]) * var);
}

Ctl::RbfInterpolator rbfItp(numSamples, p);
Expand Down

0 comments on commit c200162

Please sign in to comment.