panacekcz / checker-framework

Pluggable type-checking for Java
http://checkerframework.org/
Other
0 stars 0 forks source link

Known suffix can guard against index out of bounds when skipping characters #21

Open panacekcz opened 6 years ago

panacekcz commented 6 years ago

The following code is safe, because the index i can never get past the ')' suffix, so it is always a valid index for s:

if(s.endsWith(")")) {
 @IndexFor("s") int i = 0;
 while (s.charAt(i) == '[') {
  i++;
 }
 char c = s.charAt(i);
}

This occurred in plume-lib UtilMDE.arglistFromJvm, but now it seems not to be an issue.