Skip to content

Commit

Permalink
Fix issues from static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Nov 15, 2017
1 parent c59e9e9 commit 5f5fb04
Show file tree
Hide file tree
Showing 23 changed files with 518 additions and 685 deletions.
45 changes: 20 additions & 25 deletions CDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void CDebug::actualizeData()
FrameCounterText = dbgWnd->addText(puffer1, 0, 10, fontsize);

// Frames per Second
static float tmpFrameCtr = 0, tmpTickCtr = (float)SDL_GetTicks();
static Uint32 tmpFrameCtr = 0, tmpTickCtr = SDL_GetTicks();
if(tmpFrameCtr == 10)
{
// del FramesPerSecText before drawing new
Expand All @@ -124,7 +124,7 @@ void CDebug::actualizeData()
FramesPerSecText = dbgWnd->addText(puffer1, 0, 20, fontsize);
// set new values
tmpFrameCtr = 0;
tmpTickCtr = (float)SDL_GetTicks();
tmpTickCtr = SDL_GetTicks();
} else
tmpFrameCtr++;

Expand Down Expand Up @@ -171,6 +171,7 @@ void CDebug::actualizeData()
if(MapObj != NULL)
{
map = MapObj->map;
const MapNode& vertex = map->getVertex(MapObj->VertexX_, MapObj->VertexY_);

if(MapNameText != NULL)
{
Expand Down Expand Up @@ -242,10 +243,8 @@ void CDebug::actualizeData()
}
if(VertexDataText == NULL)
{
sprintf(puffer1, "Vertex Data: x=%d, y=%d, z=%d i=%.2f h=%#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).x,
map->getVertex(MapObj->VertexX_, MapObj->VertexY_).y, map->getVertex(MapObj->VertexX_, MapObj->VertexY_).z,
((float)map->getVertex(MapObj->VertexX_, MapObj->VertexY_).i) / pow(2, 16),
map->getVertex(MapObj->VertexX_, MapObj->VertexY_).h);
sprintf(puffer1, "Vertex Data: x=%d, y=%d, z=%d i=%.2f h=%#04x", vertex.x, vertex.y, vertex.z, ((float)vertex.i) / pow(2, 16),
vertex.h);
VertexDataText = dbgWnd->addText(puffer1, 260, 70, fontsize);
}
if(VertexVectorText != NULL)
Expand All @@ -255,9 +254,7 @@ void CDebug::actualizeData()
}
if(VertexVectorText == NULL)
{
sprintf(puffer1, "Vertex Vector: (%.2f, %.2f, %.2f)", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).normVector.x,
map->getVertex(MapObj->VertexX_, MapObj->VertexY_).normVector.y,
map->getVertex(MapObj->VertexX_, MapObj->VertexY_).normVector.z);
sprintf(puffer1, "Vertex Vector: (%.2f, %.2f, %.2f)", vertex.normVector.x, vertex.normVector.y, vertex.normVector.z);
VertexVectorText = dbgWnd->addText(puffer1, 260, 80, fontsize);
}
if(FlatVectorText != NULL)
Expand All @@ -267,9 +264,7 @@ void CDebug::actualizeData()
}
if(FlatVectorText == NULL)
{
sprintf(puffer1, "Flat Vector: (%.2f, %.2f, %.2f)", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).flatVector.x,
map->getVertex(MapObj->VertexX_, MapObj->VertexY_).flatVector.y,
map->getVertex(MapObj->VertexX_, MapObj->VertexY_).flatVector.z);
sprintf(puffer1, "Flat Vector: (%.2f, %.2f, %.2f)", vertex.flatVector.x, vertex.flatVector.y, vertex.flatVector.z);
FlatVectorText = dbgWnd->addText(puffer1, 260, 90, fontsize);
}
if(rsuTextureText != NULL)
Expand All @@ -279,7 +274,7 @@ void CDebug::actualizeData()
}
if(rsuTextureText == NULL)
{
sprintf(puffer1, "RSU-Texture: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).rsuTexture);
sprintf(puffer1, "RSU-Texture: %#04x", vertex.rsuTexture);
rsuTextureText = dbgWnd->addText(puffer1, 260, 100, fontsize);
}
if(usdTextureText != NULL)
Expand All @@ -289,7 +284,7 @@ void CDebug::actualizeData()
}
if(usdTextureText == NULL)
{
sprintf(puffer1, "USD-Texture: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).usdTexture);
sprintf(puffer1, "USD-Texture: %#04x", vertex.usdTexture);
usdTextureText = dbgWnd->addText(puffer1, 260, 110, fontsize);
}
if(roadText != NULL)
Expand All @@ -299,7 +294,7 @@ void CDebug::actualizeData()
}
if(roadText == NULL)
{
sprintf(puffer1, "road: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).road);
sprintf(puffer1, "road: %#04x", vertex.road);
roadText = dbgWnd->addText(puffer1, 260, 120, fontsize);
}
if(objectTypeText != NULL)
Expand All @@ -309,7 +304,7 @@ void CDebug::actualizeData()
}
if(objectTypeText == NULL)
{
sprintf(puffer1, "objectType: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).objectType);
sprintf(puffer1, "objectType: %#04x", vertex.objectType);
objectTypeText = dbgWnd->addText(puffer1, 260, 130, fontsize);
}
if(objectInfoText != NULL)
Expand All @@ -319,7 +314,7 @@ void CDebug::actualizeData()
}
if(objectInfoText == NULL)
{
sprintf(puffer1, "objectInfo: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).objectInfo);
sprintf(puffer1, "objectInfo: %#04x", vertex.objectInfo);
objectInfoText = dbgWnd->addText(puffer1, 260, 140, fontsize);
}
if(animalText != NULL)
Expand All @@ -329,7 +324,7 @@ void CDebug::actualizeData()
}
if(animalText == NULL)
{
sprintf(puffer1, "animal: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).animal);
sprintf(puffer1, "animal: %#04x", vertex.animal);
animalText = dbgWnd->addText(puffer1, 260, 150, fontsize);
}
if(unknown1Text != NULL)
Expand All @@ -339,7 +334,7 @@ void CDebug::actualizeData()
}
if(unknown1Text == NULL)
{
sprintf(puffer1, "unknown1: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).unknown1);
sprintf(puffer1, "unknown1: %#04x", vertex.unknown1);
unknown1Text = dbgWnd->addText(puffer1, 260, 160, fontsize);
}
if(buildText != NULL)
Expand All @@ -349,7 +344,7 @@ void CDebug::actualizeData()
}
if(buildText == NULL)
{
sprintf(puffer1, "build: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).build);
sprintf(puffer1, "build: %#04x", vertex.build);
buildText = dbgWnd->addText(puffer1, 260, 170, fontsize);
}
if(unknown2Text != NULL)
Expand All @@ -359,7 +354,7 @@ void CDebug::actualizeData()
}
if(unknown2Text == NULL)
{
sprintf(puffer1, "unknown2: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).unknown2);
sprintf(puffer1, "unknown2: %#04x", vertex.unknown2);
unknown2Text = dbgWnd->addText(puffer1, 260, 180, fontsize);
}
if(unknown3Text != NULL)
Expand All @@ -369,7 +364,7 @@ void CDebug::actualizeData()
}
if(unknown3Text == NULL)
{
sprintf(puffer1, "unknown3: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).unknown3);
sprintf(puffer1, "unknown3: %#04x", vertex.unknown3);
unknown3Text = dbgWnd->addText(puffer1, 260, 190, fontsize);
}
if(resourceText != NULL)
Expand All @@ -379,7 +374,7 @@ void CDebug::actualizeData()
}
if(resourceText == NULL)
{
sprintf(puffer1, "resource: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).resource);
sprintf(puffer1, "resource: %#04x", vertex.resource);
resourceText = dbgWnd->addText(puffer1, 260, 200, fontsize);
}
if(shadingText != NULL)
Expand All @@ -389,7 +384,7 @@ void CDebug::actualizeData()
}
if(shadingText == NULL)
{
sprintf(puffer1, "shading: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).shading);
sprintf(puffer1, "shading: %#04x", vertex.shading);
shadingText = dbgWnd->addText(puffer1, 260, 210, fontsize);
}
if(unknown5Text != NULL)
Expand All @@ -399,7 +394,7 @@ void CDebug::actualizeData()
}
if(unknown5Text == NULL)
{
sprintf(puffer1, "unknown5: %#04x", map->getVertex(MapObj->VertexX_, MapObj->VertexY_).unknown5);
sprintf(puffer1, "unknown5: %#04x", vertex.unknown5);
unknown5Text = dbgWnd->addText(puffer1, 260, 220, fontsize);
}
if(editorModeText != NULL)
Expand Down
4 changes: 1 addition & 3 deletions CDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ class CDebug
CFont* unknown5Text;
CFont* editorModeText;
// some puffers to write texts with sprintf()
char puffer1[100];
// char puffer2[100];
// char puffer3[100];
char puffer1[100]; //-V730_NOINIT
// fontsize for debugging window (remember: only 9, 11 or 14)
int fontsize;
// temporary pointer to Map-Object
Expand Down
6 changes: 3 additions & 3 deletions CIO/CFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ bobMAP* CFile::open_wld()
freadChecked(&myMap->width, 2, 1, fp);
freadChecked(&myMap->height, 2, 1, fp);

