Skip to content

Commit

Permalink
Check double bounds while parsing (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown authored Jul 28, 2021
1 parent 1bb0361 commit 624a37b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public Throwable fillInStackTrace() {
public ParsingFailure(String message, Throwable cause) {
super(message, cause);
}

public ParsingFailure(String message) {
super(message);
}
}

public static final class ResolutionFailure extends DhallException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ private static Source sourceFromToken(Token token) {
}

static final Expr.Parsed makeDoubleLiteral(Token token) {
return new Expr.Parsed(
Expr.makeDoubleLiteral(Double.parseDouble(token.image)), sourceFromToken(token));
double parsed = Double.parseDouble(token.image);

if (Double.isInfinite(parsed)
&& !token.image.equals("Infinity")
&& !token.image.equals("-Infinity")) {
throw new ParsingFailure("double out of bounds");
}

return new Expr.Parsed(Expr.makeDoubleLiteral(parsed), sourceFromToken(token));
}

static final Expr.Parsed makeNaturalLiteral(Token token) {
Expand Down

0 comments on commit 624a37b

Please sign in to comment.