From: stevenj Date: Wed, 7 Jul 2010 23:10:56 +0000 (-0400) Subject: return error if more than n equality constraints are specified X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=93939840a9894f90d9ea5d9b1b766d6f123019ce;p=nlopt.git return error if more than n equality constraints are specified darcs-hash:20100707231056-c8de0-74c179fa38352cee82f7ee5e209602be5aafe27b.gz --- diff --git a/api/options.c b/api/options.c index 9b2beda..fbd32a7 100644 --- a/api/options.c +++ b/api/options.c @@ -431,7 +431,8 @@ NLOPT_STDCALL nlopt_add_equality_mconstraint(nlopt_opt opt, unsigned m, const double *tol) { if (!m) return NLOPT_SUCCESS; /* empty constraints are always ok */ - if (!opt || !equality_ok(opt->algorithm)) return NLOPT_INVALID_ARGS; + if (!opt || !equality_ok(opt->algorithm) + || nlopt_count_constraints(opt->p, opt->h) + m > opt->n) return NLOPT_INVALID_ARGS; return add_constraint(&opt->p, &opt->p_alloc, &opt->h, m, NULL, fc, fc_data, tol); } @@ -441,7 +442,8 @@ NLOPT_STDCALL nlopt_add_equality_constraint(nlopt_opt opt, nlopt_func fc, void *fc_data, double tol) { - if (!opt || !equality_ok(opt->algorithm)) return NLOPT_INVALID_ARGS; + if (!opt || !equality_ok(opt->algorithm) + || nlopt_count_constraints(opt->p, opt->h) + 1 > opt->n) return NLOPT_INVALID_ARGS; return add_constraint(&opt->p, &opt->p_alloc, &opt->h, 1, fc, NULL, fc_data, &tol); }