From ce054bfc3f2d69efd821ca4bafea84ca57a19d64 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 6 May 2017 20:02:23 -0400 Subject: [PATCH] fix misc. errors reported by clang static analyzer --- src/client/DownloadManager.cpp | 2 +- src/graphics/Graphics.cpp | 27 ------------------- src/graphics/Graphics.h | 1 - src/graphics/Renderer.cpp | 6 +++-- src/gui/colourpicker/ColourPickerActivity.cpp | 4 +-- src/gui/game/GameView.cpp | 6 ++--- src/gui/search/SearchView.cpp | 4 +-- src/lua/TPTScriptInterface.cpp | 4 +-- src/simulation/elements/PIPE.cpp | 2 +- src/simulation/elements/STKM.cpp | 3 ++- 10 files changed, 17 insertions(+), 42 deletions(-) diff --git a/src/client/DownloadManager.cpp b/src/client/DownloadManager.cpp index 15026206a..dc333a6ed 100644 --- a/src/client/DownloadManager.cpp +++ b/src/client/DownloadManager.cpp @@ -59,7 +59,7 @@ void DownloadManager::Start() void DownloadManager::Update() { - unsigned int numActiveDownloads; + unsigned int numActiveDownloads = 0; while (!managerShutdown) { pthread_mutex_lock(&downloadAddLock); diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index beeec809c..69d3ad342 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -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=-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; diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h index ddb22bc2e..6ad16a697 100644 --- a/src/graphics/Graphics.h +++ b/src/graphics/Graphics.h @@ -211,7 +211,6 @@ public: 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); diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index df80531dc..d528e58d6 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -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; @@ -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++) @@ -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; yAppearance.HorizontalAlign = ui::Appearance::AlignLeft; tagSimulationButton->SetIcon(IconTag); - currentX+=252; + //currentX+=252; tagSimulationButton->SetActionCallback(new TagSimulationAction(this)); AddComponent(tagSimulationButton); @@ -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()); diff --git a/src/gui/search/SearchView.cpp b/src/gui/search/SearchView.cpp index cbb190ab1..f49a99877 100644 --- a/src/gui/search/SearchView.cpp +++ b/src/gui/search/SearchView.cpp @@ -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 > tags = sender->GetTagList(); diff --git a/src/lua/TPTScriptInterface.cpp b/src/lua/TPTScriptInterface.cpp index bf09543c8..d2fbc8ef6 100644 --- a/src/lua/TPTScriptInterface.cpp +++ b/src/lua/TPTScriptInterface.cpp @@ -272,8 +272,8 @@ AnyType TPTScriptInterface::tptS_set(std::deque * 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(); diff --git a/src/simulation/elements/PIPE.cpp b/src/simulation/elements/PIPE.cpp index 6d7a25826..56e0a13cd 100644 --- a/src/simulation/elements/PIPE.cpp +++ b/src/simulation/elements/PIPE.cpp @@ -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) diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp index cd17c14b9..0c16109ee 100644 --- a/src/simulation/elements/STKM.cpp +++ b/src/simulation/elements/STKM.cpp @@ -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)