Skip to content

Commit 951d912

Browse files
committed
crnlib: attempt to silence false positive CodeQL cpp/static-buffer-overflow
On the default case it wrongly reports as critical: > Potential buffer-overflow: 'm_buf' has size 2 but 'm_buf[3]' may be accessed here. Because it fails to understand that default only happens with m_buf size being 4.
1 parent a386984 commit 951d912

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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: 2 additions & 2 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] = static_cast<double>(v.dot(v)) * static_cast<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 += static_cast<double>(axis[j]) * static_cast<double>(covar[i][j]);
293293

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

0 commit comments

Comments
 (0)