From b699d5a6303e164aab04f1a1d0990b978c15d87d Mon Sep 17 00:00:00 2001 From: Tobias Markus Date: Sun, 23 Nov 2014 21:44:52 +0100 Subject: [PATCH] [cppcheck] Part 2: Some further style fixes etc. --- src/addon/md5.cpp | 8 ++++---- src/audio/wav_sound_file.cpp | 8 +++----- src/badguy/yeti.cpp | 7 ++----- src/gui/dialog.cpp | 2 +- src/lisp/lexer.cpp | 1 + src/object/ambient_sound.cpp | 2 -- src/object/ambient_sound.hpp | 1 - src/object/rain_particle_system.cpp | 3 ++- src/physfs/ifile_streambuf.cpp | 1 + src/supertux/command_line_arguments.cpp | 3 +-- src/supertux/console.cpp | 3 +-- src/supertux/levelintro.cpp | 1 - src/supertux/screen_manager.cpp | 2 +- src/supertux/sector.cpp | 4 ++-- src/supertux/statistics.hpp | 1 - src/video/drawing_context.cpp | 4 ++-- src/video/gl/gl_lightmap.cpp | 2 +- src/video/gl/gl_painter.cpp | 8 ++++---- src/video/sdl/sdl_painter.cpp | 10 +++++----- src/video/texture_manager.cpp | 2 +- 20 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/addon/md5.cpp b/src/addon/md5.cpp index 3a95f2c85..93dd1df76 100644 --- a/src/addon/md5.cpp +++ b/src/addon/md5.cpp @@ -47,6 +47,8 @@ #include MD5::MD5() : + buffer(), + digest(), finalized() { init(); @@ -99,22 +101,20 @@ void MD5::update(FILE *file) { void MD5::update(std::istream& stream) { uint8_t buffer_[1024]; - int len; while (stream.good()) { stream.read((char*)buffer_, 1024); // note that return value of read is unusable. - len=stream.gcount(); + int len = stream.gcount(); update(buffer_, len); } } void MD5::update(std::ifstream& stream) { uint8_t buffer_[1024]; - int len; while (stream.good()) { stream.read((char*)buffer_, 1024); // note that return value of read is unusable. - len=stream.gcount(); + int len = stream.gcount(); update(buffer_, len); } } diff --git a/src/audio/wav_sound_file.cpp b/src/audio/wav_sound_file.cpp index c987516ed..a10495836 100644 --- a/src/audio/wav_sound_file.cpp +++ b/src/audio/wav_sound_file.cpp @@ -151,16 +151,14 @@ WavSoundFile::read(void* buffer, size_t buffer_size) return readsize; char *tmp = (char*)buffer; - size_t i; - char c; - for (i = 0; i < readsize / 2; i++) + for (size_t i = 0; i < readsize / 2; i++) { - c = tmp[2*i]; + char c = tmp[2*i]; tmp[2*i] = tmp[2*i+1]; tmp[2*i+1] = c; } - buffer = tmp; + *buffer = tmp; #endif return readsize; diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 3e5c420de..26c47d6f7 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -93,14 +93,12 @@ Yeti::draw(DrawingContext& context) void Yeti::draw_hit_points(DrawingContext& context) { - int i; - if (hud_head) { context.push_transform(); context.set_translation(Vector(0, 0)); - for (i = 0; i < hit_points; ++i) + for (int i = 0; i < hit_points; ++i) { context.draw_surface(hud_head, Vector(BORDER_X + (i * hud_head->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1); } @@ -246,10 +244,9 @@ Yeti::drop_stalactite() i != sector->gameobjects.end(); ++i) { YetiStalactite* stalactite = dynamic_cast(i->get()); if(stalactite && stalactite->is_hanging()) { - float distancex; if (hit_points >= 3) { // drop stalactites within 3 of player, going out with each jump - distancex = fabsf(stalactite->get_bbox().get_middle().x - player->get_bbox().get_middle().x); + float distancex = fabsf(stalactite->get_bbox().get_middle().x - player->get_bbox().get_middle().x); if(distancex < stomp_count*32) { stalactite->start_shaking(); } diff --git a/src/gui/dialog.cpp b/src/gui/dialog.cpp index e536c9cd3..47b9a0c1f 100644 --- a/src/gui/dialog.cpp +++ b/src/gui/dialog.cpp @@ -209,12 +209,12 @@ Dialog::draw(DrawingContext& ctx) { float segment_width = bg_rect.get_width() / m_buttons.size(); float button_width = segment_width; - float button_height = 24.0f; Vector pos(bg_rect.p1.x + segment_width/2.0f + i * segment_width, bg_rect.p2.y - 12); if (i == m_selected_button) { + float button_height = 24.0f; float blink = (sinf(real_time * M_PI * 1.0f)/2.0f + 0.5f) * 0.5f + 0.25f; ctx.draw_filled_rect(Rectf(Vector(pos.x - button_width/2, pos.y - button_height/2), Vector(pos.x + button_width/2, pos.y + button_height/2)).grown(2.0f), diff --git a/src/lisp/lexer.cpp b/src/lisp/lexer.cpp index 99ffa8151..daa219b3c 100644 --- a/src/lisp/lexer.cpp +++ b/src/lisp/lexer.cpp @@ -30,6 +30,7 @@ Lexer::Lexer(std::istream& newstream) : bufend(), bufpos(), c(), + token_string(), token_length() { // trigger a refill of the buffer diff --git a/src/object/ambient_sound.cpp b/src/object/ambient_sound.cpp index 76b257a36..e7474e68e 100644 --- a/src/object/ambient_sound.cpp +++ b/src/object/ambient_sound.cpp @@ -27,7 +27,6 @@ #include "util/reader.hpp" AmbientSound::AmbientSound(const Reader& lisp) : - name(), position(), dimension(), sample(), @@ -92,7 +91,6 @@ AmbientSound::AmbientSound(const Reader& lisp) : } AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std::string file) : - name(), position(), dimension(), sample(file), diff --git a/src/object/ambient_sound.hpp b/src/object/ambient_sound.hpp index e438ea9db..d58727ebb 100644 --- a/src/object/ambient_sound.hpp +++ b/src/object/ambient_sound.hpp @@ -86,7 +86,6 @@ protected: virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx); private: - std::string name; /**< user-defined name for use in scripts or empty string if not scriptable */ Vector position; Vector dimension; diff --git a/src/object/rain_particle_system.cpp b/src/object/rain_particle_system.cpp index 85cd01941..0457cf29a 100644 --- a/src/object/rain_particle_system.cpp +++ b/src/object/rain_particle_system.cpp @@ -71,8 +71,9 @@ void RainParticleSystem::update(float elapsed_time) //Create rainsplash if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)){ bool vertical = (col == 2); - int splash_x, splash_y; if (!vertical) { //check if collision happened from above + int splash_x, splash_y; // move outside if statement when + // uncommenting the else statement below. splash_x = int(particle->pos.x); splash_y = int(particle->pos.y) - (int(particle->pos.y) % 32) + 32; Sector::current()->add_object(std::make_shared(Vector(splash_x, splash_y),vertical)); diff --git a/src/physfs/ifile_streambuf.cpp b/src/physfs/ifile_streambuf.cpp index 224f37d1d..e856f3e49 100644 --- a/src/physfs/ifile_streambuf.cpp +++ b/src/physfs/ifile_streambuf.cpp @@ -22,6 +22,7 @@ #include IFileStreambuf::IFileStreambuf(const std::string& filename) : + buf(), file() { // check this as PHYSFS seems to be buggy and still returns a diff --git a/src/supertux/command_line_arguments.cpp b/src/supertux/command_line_arguments.cpp index 6c14e02a8..843f23d52 100644 --- a/src/supertux/command_line_arguments.cpp +++ b/src/supertux/command_line_arguments.cpp @@ -59,10 +59,9 @@ CommandLineArguments::print_datadir() // Print the datadir searchpath to stdout, one path per // line. Then exit. Intended for use by the supertux-editor. char **sp; - size_t sp_index; sp = PHYSFS_getSearchPath(); if (sp) - for (sp_index = 0; sp[sp_index]; sp_index++) + for (size_t sp_index = 0; sp[sp_index]; sp_index++) std::cout << sp[sp_index] << std::endl; PHYSFS_freeList(sp); } diff --git a/src/supertux/console.cpp b/src/supertux/console.cpp index 43d09e7f4..1d27bc87b 100644 --- a/src/supertux/console.cpp +++ b/src/supertux/console.cpp @@ -424,10 +424,9 @@ Console::parse(std::string s) // split line into list of args std::vector args; - size_t start = 0; size_t end = 0; while (1) { - start = s.find_first_not_of(" ,", end); + size_t start = s.find_first_not_of(" ,", end); end = s.find_first_of(" ,", start); if (start == s.npos) break; args.push_back(s.substr(start, end-start)); diff --git a/src/supertux/levelintro.cpp b/src/supertux/levelintro.cpp index 8d00022ef..311387d17 100644 --- a/src/supertux/levelintro.cpp +++ b/src/supertux/levelintro.cpp @@ -142,7 +142,6 @@ LevelIntro::draw(DrawingContext& context) std::stringstream ss; ss << _("Level target time") << ": " << Statistics::time_to_string(level->target_time); context.draw_center_text(Resources::normal_font, ss.str(), Vector(0, py), LAYER_FOREGROUND1,LevelIntro::stat_color); - py += static_cast(Resources::normal_font->get_height()); } } diff --git a/src/supertux/screen_manager.cpp b/src/supertux/screen_manager.cpp index 580d8753a..dd1cbf7c7 100644 --- a/src/supertux/screen_manager.cpp +++ b/src/supertux/screen_manager.cpp @@ -128,7 +128,6 @@ ScreenManager::draw(DrawingContext& context) assert(!m_screen_stack.empty()); static Uint32 fps_ticks = SDL_GetTicks(); - static int frame_count = 0; m_screen_stack.back()->draw(context); m_menu_manager->draw(context); @@ -156,6 +155,7 @@ ScreenManager::draw(DrawingContext& context) /* Calculate frames per second */ if (g_config->show_fps) { + static int frame_count = 0; ++frame_count; if (SDL_GetTicks() - fps_ticks >= 500) diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 3e0c44ead..73d3cce97 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -228,7 +228,7 @@ Sector::parse(const Reader& sector) update_game_objects(); - if(solid_tilemaps.size() < 1) { log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; } + if(solid_tilemaps.empty()) { log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; } fix_old_tiles(); if(!camera) { @@ -393,7 +393,7 @@ Sector::parse_old_format(const Reader& reader) update_game_objects(); - if(solid_tilemaps.size() < 1) { log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; } + if(solid_tilemaps.empty()) { log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; } fix_old_tiles(); update_game_objects(); diff --git a/src/supertux/statistics.hpp b/src/supertux/statistics.hpp index 964b055e7..85d97902c 100644 --- a/src/supertux/statistics.hpp +++ b/src/supertux/statistics.hpp @@ -24,7 +24,6 @@ #include "video/color.hpp" #include "video/surface_ptr.hpp" -namespace lisp { class Writer; } namespace lisp { class Lisp; } class DrawingContext; diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index f600246ed..faa95ddf5 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -385,7 +385,7 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests_) break; case TEXT: { - const TextRequest* textrequest = (TextRequest*) request.request_data; + const TextRequest* textrequest = static_cast(request.request_data); textrequest->font->draw(&renderer, textrequest->text, request.pos, textrequest->alignment, request.drawing_effect, request.color, request.alpha); } @@ -417,7 +417,7 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests_) break; case TEXT: { - const TextRequest* textrequest = (TextRequest*) request.request_data; + const TextRequest* textrequest = static_cast(request.request_data); textrequest->font->draw(&renderer, textrequest->text, request.pos, textrequest->alignment, request.drawing_effect, request.color, request.alpha); } diff --git a/src/video/gl/gl_lightmap.cpp b/src/video/gl/gl_lightmap.cpp index b5251e076..97cf70aa0 100644 --- a/src/video/gl/gl_lightmap.cpp +++ b/src/video/gl/gl_lightmap.cpp @@ -180,7 +180,7 @@ void GLLightmap::get_light(const DrawingRequest& request) const { const GetLightRequest* getlightrequest - = (GetLightRequest*) request.request_data; + = static_cast(request.request_data); float pixels[3]; for( int i = 0; i<3; i++) diff --git a/src/video/gl/gl_painter.cpp b/src/video/gl/gl_painter.cpp index ecb3cb177..70150dfd1 100644 --- a/src/video/gl/gl_painter.cpp +++ b/src/video/gl/gl_painter.cpp @@ -142,7 +142,7 @@ void GLPainter::draw_surface_part(const DrawingRequest& request) { const SurfacePartRequest* surfacepartrequest - = (SurfacePartRequest*) request.request_data; + = static_cast(request.request_data); const Surface* surface = surfacepartrequest->surface; std::shared_ptr gltexture = std::dynamic_pointer_cast(surface->get_texture()); GLSurfaceData *surface_data = reinterpret_cast(surface->get_surface_data()); @@ -178,7 +178,7 @@ void GLPainter::draw_gradient(const DrawingRequest& request) { const GradientRequest* gradientrequest - = (GradientRequest*) request.request_data; + = static_cast(request.request_data); const Color& top = gradientrequest->top; const Color& bottom = gradientrequest->bottom; @@ -215,7 +215,7 @@ void GLPainter::draw_filled_rect(const DrawingRequest& request) { const FillRectRequest* fillrectrequest - = (FillRectRequest*) request.request_data; + = static_cast(request.request_data); glDisable(GL_TEXTURE_2D); glColor4f(fillrectrequest->color.red, fillrectrequest->color.green, @@ -294,7 +294,7 @@ GLPainter::draw_filled_rect(const DrawingRequest& request) void GLPainter::draw_inverse_ellipse(const DrawingRequest& request) { - const InverseEllipseRequest* ellipse = (InverseEllipseRequest*)request.request_data; + const InverseEllipseRequest* ellipse = static_cast (request.request_data); glDisable(GL_TEXTURE_2D); glColor4f(ellipse->color.red, ellipse->color.green, diff --git a/src/video/sdl/sdl_painter.cpp b/src/video/sdl/sdl_painter.cpp index 0da8c2860..5a68c5a5e 100644 --- a/src/video/sdl/sdl_painter.cpp +++ b/src/video/sdl/sdl_painter.cpp @@ -93,8 +93,8 @@ void SDLPainter::draw_surface_part(SDL_Renderer* renderer, const DrawingRequest& request) { //FIXME: support parameters request.blend - const SurfacePartRequest* surface = (const SurfacePartRequest*) request.request_data; - const SurfacePartRequest* surfacepartrequest = (SurfacePartRequest*) request.request_data; + const SurfacePartRequest* surface = static_cast(request.request_data); + const SurfacePartRequest* surfacepartrequest = static_cast(request.request_data); std::shared_ptr sdltexture = std::dynamic_pointer_cast(surface->surface->get_texture()); @@ -136,7 +136,7 @@ void SDLPainter::draw_gradient(SDL_Renderer* renderer, const DrawingRequest& request) { const GradientRequest* gradientrequest - = (GradientRequest*) request.request_data; + = static_cast(request.request_data); const Color& top = gradientrequest->top; const Color& bottom = gradientrequest->bottom; @@ -170,7 +170,7 @@ void SDLPainter::draw_filled_rect(SDL_Renderer* renderer, const DrawingRequest& request) { const FillRectRequest* fillrectrequest - = (FillRectRequest*) request.request_data; + = static_cast(request.request_data); SDL_Rect rect; rect.x = request.pos.x; @@ -246,7 +246,7 @@ SDLPainter::draw_filled_rect(SDL_Renderer* renderer, const DrawingRequest& reque void SDLPainter::draw_inverse_ellipse(SDL_Renderer* renderer, const DrawingRequest& request) { - const InverseEllipseRequest* ellipse = (InverseEllipseRequest*)request.request_data; + const InverseEllipseRequest* ellipse = static_cast(request.request_data); float x = request.pos.x; float w = ellipse->size.x; diff --git a/src/video/texture_manager.cpp b/src/video/texture_manager.cpp index e54490919..e7c392f6f 100644 --- a/src/video/texture_manager.cpp +++ b/src/video/texture_manager.cpp @@ -224,7 +224,7 @@ TextureManager::create_dummy_texture() SDLSurfacePtr image(SDL_CreateRGBSurface(0, 1024, 1024, 8, 0, 0, 0, 0)); if (!image) { - throw err; + throw; } else { -- 2.11.0