From: Julien Schueller Date: Wed, 23 Aug 2017 19:46:11 +0000 (+0200) Subject: Fix all uninitialized variable warnings X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5b068e95253718f182f3370c895bbc0b36140bdf;p=nlopt.git Fix all uninitialized variable warnings Every variables that yields a -Wmaybe-uninitialized gcc warning is set to 0 Fixes #133 --- diff --git a/bobyqa/bobyqa.c b/bobyqa/bobyqa.c index 0317789..2ef46a3 100644 --- a/bobyqa/bobyqa.c +++ b/bobyqa/bobyqa.c @@ -158,8 +158,8 @@ static nlopt_result rescue_(int *n, int *npt, const double *xl, const double *xu /* Local variables */ double f; int i__, j, k, ih, jp, ip, iq, np, iw; - double xp, xq, den; - int ihp; + double xp = 0.0, xq, den; + int ihp = 0; double one; int ihq, jpn, kpt; double sum, diff, half, beta; @@ -760,12 +760,12 @@ static void altmov_(int *n, int *npt, double *xpt, double slbd; int iubd; double vlag, subd, temp; - int ksav; - double step, zero, curv; + int ksav = 0; + double step = 0.0, zero, curv; int iflag; - double scale, csave, tempa, tempb, tempd, const__, sumin, ggfree; - int ibdsav; - double dderiv, bigstp, predsq, presav, distsq, stpsav, wfixsq, wsqsav; + double scale, csave = 0.0, tempa, tempb, tempd, const__, sumin, ggfree; + int ibdsav = 0; + double dderiv, bigstp, predsq, presav, distsq, stpsav = 0.0, wfixsq, wsqsav; /* The arguments N, NPT, XPT, XOPT, BMAT, ZMAT, NDIM, SL and SU all have */ @@ -1174,16 +1174,16 @@ static void trsbox_(int *n, int *npt, double *xpt, double ds; int iu; double dhd, dhs, cth, one, shs, sth, ssq, half, beta, sdec, blen; - int iact, nact; + int iact = 0, nact; double angt, qred; int isav; - double temp, zero, xsav, xsum, angbd, dredg, sredg; + double temp, zero, xsav = 0.0, xsum, angbd = 0.0, dredg = 0.0, sredg = 0.0; int iterc; - double resid, delsq, ggsav, tempa, tempb, ratio, sqstp, redmax, - dredsq, redsav, onemin, gredsq, rednew; - int itcsav; - double rdprev, rdnext, stplen, stepsq; - int itermax; + double resid, delsq, ggsav = 0.0, tempa, tempb, ratio, sqstp, redmax, + dredsq = 0.0, redsav, onemin, gredsq = 0.0, rednew; + int itcsav = 0; + double rdprev, rdnext = 0.0, stplen, stepsq; + int itermax = 0; /* The arguments N, NPT, XPT, XOPT, GOPT, HQ, PQ, SL and SU have the same */ @@ -1728,8 +1728,8 @@ static nlopt_result prelim_(int *n, int *npt, double *x, double f; int i__, j, k, ih, np, nfm; double one; - int nfx, ipt, jpt; - double two, fbeg, diff, half, temp, zero, recip, stepa, stepb; + int nfx, ipt = 0, jpt = 0; + double two, fbeg, diff, half, temp, zero, recip, stepa = 0.0, stepb = 0.0; int itemp; double rhosq; @@ -1979,7 +1979,7 @@ static nlopt_result bobyqb_(int *n, int *npt, double *x, int kopt, nptm; double zero, curv; int ksav; - double gqsq, dist, sumw, sumz, diffa, diffb, diffc, hdiag; + double gqsq, dist, sumw, sumz, diffa, diffb, diffc = 0.0, hdiag; int kbase; double alpha, delta, adelt, denom, fsave, bdtol, delsq; int nresc, nfsav; diff --git a/cobyla/cobyla.c b/cobyla/cobyla.c index ca4219a..2e7a81c 100644 --- a/cobyla/cobyla.c +++ b/cobyla/cobyla.c @@ -478,7 +478,7 @@ static nlopt_result cobylb(int *n, int *m, int *mpp, int ivmc; int ivmd; int mp, np, iz, ibrnch; - int nbest, ifull, iptem, jdrop; + int nbest, ifull = 0, iptem, jdrop; nlopt_result rc = NLOPT_SUCCESS; uint32_t seed = (uint32_t) (*n + *m); /* arbitrary deterministic LCG seed */ int feasible; diff --git a/luksan/pnet.c b/luksan/pnet.c index d57461c..3e25634 100644 --- a/luksan/pnet.c +++ b/luksan/pnet.c @@ -144,7 +144,7 @@ static void pnet_(int *nf, int *nb, double *x, int * /* Builtin functions */ /* Local variables */ - double a, b; + double a = 0.0, b = 0.0; int i__, n; double p, r__; int kd, ld; diff --git a/luksan/pssubs.c b/luksan/pssubs.c index cfec171..6e81e56 100644 --- a/luksan/pssubs.c +++ b/luksan/pssubs.c @@ -96,7 +96,7 @@ void luksan_pnint1__(double *rl, double *ru, double *fl, double d__1, d__2; /* Local variables */ - double a, b, c__, d__, den, dis; + double a = 0.0, b = 0.0, c__, d__, den = 0.0, dis; int ntyp; *merr = 0; diff --git a/mma/ccsa_quadratic.c b/mma/ccsa_quadratic.c index 01f2413..2b34527 100644 --- a/mma/ccsa_quadratic.c +++ b/mma/ccsa_quadratic.c @@ -224,7 +224,7 @@ nlopt_result ccsa_quadratic_minimize( double *xcur, rho, *sigma, *dfdx, *dfdx_cur, *xprev, *xprevprev, fcur; double *dfcdx, *dfcdx_cur; double *fcval, *fcval_cur, *rhoc, *gcval, *y, *dual_lb, *dual_ub; - double *pre_lb, *pre_ub; + double *pre_lb = NULL, *pre_ub = NULL; unsigned i, ifc, j, k = 0; dual_data dd; int feasible; diff --git a/newuoa/newuoa.c b/newuoa/newuoa.c index f6ad2ce..a22849e 100644 --- a/newuoa/newuoa.c +++ b/newuoa/newuoa.c @@ -108,16 +108,16 @@ static nlopt_result trsapp_(int *n, int *npt, double *xopt, /* Local variables */ int i__, j, k; - double dd, cf, dg, gg; + double dd = 0.0, cf, dg, gg = 0.0; int ih; - double ds, sg; + double ds, sg = 0.0; int iu; - double ss, dhd, dhs, cth, sgk, shs, sth, qadd, half, qbeg, qred, qmin, - temp, qsav, qnew, zero, ggbeg, alpha, angle, reduc; + double ss, dhd, dhs, cth, sgk, shs = 0.0, sth, qadd, half, qbeg, qred = 0.0, qmin, + temp, qsav, qnew, zero, ggbeg = 0.0, alpha, angle, reduc; int iterc; - double ggsav, delsq, tempa, tempb; + double ggsav, delsq, tempa = 0.0, tempb = 0.0; int isave; - double bstep, ratio, twopi; + double bstep = 0.0, ratio, twopi; int itersw; double angtest; int itermax; @@ -1070,7 +1070,7 @@ static nlopt_result biglag_(int *n, int *npt, double *xopt, int nptm; double zero, angle, scale, denom; int iterc, isave; - double delsq, tempa, tempb, twopi, taubeg, tauold, taumax; + double delsq, tempa, tempb = 0.0, twopi, taubeg, tauold, taumax; /* N is the number of variables. */ @@ -1390,7 +1390,7 @@ static void update_(int *n, int *npt, double *bmat, int nptm; double zero; int iflag; - double scala, scalb_, alpha, denom, tempa, tempb, tausq; + double scala, scalb_, alpha, denom, tempa, tempb = 0.0, tausq; /* The arrays BMAT and ZMAT with IDZ are updated, in order to shift the */ @@ -1579,31 +1579,31 @@ static nlopt_result newuob_(int *n, int *npt, double *x, double d__1, d__2, d__3; /* Local variables */ - double f; + double f = 0.0; int i__, j, k, ih, nf, nh, ip, jp; double dx; int np, nfm; double one; int idz; - double dsq, rho; - int ipt, jpt; - double sum, fbeg, diff, half, beta; + double dsq, rho = 0.0; + int ipt = 0, jpt = 0; + double sum, fbeg = 0.0, diff, half, beta; int nfmm; double gisq; int knew; double temp, suma, sumb, fopt = HUGE_VAL, bsum, gqsq; int kopt, nptm; - double zero, xipt, xjpt, sumz, diffa, diffb, diffc, hdiag, alpha, + double zero, xipt = 0.0, xjpt = 0.0, sumz, diffa = 0.0, diffb = 0.0, diffc = 0.0, hdiag, alpha = 0.0, delta, recip, reciq, fsave; - int ksave, nfsav, itemp; - double dnorm, ratio, dstep, tenth, vquad; + int ksave, nfsav = 0, itemp; + double dnorm = 0.0, ratio = 0.0, dstep, tenth, vquad; int ktemp; double tempq; - int itest; + int itest = 0; double rhosq; - double detrat, crvmin; + double detrat, crvmin = 0.0; double distsq; - double xoptsq; + double xoptsq = 0.0; double rhoend; nlopt_result rc = NLOPT_SUCCESS, rc2; diff --git a/praxis/praxis.c b/praxis/praxis.c index d6636a9..a032904 100644 --- a/praxis/praxis.c +++ b/praxis/praxis.c @@ -622,7 +622,7 @@ static void minfit_(int m, int n, double machep, /* Local variables */ double *e; /* size n */ - double c__, f, g, h__; + double c__, f = 0.0, g, h__; int i__, j, k, l; double s, x, y, z__; int l2, ii, kk, kt, ll2, lp1; diff --git a/slsqp/slsqp.c b/slsqp/slsqp.c index 6cb284d..8a4be2d 100644 --- a/slsqp/slsqp.c +++ b/slsqp/slsqp.c @@ -315,7 +315,7 @@ static void nnls_(double *a, int *mda, int *m, int * double up; int iz1, iz2, npp1, iter; double wmax, alpha, asave; - int itmax, izmax, nsetp; + int itmax, izmax = 0, nsetp; double unorm; /* C.L.LAWSON AND R.J.HANSON, JET PROPULSION LABORATORY: */