From 8913d11fa529f768cdf9bdef7e1b30d335624a36 Mon Sep 17 00:00:00 2001 From: Daniel Richard G Date: Mon, 26 Aug 2013 15:36:00 -0400 Subject: [PATCH] Quash "variable may be used uninitialized" warnings Whether or not there is any actual danger of these variables being used without initialization, the warnings are noise, and getting rid of them is trivial. --- bsp.cpp | 2 +- draw.cpp | 2 +- drawconstraint.cpp | 4 ++-- drawentity.cpp | 4 +++- mesh.cpp | 3 ++- modify.cpp | 4 ++-- polygon.cpp | 5 +++-- request.cpp | 2 +- srf/ratpoly.cpp | 2 +- srf/raycast.cpp | 2 +- srf/surface.cpp | 2 +- srf/surfinter.cpp | 4 ++-- system.cpp | 2 +- ttf.cpp | 6 +++--- win32/w32main.cpp | 2 +- 15 files changed, 25 insertions(+), 21 deletions(-) diff --git a/bsp.cpp b/bsp.cpp index 72eb4f0..ae509c4 100644 --- a/bsp.cpp +++ b/bsp.cpp @@ -49,7 +49,7 @@ void SBsp3::InsertInPlane(bool pos2, STriangle *tr, SMesh *m) { Vector tc = ((tr->a).Plus(tr->b).Plus(tr->c)).ScaledBy(1.0/3); bool onFace = false; - bool sameNormal; + bool sameNormal = false; double maxNormalMag = -1; Vector lln, trn = tr->Normal(); diff --git a/draw.cpp b/draw.cpp index c9f4e05..4659749 100644 --- a/draw.cpp +++ b/draw.cpp @@ -40,7 +40,7 @@ void GraphicsWindow::Selection::Clear(void) { } void GraphicsWindow::Selection::Draw(void) { - Vector refp; + Vector refp = Vector::From(0, 0, 0); if(entity.v) { Entity *e = SK.GetEntity(entity); e->Draw(); diff --git a/drawconstraint.cpp b/drawconstraint.cpp index 3e7bf33..7a42653 100644 --- a/drawconstraint.cpp +++ b/drawconstraint.cpp @@ -695,7 +695,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) { } case PERPENDICULAR: { - Vector u, v; + Vector u = Vector::From(0, 0, 0), v = Vector::From(0, 0, 0); Vector rn, ru; if(workplane.v == Entity::FREE_IN_3D.v) { rn = gn; @@ -845,7 +845,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) { case LENGTH_RATIO: case EQUAL_LENGTH_LINES: { - Vector a, b; + Vector a, b = Vector::From(0, 0, 0); for(int i = 0; i < 2; i++) { Entity *e = SK.GetEntity(i == 0 ? entityA : entityB); a = SK.GetEntity(e->point[0])->PointGetNum(); diff --git a/drawentity.cpp b/drawentity.cpp index 800a491..b9afcd4 100644 --- a/drawentity.cpp +++ b/drawentity.cpp @@ -239,7 +239,9 @@ void Entity::ComputeInterpolatingSpline(SBezierList *sbl, bool periodic) { // The starting and finishing control points that define our end tangents // (if the spline isn't periodic), and the on-curve points. - Vector ctrl_s, ctrl_f, pt[MAX_N+4]; + Vector ctrl_s = Vector::From(0, 0, 0); + Vector ctrl_f = Vector::From(0, 0, 0); + Vector pt[MAX_N+4]; if(periodic) { for(i = 0; i < ep + 3; i++) { pt[i] = SK.GetEntity(point[i])->PointGetNum(); diff --git a/mesh.cpp b/mesh.cpp index 967bd38..72ac223 100644 --- a/mesh.cpp +++ b/mesh.cpp @@ -113,7 +113,8 @@ void SMesh::Simplify(int start) { STriangle *tout = (STriangle *)AllocTemporary(maxTriangles*sizeof(*tout)); int toutc = 0; - Vector n, *conv = (Vector *)AllocTemporary(maxTriangles*3*sizeof(*conv)); + Vector n = Vector::From(0, 0, 0); + Vector *conv = (Vector *)AllocTemporary(maxTriangles*3*sizeof(*conv)); int convc = 0; int start0 = start; diff --git a/modify.cpp b/modify.cpp index 0e8fcf6..86c709d 100644 --- a/modify.cpp +++ b/modify.cpp @@ -286,7 +286,7 @@ void GraphicsWindow::MakeTangentArc(void) { memset(req, 0, sizeof(req)); Vector pinter; - double r, vv; + double r = 0.0, vv = 0.0; // We now do Newton iterations to find the tangent arc, and its positions // t back along the two curves, starting from shared point of the curves // at t = 0. Lots of iterations helps convergence, and this is still @@ -616,7 +616,7 @@ void GraphicsWindow::SplitLinesOrCurves(void) { sbla.AllIntersectionsWith(&sblb, &inters); if(inters.l.n > 0) { - Vector pi; + Vector pi = Vector::From(0, 0, 0); // If there's multiple points, then take the one closest to the // mouse pointer. double dmin = VERY_POSITIVE; diff --git a/polygon.cpp b/polygon.cpp index 46727f0..f146d72 100644 --- a/polygon.cpp +++ b/polygon.cpp @@ -203,7 +203,8 @@ bool SEdgeList::AssemblePolygon(SPolygon *dest, SEdge *errorAt, bool keepDir) { bool allClosed = true; for(;;) { - Vector first, last; + Vector first = Vector::From(0, 0, 0); + Vector last = Vector::From(0, 0, 0); int i; for(i = 0; i < l.n; i++) { if(!l.elem[i].tag) { @@ -826,7 +827,7 @@ void SContour::OffsetInto(SContour *dest, double r) { // material as we can without removing any that we shouldn't. double px0, py0, pdx, pdy; double nx0, ny0, ndx, ndy; - double x, y; + double x = 0.0, y = 0.0; px0 = b.x - r*sin(thetap); py0 = b.y + r*cos(thetap); diff --git a/request.cpp b/request.cpp index 168020a..a6d8c09 100644 --- a/request.cpp +++ b/request.cpp @@ -76,7 +76,7 @@ bool EntReqTable::GetEntityInfo(int ent, int extraPoints, } int EntReqTable::GetRequestForEntity(int ent) { - int req; + int req = 0; GetEntityInfo(ent, 0, &req, NULL, NULL, NULL); return req; } diff --git a/srf/ratpoly.cpp b/srf/ratpoly.cpp index 578b205..4bc4d04 100644 --- a/srf/ratpoly.cpp +++ b/srf/ratpoly.cpp @@ -441,7 +441,7 @@ void SSurface::ClosestPointTo(Vector p, double *u, double *v, bool converge) { bool SSurface::ClosestPointNewton(Vector p, double *u, double *v, bool converge) { // Initial guess is in u, v; refine by Newton iteration. - Vector p0; + Vector p0 = Vector::From(0, 0, 0); for(int i = 0; i < (converge ? 25 : 5); i++) { p0 = PointAt(*u, *v); if(converge) { diff --git a/srf/raycast.cpp b/srf/raycast.cpp index aa85b19..11d8af3 100644 --- a/srf/raycast.cpp +++ b/srf/raycast.cpp @@ -18,7 +18,7 @@ extern int FLAG; double SSurface::DepartureFromCoplanar(void) { int i, j; - int ia, ja, ib, jb, ic, jc; + int ia, ja, ib = 0, jb = 0, ic = 0, jc = 0; double best; // Grab three points to define a plane; first choose (0, 0) arbitrarily. diff --git a/srf/surface.cpp b/srf/surface.cpp index 92bbe9d..7116238 100644 --- a/srf/surface.cpp +++ b/srf/surface.cpp @@ -211,7 +211,7 @@ bool SSurface::LineEntirelyOutsideBbox(Vector a, Vector b, bool segment) { void SSurface::MakeTrimEdgesInto(SEdgeList *sel, int flags, SCurve *sc, STrimBy *stb) { - Vector prev; + Vector prev = Vector::From(0, 0, 0); bool inCurve = false, empty = true; double u = 0, v = 0; diff --git a/srf/surfinter.cpp b/srf/surfinter.cpp index 171b7ec..0c0a4c0 100644 --- a/srf/surfinter.cpp +++ b/srf/surfinter.cpp @@ -392,8 +392,8 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB, sc.pts.Add(&padd); Point2d pa, pb; - Vector np, npc; - bool fwd; + Vector np, npc = Vector::From(0, 0, 0); + bool fwd = false; // Better to start with a too-small step, so that we don't miss // features of the curve entirely. double tol, step = maxtol; diff --git a/system.cpp b/system.cpp index f23c5a4..6d63fb5 100644 --- a/system.cpp +++ b/system.cpp @@ -179,7 +179,7 @@ bool System::SolveLinearSystem(double X[], double A[][MAX_UNKNOWNS], // Gaussian elimination, with partial pivoting. It's an error if the // matrix is singular, because that means two constraints are // equivalent. - int i, j, ip, jp, imax; + int i, j, ip, jp, imax = 0; double max, temp; for(i = 0; i < n; i++) { diff --git a/ttf.cpp b/ttf.cpp index 9643927..6f52afc 100644 --- a/ttf.cpp +++ b/ttf.cpp @@ -318,7 +318,7 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { WORD nameStringOffset = GetWORD(); // And now we're at the name records. Go through those till we find // one that we want. - int displayNameOffset, displayNameLength; + int displayNameOffset = 0, displayNameLength = 0; for(i = 0; i < nameCount; i++) { WORD platformID = GetWORD(); WORD encodingID = GetWORD(); @@ -430,8 +430,8 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { // and advance width) of the font. fseek(fh, hmtxAddr, SEEK_SET); - WORD hmtxAdvanceWidth; - SWORD hmtxLsb; + WORD hmtxAdvanceWidth = 0; + SWORD hmtxLsb = 0; for(i = 0; i < min(glyphs, hheaNumberOfMetrics); i++) { hmtxAdvanceWidth = GetWORD(); hmtxLsb = (SWORD)GetWORD(); diff --git a/win32/w32main.cpp b/win32/w32main.cpp index 5159cc1..6b5e597 100644 --- a/win32/w32main.cpp +++ b/win32/w32main.cpp @@ -956,7 +956,7 @@ void RefreshRecentMenus(void) HMENU CreateGraphicsWindowMenus(void) { HMENU top = CreateMenu(); - HMENU m; + HMENU m = 0; int i; int subMenu = 0;