Skip to content

Commit

Permalink
Allow Matrix.setValues to be called with array size >9.
Browse files Browse the repository at this point in the history
If the array is <9, and ArrayIndexOutOfBoundsException is still thrown.

Tested by new tests in `ShadowMatrixTest`.

Fixes #8369
  • Loading branch information
zach-klippenstein authored and utzcoz committed Jul 27, 2023
1 parent c3ef827 commit 8174aad
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Expand Up @@ -152,6 +152,35 @@ public void testGetSetValues() {
assertThat(matrixValues).isEqualTo(values);
}

@Test
public void testGetSetValues_withLargeArray() {
final Matrix matrix = new Matrix();
final float[] values = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f};
matrix.setValues(values);
final float[] matrixValues = new float[10];
matrix.getValues(matrixValues);
// First 9 elements should match.
for (int i = 0; i < 9; i++) {
assertThat(matrixValues[i]).isEqualTo(values[i]);
}
// The last element should not have been set.
assertThat(matrixValues[9]).isEqualTo(0);
}

@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testGetValues_withSmallArray() {
final Matrix matrix = new Matrix();
final float[] matrixValues = new float[8];
matrix.getValues(matrixValues);
}

@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testSetValues_withSmallArray() {
final Matrix matrix = new Matrix();
final float[] values = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f};
matrix.setValues(values);
}

@Test
public void testSet() {
final Matrix matrix1 = new Matrix();
Expand Down
Expand Up @@ -426,7 +426,7 @@ private static SimpleMatrix newIdentityMatrix() {
}

private SimpleMatrix(float[] values) {
if (values.length != 9) {
if (values.length < 9) {
throw new ArrayIndexOutOfBoundsException();
}
mValues = Arrays.copyOf(values, 9);
Expand Down

0 comments on commit 8174aad

Please sign in to comment.