From aec3add71c8c175803bc6af38342061aa2d13727 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Thu, 24 Aug 2017 19:14:22 +0200 Subject: [PATCH] Fix set lower|upper bounds methods --- api/options.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/options.c b/api/options.c index 66c0881..b3f7470 100644 --- a/api/options.c +++ b/api/options.c @@ -272,7 +272,8 @@ NLOPT_STDCALL nlopt_set_lower_bounds(nlopt_opt opt, const double *lb) nlopt_unset_errmsg(opt); if (opt && (opt->n == 0 || lb)) { unsigned int i; - memcpy(opt->lb, lb, sizeof(double) * (opt->n)); + if (opt->n > 0) + memcpy(opt->lb, lb, sizeof(double) * (opt->n)); for (i = 0; i < opt->n; ++i) if (opt->lb[i] < opt->ub[i] && nlopt_istiny(opt->ub[i] - opt->lb[i])) opt->lb[i] = opt->ub[i]; @@ -314,7 +315,8 @@ NLOPT_STDCALL nlopt_set_upper_bounds(nlopt_opt opt, const double *ub) nlopt_unset_errmsg(opt); if (opt && (opt->n == 0 || ub)) { unsigned int i; - memcpy(opt->ub, ub, sizeof(double) * (opt->n)); + if (opt->n > 0) + memcpy(opt->ub, ub, sizeof(double) * (opt->n)); for (i = 0; i < opt->n; ++i) if (opt->lb[i] < opt->ub[i] && nlopt_istiny(opt->ub[i] - opt->lb[i])) opt->ub[i] = opt->lb[i]; -- 2.30.2