From dfbf1989d3a850626283b04f93a9f61d99e7c9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr> Date: Mon, 7 Feb 2011 11:12:32 +0100 Subject: [PATCH] K-order DLL: add test for NaN/Inf in param/steady-state vectors to avoid crashes (thanks to J. Pfeifer for reporting this) (cherry picked from commit 0f9ec8b2dc496218bcd3f9f8e8abac30c1864184) --- mex/sources/k_order_perturbation/k_order_perturbation.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mex/sources/k_order_perturbation/k_order_perturbation.cc b/mex/sources/k_order_perturbation/k_order_perturbation.cc index 6ee2b06b61..8cfd3c5329 100644 --- a/mex/sources/k_order_perturbation/k_order_perturbation.cc +++ b/mex/sources/k_order_perturbation/k_order_perturbation.cc @@ -106,16 +106,22 @@ extern "C" { double *dparams = (double *) mxGetData(mxFldp); int npar = (int) mxGetM(mxFldp); Vector modParams(dparams, npar); + if (!modParams.isFinite()) + DYN_MEX_FUNC_ERR_MSG_TXT("The parameters vector contains NaN or Inf"); mxFldp = mxGetField(M_, 0, "Sigma_e"); dparams = (double *) mxGetData(mxFldp); npar = (int) mxGetN(mxFldp); TwoDMatrix vCov(npar, npar, dparams); + if (!vCov.isFinite()) + DYN_MEX_FUNC_ERR_MSG_TXT("The covariance matrix of shocks contains NaN or Inf"); mxFldp = mxGetField(dr, 0, "ys"); // and not in order of dr.order_var dparams = (double *) mxGetData(mxFldp); const int nSteady = (int) mxGetM(mxFldp); Vector ySteady(dparams, nSteady); + if (!ySteady.isFinite()) + DYN_MEX_FUNC_ERR_MSG_TXT("The steady state vector contains NaN or Inf"); mxFldp = mxGetField(dr, 0, "nstatic"); const int nStat = (int) mxGetScalar(mxFldp); -- GitLab