From 93939840a9894f90d9ea5d9b1b766d6f123019ce Mon Sep 17 00:00:00 2001 From: stevenj Date: Wed, 7 Jul 2010 19:10:56 -0400 Subject: [PATCH] return error if more than n equality constraints are specified darcs-hash:20100707231056-c8de0-74c179fa38352cee82f7ee5e209602be5aafe27b.gz --- api/options.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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); } -- 2.30.2