Fixed warnings for Implicit narrowing conversion in compound assignment #1758
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
readSkipBytes
has 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
bytesToSkip
can be converted without information loss, and only allow addition topayloadOffset
if this is true.The reverse, that is widening
payloadOffset
to long, to accommodatebytesToSkip
is not possible because of the many usespayloadOffset
has throughout the file. Lines 7043 and 7049 inIOBuffer.java
are good examples of this. Extensive reformatting is needed to changepayloadOffset
, whilebytesToSkip
can be checked with ease.The function used to check if
bytesToSkip
is 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.