if((myMap->vertex = (point*)malloc(sizeof(point) * myMap->width * myMap->height)) == NULL)
if((myMap->vertex = (MapNode*)malloc(sizeof(MapNode) * myMap->width * myMap->height)) == NULL)
{
free(myMap);
return NULL;
Expand All @@ -560,7 +560,7 @@ bobMAP* CFile::open_wld()
{
Uint8 heightFactor;
freadChecked(&heightFactor, 1, 1, fp);
myMap->getVertex(i, j).h = heightFactor;
myMap->getVertex(i, j).h = heightFactor; //-V807
}
}
myMap->initVertexCoords();
Expand Down Expand Up @@ -829,7 +829,7 @@ bool CFile::save_wld(void* data)
{
for(int i = 0; i < myMap->width; i++)
{
temp = myMap->getVertex(i, j).z / 5 + 0x0A;
temp = myMap->getVertex(i, j).z / 5 + 0x0A; //-V807
fwrite(&temp, 1, 1, fp);
}
}
Expand Down
32 changes: 8 additions & 24 deletions CIO/CMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,15 @@ CMenu::CMenu(int pic_background)
CMenu::~CMenu()
{
for(int i = 0; i < MAXBUTTONS; i++)
{
if(buttons[i] != NULL)
delete buttons[i];
}
delete buttons[i];
for(int i = 0; i < MAXTEXTS; i++)
{
if(texts[i] != NULL)
delete texts[i];
}
delete texts[i];
for(int i = 0; i < MAXPICTURES; i++)
{
if(pictures[i] != NULL)
delete pictures[i];
}
delete pictures[i];
for(int i = 0; i < MAXTEXTFIELDS; i++)
{
if(textfields[i] != NULL)
delete textfields[i];
}
delete textfields[i];
for(int i = 0; i < MAXSELECTBOXES; i++)
{
if(selectboxes[i] != NULL)
delete selectboxes[i];
}
delete selectboxes[i];
SDL_FreeSurface(Surf_Menu);
}

