Skip to content

Potential fix for code scanning alert no. 15: Implicit narrowing conversion in compound assignment #9146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lbergelson
Copy link
Member

Potential fix for https://github.com/broadinstitute/gatk/security/code-scanning/15

To fix the problem, we need to change the type of the total variable from int to long. This will ensure that the sum of the long values in the array is correctly stored without any implicit narrowing conversion. The change should be made in the sum(final long[] x) method in the MathUtils class.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…ersion in compound assignment

Fixes a bug where sums were accidentally cast down to int.  Looking at the usages it seems like it's unlikely it was ever a problem in practice because the sums calculated look like they would never have been bigger than max int.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@lbergelson
Copy link
Member Author

@jamesemery code scanning found a real bug. It's a miracle!

@lbergelson lbergelson marked this pull request as ready for review April 13, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant