Skip to content

Commit

Permalink
fix misc. errors reported by clang static analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed May 7, 2017
1 parent 9b954c7 commit ce054bf
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/client/DownloadManager.cpp
Expand Up @@ -59,7 +59,7 @@ void DownloadManager::Start()

void DownloadManager::Update()
{
unsigned int numActiveDownloads;
unsigned int numActiveDownloads = 0;
while (!managerShutdown)
{
pthread_mutex_lock(&downloadAddLock);
Expand Down
27 changes: 0 additions & 27 deletions src/graphics/Graphics.cpp
Expand Up @@ -734,33 +734,6 @@ int Graphics::CharIndexAtPosition(char *s, int positionX, int positionY)
}


int Graphics::textposxy(char *s, int width, int w, int h)
{
int x=0,y=0,n=0,cw, wordlen, charspace;
while (*s)
{
wordlen = strcspn(s," .,!?\n");
charspace = textwidthx(s, width-x);
if (charspace<wordlen && wordlen && width-x<width/3)
{
x = 0;
y += FONT_H+2;
}
for (; *s && --wordlen>=-1; s++)
{
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2))
return n++;
x += cw;
if (x>=width) {
x = 0;
y += FONT_H+2;
}
n++;
}
}
return n;
}
int Graphics::textwrapheight(char *s, int width)
{
int x=0, height=FONT_H+2, cw;
Expand Down
1 change: 0 additions & 1 deletion src/graphics/Graphics.h
Expand Up @@ -211,7 +211,6 @@ class Graphics
static int textnwidth(char *s, int n);
static void textnpos(char *s, int n, int w, int *cx, int *cy);
static int textwidthx(char *s, int w);
static int textposxy(char *s, int width, int w, int h);
static int textwrapheight(char *s, int width);
static int textwidth(const char *s);
static void textsize(const char * s, int & width, int & height);
Expand Down
6 changes: 4 additions & 2 deletions src/graphics/Renderer.cpp
Expand Up @@ -95,7 +95,7 @@ void Renderer::RenderBegin()
{
std::copy(persistentVid, persistentVid+(VIDXRES*YRES), vid);
}
pixel * oldVid;
pixel * oldVid = NULL;
if(display_mode & DISPLAY_WARP)
{
oldVid = vid;
Expand Down Expand Up @@ -1028,6 +1028,8 @@ void Renderer::render_gravlensing(pixel * source)
pixel t;
pixel *src = source;
pixel *dst = vid;
if (!dst)
return;
for(nx = 0; nx < XRES; nx++)
{
for(ny = 0; ny < YRES; ny++)
Expand Down Expand Up @@ -2361,7 +2363,7 @@ void Renderer::draw_air()
float (*hv)[XRES/CELL] = sim->air->hv;
float (*vx)[XRES/CELL] = sim->air->vx;
float (*vy)[XRES/CELL] = sim->air->vy;
pixel c;
pixel c = 0;
for (y=0; y<YRES/CELL; y++)
for (x=0; x<XRES/CELL; x++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/gui/colourpicker/ColourPickerActivity.cpp
Expand Up @@ -140,7 +140,7 @@ void ColourPickerActivity::OnMouseMove(int x, int y, int dx, int dy)
if(valueMouseDown)
{
x -= Position.X+5;
y -= Position.Y+5;
//y -= Position.Y+5;

currentValue = x;

Expand Down Expand Up @@ -230,7 +230,7 @@ void ColourPickerActivity::OnMouseUp(int x, int y, unsigned button)
valueMouseDown = false;

x -= Position.X+5;
y -= Position.Y+5;
//y -= Position.Y+5;

currentValue = x;

Expand Down
6 changes: 3 additions & 3 deletions src/gui/game/GameView.cpp
Expand Up @@ -332,7 +332,7 @@ GameView::GameView():
tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(227, 15), "[no tags set]", "Add simulation tags");
tagSimulationButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
tagSimulationButton->SetIcon(IconTag);
currentX+=252;
//currentX+=252;
tagSimulationButton->SetActionCallback(new TagSimulationAction(this));
AddComponent(tagSimulationButton);

Expand Down Expand Up @@ -2433,9 +2433,9 @@ void GameView::OnDraw()
fpsInfo << " [REPLACE MODE]";
if (c->GetReplaceModeFlags()&SPECIFIC_DELETE)
fpsInfo << " [SPECIFIC DELETE]";
if (ren->GetGridSize())
if (ren && ren->GetGridSize())
fpsInfo << " [GRID: " << ren->GetGridSize() << "]";
if (ren->findingElement)
if (ren && ren->findingElement)
fpsInfo << " [FIND]";

int textWidth = Graphics::textwidth((char*)fpsInfo.str().c_str());
Expand Down
4 changes: 2 additions & 2 deletions src/gui/search/SearchView.cpp
Expand Up @@ -466,8 +466,8 @@ void SearchView::NotifyTagListChanged(SearchModel * sender)
int savesY = 4, buttonPadding = 1;
int buttonAreaHeight, buttonYOffset;

int tagWidth, tagHeight, tagX = 0, tagY = 0, tagsX = 6, tagsY = 4, tagPadding = 1;
int tagAreaWidth, tagAreaHeight, tagXOffset, tagYOffset;
int tagWidth = 0, tagHeight = 0, tagX = 0, tagY = 0, tagsX = 6, tagsY = 4, tagPadding = 1;
int tagAreaWidth, tagAreaHeight, tagXOffset = 0, tagYOffset = 0;

vector<pair<string, int> > tags = sender->GetTagList();

Expand Down
4 changes: 2 additions & 2 deletions src/lua/TPTScriptInterface.cpp
Expand Up @@ -272,8 +272,8 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
throw GeneralException("Invalid property");

//Selector
int newValue;
float newValuef;
int newValue = 0;
float newValuef = 0.0f;
if (value.GetType() == TypeNumber)
{
newValuef = newValue = ((NumberType)value).Value();
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/elements/PIPE.cpp
Expand Up @@ -185,7 +185,7 @@ int Element_PIPE::update(UPDATE_FUNC_ARGS)
{
rndstore = rand();
rnd = rndstore&7;
rndstore = rndstore>>3;
//rndstore = rndstore>>3;
rx = pos_1_rx[rnd];
ry = pos_1_ry[rnd];
if (BOUNDS_CHECK)
Expand Down
3 changes: 2 additions & 1 deletion src/simulation/elements/STKM.cpp
Expand Up @@ -143,7 +143,8 @@ int Element_STKM::run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) {
rby = 1.0f;
tmp = 1.0f;
}
tmp = 1.0f/sqrtf(rbx*rbx+rby*rby);
else
tmp = 1.0f/sqrtf(rbx*rbx+rby*rby);
rbx *= tmp;// scale to a unit vector
rby *= tmp;
if (rbLowGrav)
Expand Down

0 comments on commit ce054bf

Please sign in to comment.