Skip to content

Commit

Permalink
Fix uninitialized variable warnings.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
whitequark committed Nov 17, 2016
1 parent 802d092 commit ea0a1b7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/generate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/render/rendergl1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void OpenGl1Renderer::SelectTexture(std::shared_ptr<const Pixmap> 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;
Expand Down
4 changes: 2 additions & 2 deletions src/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
IdList<Param,hParam> *param)
{
int points = 0;
Entity::Type et;
Entity::Type et = (Entity::Type)0;
bool hasNormal = false;
bool hasDistance = false;
int i;
Expand Down Expand Up @@ -190,7 +190,7 @@ void Request::Generate(IdList<Entity,hEntity> *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) {
Expand Down
4 changes: 2 additions & 2 deletions src/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ std::shared_ptr<Pixmap> 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;
Expand Down
3 changes: 3 additions & 0 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ SolveResult System::Solve(Group *g, int *dof, List<hConstraint> *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;
}
Expand Down

0 comments on commit ea0a1b7

Please sign in to comment.