Skip to content

Commit 3b2cdd6

Browse files
committed
crnlib: fix CodeQL report cpp/*-multiplication-cast-to-*
1 parent 752222c commit 3b2cdd6

10 files changed

+22
-22
lines changed

crnlib/crn_clusterizer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class clusterizer {
5353
root.m_total_weight += weight;
5454
root.m_vectors.push_back(i);
5555

56-
ttsum += v.dot(v) * weight;
56+
ttsum += (double)v.dot(v) * (double)weight;
5757
}
5858

5959
root.m_variance = (float)(ttsum - (root.m_centroid.dot(root.m_centroid) / root.m_total_weight));
@@ -409,7 +409,7 @@ class clusterizer {
409409
double sum = 0;
410410

411411
for (uint j = 0; j < N; j++)
412-
sum += axis[j] * covar[i][j];
412+
sum += static_cast<double>(axis[j]) * static_cast<double>(covar[i][j]);
413413

414414
x[i] = static_cast<float>(sum);
415415

@@ -629,14 +629,14 @@ class clusterizer {
629629
new_left_child += (v * (float)weight);
630630
left_weight += weight;
631631

632-
left_ttsum += v.dot(v) * weight;
632+
left_ttsum += (double)v.dot(v) * (double)weight;
633633
} else {
634634
m_right_children.push_back(parent_node.m_vectors[i]);
635635

636636
new_right_child += (v * (float)weight);
637637
right_weight += weight;
638638

639-
right_ttsum += v.dot(v) * weight;
639+
right_ttsum += (double)v.dot(v) * (double)weight;
640640
}
641641
}
642642

crnlib/crn_dxt1.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ void dxt1_endpoint_optimizer::compute_pca(vec3F& axis, const vec3F_array& norm_c
151151
double cov[6] = {0, 0, 0, 0, 0, 0};
152152
for (uint i = 0; i < norm_colors.size(); i++) {
153153
const vec3F& v = norm_colors[i];
154-
float r = v[0];
155-
float g = v[1];
156-
float b = v[2];
154+
double r = (double)v[0];
155+
double g = (double)v[1];
156+
double b = (double)v[2];
157157
if (m_unique_colors[i].m_weight > 1) {
158158
const double weight = m_unique_colors[i].m_weight;
159159
cov[0] += r * r * weight;

crnlib/crn_dxt_fast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ static bool refine_endpoints(uint n, const color_quad_u8* pBlock, uint& low16, u
413413
for (uint i = 0; i < n; i++) {
414414
const color_quad_u8& p = pBlock[i];
415415

416-
int e = v[pSelectors[i]] - p[axis];
416+
uint64 e = v[pSelectors[i]] - p[axis];
417417

418418
axis_error += e * e;
419419

crnlib/crn_image_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,9 @@ bool resample_multithreaded(const image_u8& src, image_u8& dst, const resample_p
570570
return false;
571571

572572
p.m_pSrc_pixels = src_samples.get_ptr();
573-
p.m_src_pitch = src_width * resampler_comps * sizeof(float);
573+
p.m_src_pitch = (size_t)src_width * (size_t)resampler_comps * sizeof(float);
574574
p.m_pDst_pixels = dst_samples.get_ptr();
575-
p.m_dst_pitch = dst_width * resampler_comps * sizeof(float);
575+
p.m_dst_pitch = (size_t)dst_width * (size_t)resampler_comps * sizeof(float);
576576

577577
for (uint src_y = 0; src_y < src_height; src_y++) {
578578
const color_quad_u8* pSrc = src.get_scanline(src_y);

crnlib/crn_jpgd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ jpeg_decoder::coeff_buf* jpeg_decoder::coeff_buf_open(int block_num_x, int block
24312431
cb->block_len_x = block_len_x;
24322432
cb->block_len_y = block_len_y;
24332433
cb->block_size = (block_len_x * block_len_y) * sizeof(jpgd_block_t);
2434-
cb->pData = (uint8*)alloc(cb->block_size * block_num_x * block_num_y, true);
2434+
cb->pData = (uint8*)alloc((size_t)cb->block_size * (size_t)block_num_x * (size_t)block_num_y, true);
24352435
return cb;
24362436
}
24372437

@@ -2860,7 +2860,7 @@ unsigned char* decompress_jpeg_image_from_stream(jpeg_decoder_stream* pStream, i
28602860

28612861
const int dst_bpl = image_width * req_comps;
28622862

2863-
uint8* pImage_data = (uint8*)jpgd_malloc(dst_bpl * image_height);
2863+
uint8* pImage_data = (uint8*)jpgd_malloc((size_t)dst_bpl * (size_t)image_height);
28642864
if (!pImage_data)
28652865
return NULL;
28662866

crnlib/crn_jpge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ bool jpeg_encoder::jpg_open(int p_x_res, int p_y_res, int src_channels) {
576576
m_image_bpl_mcu = m_image_x_mcu * m_num_components;
577577
m_mcus_per_row = m_image_x_mcu / m_mcu_x;
578578

579-
if ((m_mcu_lines[0] = static_cast<uint8*>(jpge_malloc(m_image_bpl_mcu * m_mcu_y))) == NULL)
579+
if ((m_mcu_lines[0] = static_cast<uint8*>(jpge_malloc((size_t)m_image_bpl_mcu * (size_t)m_mcu_y))) == NULL)
580580
return false;
581581
for (int i = 1; i < m_mcu_y; i++)
582582
m_mcu_lines[i] = m_mcu_lines[i - 1] + m_image_bpl_mcu;

crnlib/crn_mipmapped_texture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,7 @@ bool mipmapped_texture::read_crn_from_memory(const void* pData, uint data_size,
27582758

27592759
if (!pDXT_image->init(
27602760
dxt_fmt, level_width, level_height,
2761-
num_blocks_x * num_blocks_y * (tex_info.m_bytes_per_block / sizeof(dxt_image::element)),
2761+
(size_t)num_blocks_x * (size_t)num_blocks_y * (tex_info.m_bytes_per_block / sizeof(dxt_image::element)),
27622762
reinterpret_cast<dxt_image::element*>(pFaces[f]), true)) {
27632763
crnlib_delete(pDXT_image);
27642764

crnlib/crn_threaded_clusterizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class threaded_clusterizer {
219219
double sum = 0;
220220

221221
for (uint j = 0; j < N; j++)
222-
sum += axis[j] * covar[i][j];
222+
sum += static_cast<double>(axis[j]) * static_cast<double>(covar[i][j]);
223223

224224
x[i] = static_cast<float>(sum);
225225

crnlib/crn_tree_clusterizer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class tree_clusterizer {
7272
m_weightedVectors[i] = v * (float)weight;
7373
root.m_centroid += m_weightedVectors[i];
7474
root.m_total_weight += weight;
75-
m_weightedDotProducts[i] = v.dot(v) * weight;
75+
m_weightedDotProducts[i] = (double)v.dot(v) * (double)weight;
7676
ttsum += m_weightedDotProducts[i];
7777
}
7878
root.m_variance = (float)(ttsum - (root.m_centroid.dot(root.m_centroid) / root.m_total_weight));
@@ -289,7 +289,7 @@ class tree_clusterizer {
289289
double sum = 0;
290290

291291
for (uint j = 0; j < N; j++)
292-
sum += axis[j] * covar[i][j];
292+
sum += (double)axis[j] * (double)covar[i][j];
293293

294294
x[i] = (float)sum;
295295

@@ -464,7 +464,7 @@ void split_vectors(VectorType (&vectors)[64], uint (&weights)[64], uint size, Ve
464464
weightedVectors[i] = v * (float)weight;
465465
centroid += weightedVectors[i];
466466
total_weight += weight;
467-
weightedDotProducts[i] = v.dot(v) * weight;
467+
weightedDotProducts[i] = (double)v.dot(v) * (double)weight;
468468
ttsum += weightedDotProducts[i];
469469
}
470470
float variance = (float)(ttsum - (centroid.dot(centroid) / total_weight));
@@ -520,7 +520,7 @@ void split_vectors(VectorType (&vectors)[64], uint (&weights)[64], uint size, Ve
520520
for (uint i = 0; i < N; i++) {
521521
double sum = 0;
522522
for (uint j = 0; j < N; j++)
523-
sum += axis[j] * covar[i][j];
523+
sum += (double)axis[j] * (double)covar[i][j];
524524
x[i] = (float)sum;
525525
max_sum = i ? math::maximum(max_sum, sum) : sum;
526526
}

crnlib/crn_vec.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,9 @@ class vec : public helpers::rel_ops<vec<N, T> > {
475475
}
476476

477477
inline double normalize(const vec* pDefaultVec = NULL) {
478-
double n = m_s[0] * m_s[0];
478+
double n = (double)m_s[0] * (double)m_s[0];
479479
for (uint i = 1; i < N; i++)
480-
n += m_s[i] * m_s[i];
480+
n += (double)m_s[i] * (double)m_s[i];
481481

482482
if (n != 0)
483483
*this *= static_cast<T>((1.0f / sqrt(n)));
@@ -489,7 +489,7 @@ class vec : public helpers::rel_ops<vec<N, T> > {
489489
inline double normalize3(const vec* pDefaultVec = NULL) {
490490
CRNLIB_ASSUME(N >= 3);
491491

492-
double n = m_s[0] * m_s[0] + m_s[1] * m_s[1] + m_s[2] * m_s[2];
492+
double n = (double)m_s[0] * (double)m_s[0] + (double)m_s[1] * (double)m_s[1] + (double)m_s[2] * (double)m_s[2];
493493

494494
if (n != 0)
495495
*this *= static_cast<T>((1.0f / sqrt(n)));

0 commit comments

Comments
 (0)