Add in missing Java std::list listIterator index range checking

This commit is contained in:
William S Fulton 2017-06-29 19:32:34 +01:00
parent fccf5c29b4
commit 44cd658a53
3 changed files with 38 additions and 0 deletions

View File

@ -158,5 +158,23 @@ public class li_std_list_runme {
if (v10.size() != 4) throw new RuntimeException("v10 test (4) failed");
if (v10.get(1) != 22) throw new RuntimeException("v10 test (5) failed");
if (v10.get(2) != 33) throw new RuntimeException("v10 test (6) failed");
v10.add(v10.size(), 55);
if (v10.size() != 5) throw new RuntimeException("v10 test (7) failed");
if (v10.get(4) != 55) throw new RuntimeException("v10 test (8) failed");
IntList v11 = new IntList(java.util.Arrays.asList(11, 22, 33, 44));
v11.listIterator(0);
v11.listIterator(v11.size());
try {
v11.listIterator(v11.size() + 1);
throw new RuntimeException("v11 test (1) failed");
} catch (IndexOutOfBoundsException e) {
}
try {
v11.listIterator(-1);
throw new RuntimeException("v11 test (2) failed");
} catch (IndexOutOfBoundsException e) {
}
}
}

View File

@ -149,5 +149,23 @@ public class li_std_vector_runme {
if (v10.size() != 4) throw new RuntimeException("v10 test (4) failed");
if (v10.get(1) != 22) throw new RuntimeException("v10 test (5) failed");
if (v10.get(2) != 33) throw new RuntimeException("v10 test (6) failed");
v10.add(v10.size(), 55);
if (v10.size() != 5) throw new RuntimeException("v10 test (7) failed");
if (v10.get(4) != 55) throw new RuntimeException("v10 test (8) failed");
IntVector v11 = new IntVector(java.util.Arrays.asList(11, 22, 33, 44));
v11.listIterator(0);
v11.listIterator(v11.size());
try {
v11.listIterator(v11.size() + 1);
throw new RuntimeException("v11 test (1) failed");
} catch (IndexOutOfBoundsException e) {
}
try {
v11.listIterator(-1);
throw new RuntimeException("v11 test (2) failed");
} catch (IndexOutOfBoundsException e) {
}
}
}

View File

@ -55,6 +55,8 @@ namespace std {
private Iterator last;
private java.util.ListIterator<$typemap(jboxtype, T)> init(int index) {
if (index < 0 || index > $javaclassname.this.size())
throw new IndexOutOfBoundsException("Index: " + index);
pos = $javaclassname.this.begin();
pos = pos.advance_unchecked(index);
return this;