From 6b471f205ef00572abebaf403d55433f2ce40eee Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 15 Nov 2013 10:59:19 +0100 Subject: fix overflow and ambiguity in SparseLU memory allocation --- Eigen/src/SparseLU/SparseLU_Memory.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'Eigen/src/SparseLU') diff --git a/Eigen/src/SparseLU/SparseLU_Memory.h b/Eigen/src/SparseLU/SparseLU_Memory.h index e1e7de043..d068d62df 100644 --- a/Eigen/src/SparseLU/SparseLU_Memory.h +++ b/Eigen/src/SparseLU/SparseLU_Memory.h @@ -93,7 +93,7 @@ Index SparseLUImpl::expand(VectorType& vec, Index& length, Index { // First time to allocate from LUMemInit() // Let LUMemInit() deals with it. - return 0; + return -1; } if (keep_prev) { @@ -152,10 +152,9 @@ template Index SparseLUImpl::memInit(Index m, Index n, Index annz, Index lwork, Index fillratio, Index panel_size, GlobalLU_t& glu) { Index& num_expansions = glu.num_expansions; //No memory expansions so far - num_expansions = 0; - glu.nzumax = glu.nzlumax = (std::min)(fillratio * annz, m*n); // estimated number of nonzeros in U + num_expansions = 0; + glu.nzumax = glu.nzlumax = (std::min)(fillratio * annz / n, m) * n; // estimated number of nonzeros in U glu.nzlmax = (std::max)(Index(4), fillratio) * annz / 4; // estimated nnz in L factor - // Return the estimated size to the user if necessary Index tempSpace; tempSpace = (2*panel_size + 4 + LUNoMarker) * m * sizeof(Index) + (panel_size + 1) * m * sizeof(Scalar); @@ -179,10 +178,10 @@ Index SparseLUImpl::memInit(Index m, Index n, Index annz, Index lw // Reserve memory for L/U factors do { - if( (!expand(glu.lusup, glu.nzlumax, 0, 0, num_expansions)) - || (!expand(glu.ucol, glu.nzumax, 0, 0, num_expansions)) - || (!expand (glu.lsub, glu.nzlmax, 0, 0, num_expansions)) - || (!expand (glu.usub, glu.nzumax, 0, 1, num_expansions)) ) + if( (expand(glu.lusup, glu.nzlumax, 0, 0, num_expansions)<0) + || (expand(glu.ucol, glu.nzumax, 0, 0, num_expansions)<0) + || (expand (glu.lsub, glu.nzlmax, 0, 0, num_expansions)<0) + || (expand (glu.usub, glu.nzumax, 0, 1, num_expansions)<0) ) { //Reduce the estimated size and retry glu.nzlumax /= 2; -- cgit v1.2.3