From: stevenj Date: Tue, 15 Nov 2011 20:41:17 +0000 (-0500) Subject: when adding mconstraints, allow tol==NULL as synonym for zero tolerances X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=40f664a9f61e0d2e62121f5af148267046b210c5;p=nlopt.git when adding mconstraints, allow tol==NULL as synonym for zero tolerances Ignore-this: db03978604ff683b95100eb50764dab9 darcs-hash:20111115204117-c8de0-f16c8f5ab44f1aa3ade48b350675d4a094c25e03.gz --- diff --git a/api/options.c b/api/options.c index be9ef72..1722fc9 100644 --- a/api/options.c +++ b/api/options.c @@ -342,13 +342,17 @@ static nlopt_result add_constraint(unsigned *m, unsigned *m_alloc, double *tolcopy; unsigned i; - if ((fc && mfc) || (fc && fm != 1) || (!fc && !mfc) || !tol) + if ((fc && mfc) || (fc && fm != 1) || (!fc && !mfc)) return NLOPT_INVALID_ARGS; - for (i = 0; i < fm; ++i) if (tol[i] < 0) return NLOPT_INVALID_ARGS; + if (tol) + 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; - memcpy(tolcopy, tol, sizeof(double) * fm); + if (tol) + memcpy(tolcopy, tol, sizeof(double) * fm); + else + for (i = 0; i < fm; ++i) tolcopy[i] = 0; *m += 1; if (*m > *m_alloc) {