From ea0a1b743ae4d3d03c8bd691f6d20692af8f77c0 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 17 Nov 2016 13:57:31 +0000 Subject: [PATCH] Fix uninitialized variable warnings. gcc 6 displays these when compiling in release mode; all of these warnings except the rankOk one were benign because there would have been an error about the incomplete switch statement. The rankOk warning highlighted a real problem: bailing early to didnt_converge would have branched on an uninitialized variable. --- src/generate.cpp | 4 ++-- src/render/rendergl1.cpp | 2 +- src/request.cpp | 4 ++-- src/resource.cpp | 4 ++-- src/system.cpp | 3 +++ 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/generate.cpp b/src/generate.cpp index 283b58d0..9865efae 100644 --- a/src/generate.cpp +++ b/src/generate.cpp @@ -142,7 +142,7 @@ bool SolveSpaceUI::PruneConstraints(hGroup hg) { } void SolveSpaceUI::GenerateAll(Generate type, bool andFindFree, bool genForBBox) { - int first, last, i, j; + int first = 0, last = 0, i, j; uint64_t startMillis = GetMilliseconds(), endMillis; @@ -355,7 +355,7 @@ void SolveSpaceUI::GenerateAll(Generate type, bool andFindFree, bool genForBBox) endMillis = GetMilliseconds(); if(endMillis - startMillis > 30) { - const char *typeStr; + const char *typeStr = ""; switch(type) { case Generate::DIRTY: typeStr = "DIRTY"; break; case Generate::ALL: typeStr = "ALL"; break; diff --git a/src/render/rendergl1.cpp b/src/render/rendergl1.cpp index a84cb9d9..29c55722 100644 --- a/src/render/rendergl1.cpp +++ b/src/render/rendergl1.cpp @@ -308,7 +308,7 @@ void OpenGl1Renderer::SelectTexture(std::shared_ptr pm) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - GLenum format; + GLenum format = 0; switch(pm->format) { case Pixmap::Format::RGBA: format = GL_RGBA; break; case Pixmap::Format::RGB: format = GL_RGB; break; diff --git a/src/request.cpp b/src/request.cpp index 999cc945..0fdd0969 100644 --- a/src/request.cpp +++ b/src/request.cpp @@ -81,7 +81,7 @@ void Request::Generate(IdList *entity, IdList *param) { int points = 0; - Entity::Type et; + Entity::Type et = (Entity::Type)0; bool hasNormal = false; bool hasDistance = false; int i; @@ -190,7 +190,7 @@ void Request::Generate(IdList *entity, } std::string Request::DescriptionString() const { - const char *s; + const char *s = ""; if(h.v == Request::HREQUEST_REFERENCE_XY.v) { s = "#XY"; } else if(h.v == Request::HREQUEST_REFERENCE_YZ.v) { diff --git a/src/resource.cpp b/src/resource.cpp index d2d4b210..6f8102a3 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -264,8 +264,8 @@ std::shared_ptr Pixmap::ReadPng(const std::string &filename, bool flip) } bool Pixmap::WritePng(FILE *f, bool flip) { - int colorType; - bool bgr; + int colorType = 0; + bool bgr = false; switch(format) { case Format::RGBA: colorType = PNG_COLOR_TYPE_RGBA; bgr = false; break; case Format::BGRA: colorType = PNG_COLOR_TYPE_RGBA; bgr = true; break; diff --git a/src/system.cpp b/src/system.cpp index 41f02160..101a10ac 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -440,6 +440,9 @@ SolveResult System::Solve(Group *g, int *dof, List *bad, p->tag = alone; WriteJacobian(alone); if(!NewtonSolve(alone)) { + // We don't do the rank test, so let's arbitrarily return + // the DIDNT_CONVERGE result here. + rankOk = true; // Failed to converge, bail out early goto didnt_converge; }