This commit is contained in:
Jesper Wilhelmsson 2019-01-15 22:54:09 +01:00
commit a8c5f1e59a
64 changed files with 1781 additions and 378 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,7 @@ package java.math;
import static java.math.BigInteger.LONG_MASK;
import java.util.Arrays;
import java.util.Objects;
/**
* Immutable, arbitrary-precision signed decimal numbers. A
@ -424,9 +425,14 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
* @since 1.5
*/
public BigDecimal(char[] in, int offset, int len, MathContext mc) {
// protect against huge length.
if (offset + len > in.length || offset < 0)
throw new NumberFormatException("Bad offset or len arguments for char[] input.");
// protect against huge length, negative values, and integer overflow
try {
Objects.checkFromIndexSize(offset, len, in.length);
} catch (IndexOutOfBoundsException e) {
throw new NumberFormatException
("Bad offset or len arguments for char[] input.");
}
// This is the primary string to BigDecimal constructor; all
// incoming strings end up here; it uses explicit (inline)
// parsing for speed and generates at most one intermediate