Expand Down Expand Up @@ -357,10 +342,9 @@ bool CMenu::render()
}

// CSurface::Draw(Surf_Menu, global::bmpArray[pic_background].surface, 0, 0);
sge_TexturedRect(Surf_Menu, 0, 0, Surf_Menu->w - 1, 0, 0, Surf_Menu->h - 1, Surf_Menu->w - 1, Surf_Menu->h - 1,
global::bmpArray[pic_background].surface, 0, 0, global::bmpArray[pic_background].surface->w - 1, 0, 0,
global::bmpArray[pic_background].surface->h - 1, global::bmpArray[pic_background].surface->w - 1,
global::bmpArray[pic_background].surface->h - 1);
SDL_Surface* surfBG = global::bmpArray[pic_background].surface;
sge_TexturedRect(Surf_Menu, 0, 0, Surf_Menu->w - 1, 0, 0, Surf_Menu->h - 1, Surf_Menu->w - 1, Surf_Menu->h - 1, surfBG, 0, 0,
surfBG->w - 1, 0, 0, surfBG->h - 1, surfBG->w - 1, surfBG->h - 1);

for(int i = 0; i < MAXPICTURES; i++)
{
Expand Down
27 changes: 6 additions & 21 deletions CIO/CWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,15 @@ CWindow::CWindow(void callback(int), int callbackQuitMessage, Uint16 x, Uint16 y
CWindow::~CWindow()
{
for(int i = 0; i < MAXBUTTONS; i++)
{
if(buttons[i] != NULL)
delete buttons[i];
}
delete buttons[i];
for(int i = 0; i < MAXTEXTS; i++)
{
if(texts[i] != NULL)
delete texts[i];
}
delete texts[i];
for(int i = 0; i < MAXPICTURES; i++)
{
if(pictures[i] != NULL)
delete pictures[i];
}
delete pictures[i];
for(int i = 0; i < MAXTEXTFIELDS; i++)
{
if(textfields[i] != NULL)
delete textfields[i];
}
delete textfields[i];
for(int i = 0; i < MAXSELECTBOXES; i++)
{
if(selectboxes[i] != NULL)
delete selectboxes[i];
}
delete selectboxes[i];
SDL_FreeSurface(Surf_Window);
}

Expand Down Expand Up @@ -141,7 +126,7 @@ void CWindow::setMouseData(SDL_MouseMotionEvent motion)
// make sure to not move the window outside the display surface
if(x_ < 0)
x_ = 0;
if(x_ + w_ >= global::s2->getDisplaySurface()->w)
if(x_ + w_ >= global::s2->getDisplaySurface()->w) //-V807
x_ = global::s2->getDisplaySurface()->w - w_ - 1;
if(y_ < 0)
y_ = 0;
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ENDIF()

add_executable(s25edit ${MAIN_SOURCES} ${CIO_SOURCES} ${icon_RC})

target_link_libraries(s25edit SGE rttrConfig nowide-static ${SDL_LIBRARY})
target_link_libraries(s25edit SGE rttrConfig s25Common nowide-static ${SDL_LIBRARY})

if(RTTR_BINDIR)
INSTALL(TARGETS s25edit RUNTIME DESTINATION ${RTTR_BINDIR})
Expand Down
Loading

0 comments on commit 5f5fb04

Please sign in to comment.