Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix negative array index lookup overflow messages (Fixes #1188)
  • Loading branch information
PseudoKnight committed May 22, 2020
1 parent 52316a7 commit 5813d34
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/ArrayHandling.java
Expand Up @@ -171,9 +171,17 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime
//Convert negative indexes
if(start < 0) {
start = ca.size() + start;
if(start < 0) {
throw new CREIndexOverflowException("The element at index \""
+ ((CSlice) index).getStart() + "\" does not exist", t);
}
}
if(finish < 0) {
finish = ca.size() + finish;
if(finish < 0) {
throw new CREIndexOverflowException("The element at index \""
+ ((CSlice) index).getFinish() + "\" does not exist", t);
}
}
CArray na = ca.createNew(t);
if(finish < start) {
Expand Down Expand Up @@ -201,6 +209,10 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime
if(iindex < 0) {
//negative index, convert to positive index
iindex = ca.size() + iindex;
if(iindex < 0) {
throw new CREIndexOverflowException("The element at index \"" + index.val()
+ "\" does not exist", t);
}
}
return ca.get(iindex, t);
} else {
Expand Down

0 comments on commit 5813d34

Please sign in to comment.