Fixed warnings for Implicit narrowing conversion in compound assignment#1758
Merged
Jeffery-Wasty merged 5 commits intomainfrom Mar 3, 2022
Merged
Fixed warnings for Implicit narrowing conversion in compound assignment#1758Jeffery-Wasty merged 5 commits intomainfrom
Jeffery-Wasty merged 5 commits intomainfrom
Conversation
Contributor
|
I might be missing something here, but isn't an alternative like changing the "valueLength" param to int and then keeping the rest of the types in the method to int possible also? I only see the "readSkipBytes" method used in one place and it is taking in an int only, never a long |
Contributor
Author
|
You know what, I think you're absolutely right. I'm looking at the initial implementation, and it may have been necessary to pass in a long in that case, but that's no longer needed. This simplifies things greatly. |
tkyc
approved these changes
Mar 2, 2022
lilgreenbird
approved these changes
Mar 3, 2022
VeryVerySpicy
approved these changes
Mar 3, 2022
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.
(Update 3/2/2022) While the below approach works, given that the use of
readSkipByteshas changed, its no longer necessary to pass in along. Thus the changes can be reduced to ensuring all involved types areint, avoiding any information loss.As seen here: https://github.com/microsoft/mssql-jdbc/security/code-scanning/1?query=ref%3Arefs%2Fheads%2Fmain, there is an implicit cast taking place in IOBuffer.java, that may lead to a loss of information. The solution was to first check if the long value
bytesToSkipcan be converted without information loss, and only allow addition topayloadOffsetif this is true.The reverse, that is widening
payloadOffsetto long, to accommodatebytesToSkipis not possible because of the many usespayloadOffsethas throughout the file. Lines 7043 and 7049 inIOBuffer.javaare good examples of this. Extensive reformatting is needed to changepayloadOffset, whilebytesToSkipcan be checked with ease.The function used to check if
bytesToSkipis small enough,isSafeToConvert, uses a switch function even though it only has one case, this is to allow future cases to be added, if needed. Additionally, other values, besides long, can be passed in to convert, provided they are cast beforehand.