From ed5344aa35d1c956c8ce3fedfd9aae02631cca84 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 6 Jul 2024 04:41:52 +0200 Subject: [PATCH] crnlib: attempt to fix CodeQL reports --- crnlib/crn_jpgd.cpp | 4 ++-- crnlib/crn_jpge.cpp | 2 +- crnlib/crn_threaded_clusterizer.h | 2 +- crnlib/crn_tree_clusterizer.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crnlib/crn_jpgd.cpp b/crnlib/crn_jpgd.cpp index 762f884b..c007774e 100644 --- a/crnlib/crn_jpgd.cpp +++ b/crnlib/crn_jpgd.cpp @@ -2441,7 +2441,7 @@ jpeg_decoder::coeff_buf* jpeg_decoder::coeff_buf_open(int block_num_x, int block cb->block_len_x = block_len_x; cb->block_len_y = block_len_y; cb->block_size = (block_len_x * block_len_y) * sizeof(jpgd_block_t); - cb->pData = (uint8*)alloc(cb->block_size * block_num_x * block_num_y, true); + cb->pData = (uint8*)alloc((size_t)cb->block_size * (size_t)block_num_x * (size_t)block_num_y, true); return cb; } @@ -2870,7 +2870,7 @@ unsigned char* decompress_jpeg_image_from_stream(jpeg_decoder_stream* pStream, i const int dst_bpl = image_width * req_comps; - uint8* pImage_data = (uint8*)jpgd_malloc(dst_bpl * image_height); + uint8* pImage_data = (uint8*)jpgd_malloc((size_t)dst_bpl * (size_t)image_height); if (!pImage_data) return NULL; diff --git a/crnlib/crn_jpge.cpp b/crnlib/crn_jpge.cpp index 0c3d636f..7e0b4f8f 100644 --- a/crnlib/crn_jpge.cpp +++ b/crnlib/crn_jpge.cpp @@ -576,7 +576,7 @@ bool jpeg_encoder::jpg_open(int p_x_res, int p_y_res, int src_channels) { m_image_bpl_mcu = m_image_x_mcu * m_num_components; m_mcus_per_row = m_image_x_mcu / m_mcu_x; - if ((m_mcu_lines[0] = static_cast(jpge_malloc(m_image_bpl_mcu * m_mcu_y))) == NULL) + if ((m_mcu_lines[0] = static_cast(jpge_malloc((size_t)m_image_bpl_mcu * (size_t)m_mcu_y))) == NULL) return false; for (int i = 1; i < m_mcu_y; i++) m_mcu_lines[i] = m_mcu_lines[i - 1] + m_image_bpl_mcu; diff --git a/crnlib/crn_threaded_clusterizer.h b/crnlib/crn_threaded_clusterizer.h index cd2acf4e..467596cd 100644 --- a/crnlib/crn_threaded_clusterizer.h +++ b/crnlib/crn_threaded_clusterizer.h @@ -219,7 +219,7 @@ class threaded_clusterizer { double sum = 0; for (uint j = 0; j < N; j++) - sum += axis[j] * covar[i][j]; + sum += static_cast(axis[j]) * static_cast(covar[i][j]); x[i] = static_cast(sum); diff --git a/crnlib/crn_tree_clusterizer.h b/crnlib/crn_tree_clusterizer.h index d6785c3b..cf6a76d6 100644 --- a/crnlib/crn_tree_clusterizer.h +++ b/crnlib/crn_tree_clusterizer.h @@ -72,7 +72,7 @@ class tree_clusterizer { m_weightedVectors[i] = v * (float)weight; root.m_centroid += m_weightedVectors[i]; root.m_total_weight += weight; - m_weightedDotProducts[i] = v.dot(v) * weight; + m_weightedDotProducts[i] = (double)v.dot(v) * (double)weight; ttsum += m_weightedDotProducts[i]; } root.m_variance = (float)(ttsum - (root.m_centroid.dot(root.m_centroid) / root.m_total_weight)); @@ -289,7 +289,7 @@ class tree_clusterizer { double sum = 0; for (uint j = 0; j < N; j++) - sum += axis[j] * covar[i][j]; + sum += (double)axis[j] * (double)covar[i][j]; x[i] = (float)sum;