diff --git a/poi/src/main/java/org/apache/poi/ss/formula/atp/Switch.java b/poi/src/main/java/org/apache/poi/ss/formula/atp/Switch.java index 1daad88b8c..b70eb4f748 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/atp/Switch.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/atp/Switch.java @@ -56,7 +56,7 @@ public final class Switch implements FreeRefFunction { return ErrorEval.NA; } - for (int i = 1; i < args.length; i = i+2) { + for (int i = 1; i < (args.length - 1); i += 2) { try { ValueEval value = OperandResolver.getSingleValue(args[i], ec.getRowIndex(), ec.getColumnIndex()); diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java index e83ca3aef7..64ebc533be 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Baseifs.java @@ -67,7 +67,7 @@ import org.apache.poi.ss.formula.functions.Countif.ErrorMatcher; // collect pairs of ranges and criteria AreaEval[] ae = new AreaEval[(args.length - firstCriteria)/2]; I_MatchPredicate[] mp = new I_MatchPredicate[ae.length]; - for(int i = firstCriteria, k=0; i < args.length; i += 2, k++){ + for(int i = firstCriteria, k=0; i < (args.length - 1); i += 2, k++){ ae[k] = convertRangeArg(args[i]); mp[k] = Countif.createCriteriaPredicate(args[i+1], ec.getRowIndex(), ec.getColumnIndex()); diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Roman.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Roman.java index 4464ee4cff..299e48850f 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Roman.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Roman.java @@ -148,7 +148,7 @@ public class Roman extends Fixed2ArgFunction { continue; } String[] repl = REPLACEMENTS[i]; - for (int j=0; j