Skip to content

Commit

Permalink
crnlib: attempt to silence false positive CodeQL cpp/static-buffer-ov…
Browse files Browse the repository at this point in the history
…erflow

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.
  • Loading branch information
illwieckz committed Jul 6, 2024
1 parent a386984 commit 951d912
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crnlib/crn_threaded_clusterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(axis[j]) * static_cast<double>(covar[i][j]);

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

Expand Down
4 changes: 2 additions & 2 deletions crnlib/crn_tree_clusterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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] = static_cast<double>(v.dot(v)) * static_cast<double>(weight);
ttsum += m_weightedDotProducts[i];
}
root.m_variance = (float)(ttsum - (root.m_centroid.dot(root.m_centroid) / root.m_total_weight));
Expand Down Expand Up @@ -289,7 +289,7 @@ class tree_clusterizer {
double sum = 0;

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

x[i] = (float)sum;

Expand Down

0 comments on commit 951d912

Please sign in to comment.