Skip to content

Commit c200162

Browse files
codeql/cpp/integer-multiplication-cast-to-long (#175)
* fix codeql/cpp/integer-multiplication-cast-to-long issues
1 parent 6cab16b commit c200162

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

OpenEXR_CTL/exr_ctl_exr/exrCtlExr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ exrCtlExr (const char inFileName[],
139139
{
140140
const Rgba *inPtr = &inPixels[0][0];
141141
Rgba *outPtr = &outPixels[0][0];
142-
size_t numPixels = w * h;
142+
size_t numPixels = static_cast<size_t>(w) * h;
143143

144144
for (size_t i = 0; i < numPixels; ++i)
145145
(outPtr++)->a = (inPtr++)->a;

OpenEXR_CTL/exrdpx/exrToDpx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ writeHeader
105105
setU32 (sizeof (header), header.fileInfo.offsetToImageData, BO_BIG);
106106
strcpy (header.fileInfo.versionNumber, "V2.0");
107107

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

ctlrender/tiff_file.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void tiff_read_failsafe(TIFF *t, float scale, ctl::dpx::fb<float> *pixels) {
486486
TIFFGetFieldDefaulted(t, TIFFTAG_IMAGELENGTH, &h);
487487
pixels->init(w, h, 4);
488488

489-
temp_buffer=(uint8_t *)alloca(w*h*4);
489+
temp_buffer=(uint8_t *)alloca((uint64_t)w*h*4);
490490
TIFFReadRGBAImage(t, w, h, (uint32_t *)temp_buffer, 0);
491491

492492
for(i=0; i<h; i++) {

lib/IlmImfCtl/ImfCtlApplyTransforms.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ applyTransforms
487487
// Determine how many samples we will process.
488488
//
489489

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

493493
if (totalSamples <= 0)
494494
return;

lib/dpx/dpx.tcc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void dpx::fb<T>::init(uint32_t width, uint32_t height, uint32_t depth) {
8080

8181
delete [] _data;
8282

83-
_length=_width*_height*_depth*sizeof(T);
83+
_length=static_cast<uint64_t>(_width)*_height*_depth*sizeof(T);
8484

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

108108
template <class T>
109109
uint64_t dpx::fb<T>::count(void) const {
110-
return _width*_height*_depth;
110+
return static_cast<uint64_t>(_width)*static_cast<uint64_t>(_height)*static_cast<uint64_t>(_depth);
111111
}
112112

113113
template <class T>
114114
uint64_t dpx::fb<T>::pixels(void) const {
115-
return _width*_height;
115+
return static_cast<uint64_t>(_width)*_height;
116116
}
117117

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

144-
count=width()*height();
144+
count=static_cast<uint64_t>(width())*height();
145145

146146
i=_data;
147147
o=_data;

lib/dpx/dpx_read.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void unpack(dpx::fb<O> *out, const I *i, const rwinfo &ri) {
135135
// XXX not supported
136136
}
137137

138-
count=out->width()*out->depth();
138+
count= static_cast<uint64_t>(out->width())*out->depth();
139139
for(u=0; u<out->height(); u++) {
140140
onbit=0;
141141
for(v=0; v<count; v++) {

unittest/IlmCtlMath/testGaussRec.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ runTestGaussian(int numSamples, int numTests)
8282
p[s][0][1] = (float) rand() / (float) RAND_MAX;
8383
p[s][0][2] = (float) rand() / (float) RAND_MAX;
8484

85-
p[s][1][0] = exp( -p[s][0][0]*p[s][0][0] * var);
86-
p[s][1][1] = exp( -p[s][0][1]*p[s][0][1] * var);
87-
p[s][1][2] = exp( -p[s][0][2]*p[s][0][2] * var);
85+
p[s][1][0] = exp( -static_cast<double>(p[s][0][0])*static_cast<double>(p[s][0][0]) * var);
86+
p[s][1][1] = exp( -static_cast<double>(p[s][0][1])*static_cast<double>(p[s][0][1]) * var);
87+
p[s][1][2] = exp( -static_cast<double>(p[s][0][2])*static_cast<double>(p[s][0][2]) * var);
8888
}
8989

9090
Ctl::RbfInterpolator rbfItp(numSamples, p);

0 commit comments

Comments
 (0)