mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8321180: Condition for non-latin1 string size too large exception is off by one
Reviewed-by: rgiulietti
This commit is contained in:
parent
d5a96e3f49
commit
4fb5c12813
2 changed files with 111 additions and 9 deletions
|
@ -42,15 +42,10 @@ import static java.lang.String.LATIN1;
|
|||
|
||||
final class StringUTF16 {
|
||||
|
||||
// Return a new byte array for a UTF16-coded string for len chars
|
||||
// Throw an exception if out of range
|
||||
public static byte[] newBytesFor(int len) {
|
||||
if (len < 0) {
|
||||
throw new NegativeArraySizeException();
|
||||
}
|
||||
if (len > MAX_LENGTH) {
|
||||
throw new OutOfMemoryError("UTF16 String size is " + len +
|
||||
", should be less than " + MAX_LENGTH);
|
||||
}
|
||||
return new byte[len << 1];
|
||||
return new byte[newBytesLength(len)];
|
||||
}
|
||||
|
||||
// Check the size of a UTF16-coded string
|
||||
|
@ -59,7 +54,7 @@ final class StringUTF16 {
|
|||
if (len < 0) {
|
||||
throw new NegativeArraySizeException();
|
||||
}
|
||||
if (len > MAX_LENGTH) {
|
||||
if (len >= MAX_LENGTH) {
|
||||
throw new OutOfMemoryError("UTF16 String size is " + len +
|
||||
", should be less than " + MAX_LENGTH);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue