Skip to content

Fix #846: multip. result converted to larger type#849

Merged
mhucka merged 5 commits intomasterfrom
mh-fix-846-multiplication
Aug 15, 2025
Merged

Fix #846: multip. result converted to larger type#849
mhucka merged 5 commits intomasterfrom
mh-fix-846-multiplication

Conversation

@mhucka
Copy link
Copy Markdown
Collaborator

@mhucka mhucka commented Jul 31, 2025

CodeQL scans flagged the construct ➀ below on line 53 in lib/matrix.h because the multiplication result may overflow 'unsigned int' before it is converted to 'size_type'.

template <typename fp_type>
inline void MatrixIdentity(unsigned n, Matrix<fp_type>& m) {
  m.resize(2 * n * n);      ➀

The warning is:

This rule finds code that converts the result of an integer multiplication to a larger type. Since the conversion applies after the multiplication, arithmetic overflow may still occur.

CodeQL scans flagged the construct ➀ below on line 53 in `lib/matrix.h` because the multiplication result may overflow 'unsigned int' before it is converted to 'size_type'.

```C++
template <typename fp_type>
inline void MatrixIdentity(unsigned n, Matrix<fp_type>& m) {
  m.resize(2 * n * n);      ➀
```

The warning is:

> This rule finds code that converts the result of an integer multiplication to a larger type. Since the conversion applies after the multiplication, arithmetic overflow may still occur.
@github-actions github-actions Bot added the size: XS <10 lines changed label Jul 31, 2025
@mhucka mhucka self-assigned this Jul 31, 2025
@mhucka mhucka marked this pull request as ready for review August 14, 2025 02:55
@mhucka mhucka enabled auto-merge (squash) August 15, 2025 20:23
@mhucka mhucka merged commit 1d89c1d into master Aug 15, 2025
49 checks passed
@mhucka mhucka deleted the mh-fix-846-multiplication branch August 15, 2025 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XS <10 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants