From 45f7de33e8858f1b629c7d4cd031ed931567815d Mon Sep 17 00:00:00 2001 From: Michel Juillard <michel.juillard@mjui.fr> Date: Sat, 15 Feb 2014 21:02:33 +0100 Subject: [PATCH] sobol qmc_sequence MEX: dimension larger than 1111 returns a proper Matlab error message instead of crashing --- mex/sources/sobol/qmc_sequence.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mex/sources/sobol/qmc_sequence.cc b/mex/sources/sobol/qmc_sequence.cc index 04e4a567f..bd6ed4ddc 100644 --- a/mex/sources/sobol/qmc_sequence.cc +++ b/mex/sources/sobol/qmc_sequence.cc @@ -21,6 +21,7 @@ ** AUTHOR(S): stephane DOT adjemian AT univ DASH lemans DOT fr **/ +#include <sstream> #include <string.h> #include <stdint.h> #include <dynmex.h> @@ -28,6 +29,9 @@ #include "sobol.hh" #include "gaussian.hh" +// the maximum dimension defined in sobol.ff (but undef at the end) +#define DIM_MAX 1111 + void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* @@ -100,6 +104,13 @@ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { DYN_MEX_FUNC_ERR_MSG_TXT("qmc_sequence:: First input (dimension) has to be greater than 1 for a uniform QMC on an hypershere!"); } + else if (dimension > DIM_MAX) + { + stringstream msg; + msg << "qmc_sequence:: First input (dimension) has to be smaller than " << DIM_MAX << " !"; + DYN_MEX_FUNC_ERR_MSG_TXT(msg.str().c_str()); + } + /* ** Test the optional fourth input argument and assign it to sequence_size. */ -- GitLab