chiark / gitweb /
yikes, fix argument check for tol argument in add_constraint functions
authorstevenj <stevenj@alum.mit.edu>
Wed, 7 Jul 2010 23:10:33 +0000 (19:10 -0400)
committerstevenj <stevenj@alum.mit.edu>
Wed, 7 Jul 2010 23:10:33 +0000 (19:10 -0400)
darcs-hash:20100707231033-c8de0-d1d4a50c4e1ac45220449d5b0057a758b9441dff.gz

api/options.c

index db955ccea63a6a2dc16c98d6717cdd31b5f0f729..9b2bedaf19c02ab2084ffc0c32dde900c86c5401 100644 (file)
@@ -336,9 +336,11 @@ static nlopt_result add_constraint(unsigned *m, unsigned *m_alloc,
                                   const double *tol)
 {
      double *tolcopy;
+     unsigned i;
 
-     if ((fc && mfc) || (fc && fm != 1) || (!fc && !mfc) || tol < 0)
+     if ((fc && mfc) || (fc && fm != 1) || (!fc && !mfc) || !tol)
          return NLOPT_INVALID_ARGS;
+     for (i = 0; i < fm; ++i) if (tol[i] < 0) return NLOPT_INVALID_ARGS;
      
      tolcopy = (double *) malloc(sizeof(double) * fm);
      if (fm && !tolcopy) return NLOPT_OUT_OF_MEMORY;