chiark / gitweb /
Fix set lower|upper bounds methods
authorJulien Schueller <schueller@phimeca.com>
Thu, 24 Aug 2017 17:14:22 +0000 (19:14 +0200)
committerJulien Schueller <schueller@phimeca.com>
Sun, 10 Sep 2017 07:34:55 +0000 (09:34 +0200)
api/options.c

index 66c0881faa98923ca77b94fb41380de176eda1fe..b3f7470932d857d5f04371e8716b4789c6702a04 100644 (file)
@@ -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];