Potential fix for code scanning alert no. 18: Implicit narrowing conversion in compound assignment#1013
Draft
Avery-Dunn wants to merge 1 commit intodevfrom
Draft
Potential fix for code scanning alert no. 18: Implicit narrowing conversion in compound assignment#1013Avery-Dunn wants to merge 1 commit intodevfrom
Avery-Dunn wants to merge 1 commit intodevfrom
Conversation
…ersion in compound assignment Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/AzureAD/microsoft-authentication-library-for-java/security/code-scanning/18
In general, the fix is to ensure that the left-hand side of the compound assignment is at least as wide as the right-hand side expression. Here, the expression
interval[1] - interval[0]is of typelong, sosumshould also be alongto avoid implicit narrowing when doingsum += ....The best targeted fix is:
sumfrominttolong.sum(specifically in the divisionsum/list.size()) performlongarithmetic and then rely on Java’s automatic widening when concatenating with the string; no further changes are necessary there becausesumbeinglongis acceptable and safe.Concretely, in
msal4j-persistence-extension/src/test/java/com/microsoft/aad/msal4jextensions/CacheLockTestBase.java, insidevalidateLockUsageIntervals:int sum = 0;tolong sum = 0L;.No new imports, methods, or definitions are required.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.