Skip to content

Commit

Permalink
Merge pull request #412 from Pieter12345/master
Browse files Browse the repository at this point in the history
Fixed an NPE in mod(@var, 0).
  • Loading branch information
jb-aero committed Apr 6, 2016
2 parents 16ae2e2 + 3e85176 commit bf7105c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/com/laytonsmith/core/functions/Math.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,20 @@ public Integer[] numArgs() {
public Construct exec(Target t, Environment env, Construct... args) throws CancelCommandException, ConfigRuntimeException {
long arg1 = Static.getInt(args[0], t);
long arg2 = Static.getInt(args[1], t);
if(arg2 == 0) {
throw new CRERangeException("Modulo by 0!", t);
}
return new CInt(arg1 % arg2, t);
}

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[]{CRECastException.class};
return new Class[]{CRECastException.class, CRERangeException.class};
}

@Override
public String docs() {
return "int {x, n} Returns x modulo n. Operator syntax is also supported: @x % @n";
return "int {x, n} Returns x modulo n. Throws a RangeException when n is 0. Operator syntax is also supported: @x % @n";
}

@Override
Expand Down

0 comments on commit bf7105c

Please sign in to comment.