Skip to content

Java: FP in java/index-out-of-bounds when index known to be less than the length of the array #1061

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
s0 opened this issue Mar 7, 2019 · 0 comments

Comments

@s0
Copy link
Contributor

s0 commented Mar 7, 2019

See: https://discuss.lgtm.com/t/java-false-positives/1787/2

int x = ++i;
int y = ++i;
if (y < sb.length) {
  byte[] hex = {sb[x], sb[y]};
                ^^^^^ -- flagged as alert

We know that (modulo overflow):

  • x = y - 1 --> x < y
  • y < sb.length

Example: https://lgtm.com/projects/g/apache/accumulo/snapshot/b672a845ed56e9fd521ab85462cb6c45baa9abad/files/core/src/main/java/org/apache/accumulo/core/iterators/conf/ColumnSet.java?sort=name&dir=ASC&mode=heatmap#xb5a588dd1daff67e:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants