mirror of
https://github.com/apache/commons-math.git
synced 2025-02-06 10:09:26 +00:00
Fixed an integer overflow in OpenMapRealMatrix.
JIRA: MATH-679 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1181181 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
004b8958d7
commit
5e6389761c
@ -19,6 +19,7 @@ package org.apache.commons.math.linear;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.math.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math.util.OpenIntToDoubleHashMap;
|
||||
|
||||
/**
|
||||
@ -46,6 +47,11 @@ public class OpenMapRealMatrix extends AbstractRealMatrix
|
||||
*/
|
||||
public OpenMapRealMatrix(int rowDimension, int columnDimension) {
|
||||
super(rowDimension, columnDimension);
|
||||
long lRow = (long) rowDimension;
|
||||
long lCol = (long) columnDimension;
|
||||
if (lRow * lCol >= (long) Integer.MAX_VALUE) {
|
||||
throw new NumberIsTooLargeException(lRow * lCol, Integer.MAX_VALUE, false);
|
||||
}
|
||||
this.rows = rowDimension;
|
||||
this.columns = columnDimension;
|
||||
this.entries = new OpenIntToDoubleHashMap(0.0);
|
||||
|
@ -52,6 +52,9 @@ The <action> type attribute can be add,update,fix,remove.
|
||||
If the output is not quite correct, check for invisible trailing spaces!
|
||||
-->
|
||||
<release version="3.0" date="TBD" description="TBD">
|
||||
<action dev="luc" type="fix" issue="MATH-679" due-to="Christopher Berner">
|
||||
Fixed an integer overflow in OpenMapRealMatrix.
|
||||
</action>
|
||||
<action dev="erans" type="fix" issue="MATH-688">
|
||||
"FastMath": Use constant fields instead of recomputing them at method
|
||||
call.
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.commons.math.linear;
|
||||
|
||||
import org.apache.commons.math.exception.NumberIsTooLargeException;
|
||||
import org.junit.Test;
|
||||
|
||||
public final class OpenMapRealMatrixTest {
|
||||
|
||||
@Test(expected=NumberIsTooLargeException.class)
|
||||
public void testMath679() {
|
||||
new OpenMapRealMatrix(3, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user