Skip to content

Commit d47c389

Browse files
committed
overflow check from a constructor function.
1 parent ab3b200 commit d47c389

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/linalg/Matrix.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ Matrix::Matrix(
130130
memcpy(d_mat, mat, d_alloc_size*sizeof(double));
131131
}
132132
else {
133+
// Check integer multiplication overflow
134+
if (num_rows > INT_MAX / num_cols)
135+
CAROM_ERROR("Matrix::setSize- new size exceeds maximum integer value!\n");
136+
133137
d_mat = mat;
134138
d_alloc_size = num_rows*num_cols;
135139
d_num_cols = num_cols;

0 commit comments

Comments
 (0)