Fix G115 false positive when going from parsed uint to larger int #1254
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.
Fixes the issue I recently found in #1212 (comment).
When converting to an
int*
from auint64
created bystrconv.ParseUint
with a specified bit size less than the size of the destination integer, currently G115 is falsely triggered.That's because the current check only allows the source and destination sign to match (i.e. from int* to int* or uint* to uint*). This is a useful check when going from
ParseInt
to a uint*, but when going fromParseUint
to an int* the conversion is safe as long as the bit size is at least one less.I've added the extra test and documented it since the logic is somewhat complex.
I've also added a few test cases to catch regressions.