Permalink
Browse files

CppCheck fixes

  • Loading branch information...
1 parent c44c93a commit 6c29bdbf2149a84cb2d471f244ad9c7a07759a04 @Broxzier Broxzier committed Nov 30, 2016
Showing with 823 additions and 1,118 deletions.
  1. +0 −1 resources/OpenRCT2.rc
  2. +14 −13 src/audio/mixer.cpp
  3. +1 −1 src/cmdline/ConvertCommand.cpp
  4. +1 −1 src/config.c
  5. +2 −7 src/core/Exception.hpp
  6. +2 −2 src/core/IStream.hpp
  7. +2 −2 src/core/Json.hpp
  8. +7 −7 src/core/Stopwatch.cpp
  9. +1 −2 src/core/String.cpp
  10. +1 −1 src/core/StringBuilder.hpp
  11. +1 −1 src/core/StringReader.hpp
  12. +1 −1 src/drawing/NewDrawing.cpp
  13. +0 −1 src/drawing/NewDrawing.h
  14. +2 −2 src/drawing/engines/SoftwareDrawingEngine.cpp
  15. +2 −2 src/drawing/engines/opengl/OpenGLShaderProgram.h
  16. +1 −2 src/drawing/engines/opengl/TextureCache.h
  17. +5 −13 src/drawing/sprite.c
  18. +3 −3 src/game.c
  19. +5 −5 src/interface/Theme.cpp
  20. +20 −20 src/interface/widget.c
  21. +18 −19 src/interface/window.c
  22. +1 −1 src/localisation/LanguagePack.cpp
  23. +1 −2 src/localisation/localisation.c
  24. +4 −6 src/management/award.c
  25. +31 −42 src/management/research.c
  26. +4 −4 src/network/NetworkPacket.cpp
  27. +3 −3 src/network/NetworkServerAdvertiser.cpp
  28. +4 −2 src/network/NetworkUser.cpp
  29. +7 −7 src/network/TcpSocket.cpp
  30. +2 −2 src/network/network.cpp
  31. +1 −1 src/object/ImageTable.cpp
  32. +3 −3 src/object/ObjectFactory.cpp
  33. +2 −2 src/object/ObjectManager.cpp
  34. +9 −9 src/object/ObjectRepository.cpp
  35. +1 −1 src/object/StringTable.cpp
  36. +1 −1 src/object/StringTable.h
  37. +1 −1 src/paint/map_element/entrance.c
  38. +0 −1 src/paint/map_element/fence.c
  39. +0 −1 src/paint/map_element/path.c
  40. +2 −3 src/paint/map_element/scenery_multiple.c
  41. +1 −3 src/paint/map_element/surface.c
  42. +0 −2 src/paint/map_element/surface.h
  43. +4 −4 src/peep/peep.c
  44. +6 −8 src/peep/staff.c
  45. +14 −18 src/platform/shared.c
  46. +2 −2 src/rct1/S4Importer.cpp
  47. +2 −2 src/rct2/S6Exporter.cpp
  48. +11 −11 src/rct2/S6Importer.cpp
  49. +2 −2 src/ride/TrackDesignRepository.cpp
  50. +2 −2 src/ride/coaster/air_powered_vertical_coaster.c
  51. +63 −63 src/ride/coaster/junior_roller_coaster.c
  52. +9 −9 src/ride/gentle/mini_golf.c
  53. +118 −202 src/ride/ride.c
  54. +1 −1 src/ride/ride_ratings.c
  55. +1 −1 src/ride/shops/facility.c
  56. +0 −2 src/ride/shops/misc.c
  57. +1 −1 src/ride/shops/shop.c
  58. +16 −26 src/ride/station.c
  59. +1 −2 src/ride/thrill/pirate_ship.c
  60. +2 −4 src/ride/track_design.c
  61. +7 −9 src/ride/track_paint.c
  62. +2 −4 src/ride/transport/monorail.c
  63. +2 −4 src/ride/vehicle.c
  64. +3 −3 src/scenario/ScenarioRepository.cpp
  65. +5 −7 src/scenario/scenario.c
  66. +17 −23 src/util/sawyercoding.c
  67. +1 −1 src/util/util.c
  68. +18 −3 src/windows/changelog.c
  69. +1 −2 src/windows/cheats.c
  70. +11 −21 src/windows/editor_inventions_list.c
  71. +15 −13 src/windows/editor_object_selection.c
  72. +5 −7 src/windows/editor_objective_options.c
  73. +7 −15 src/windows/editor_scenario_options.c
  74. +23 −34 src/windows/footpath.c
  75. +2 −2 src/windows/game_bottom_toolbar.c
  76. +1 −2 src/windows/guest_list.c
  77. +0 −1 src/windows/install_track.c
  78. +0 −1 src/windows/land_rights.c
  79. +9 −7 src/windows/loadsave.c
  80. +3 −5 src/windows/map.c
  81. +1 −2 src/windows/multiplayer.c
  82. +1 −5 src/windows/new_ride.c
  83. +1 −2 src/windows/options.c
  84. +6 −11 src/windows/park.c
  85. +129 −193 src/windows/ride.c
  86. +22 −23 src/windows/ride_construction.c
  87. +3 −3 src/windows/ride_list.c
  88. +12 −2 src/windows/server_list.c
  89. +9 −12 src/windows/staff_list.c
  90. +1 −3 src/windows/themes.c
  91. +1 −2 src/windows/tile_inspector.c
  92. +1 −1 src/windows/title_editor.c
  93. +10 −10 src/windows/title_scenarioselect.c
  94. +2 −2 src/windows/top_toolbar.c
  95. +0 −1 src/windows/track_list.c
  96. +4 −6 src/windows/track_place.c
  97. +5 −9 src/windows/viewport.c
  98. +0 −2 src/windows/water.c
  99. +3 −4 src/world/balloon.c
  100. +8 −13 src/world/footpath.c
  101. +11 −27 src/world/map.c
  102. +4 −4 src/world/map_helpers.c
  103. +12 −18 src/world/mapgen.c
  104. +7 −8 src/world/money_effect.c
  105. +6 −9 src/world/park.c
  106. +5 −9 src/world/sprite.c
  107. +0 −1 test/testpaint/String.cpp
  108. +5 −4 test/testpaint/TestPaint.cpp
  109. +0 −5 test/testpaint/TestTrack.cpp
@@ -67,4 +67,3 @@ IDI_ICON ICON "logo\\icon.ico"
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
-
View
@@ -229,7 +229,6 @@ unsigned long Source_SampleStream::Read(unsigned long offset, const uint8** data
if (newposition == -1) {
return 0;
}
- currentposition = newposition;
}
*data = buffer;
size_t read = SDL_RWread(rw, buffer, 1, length);
@@ -438,9 +437,11 @@ void Channel::SetGroup(int group)
}
Mixer::Mixer()
+ : deviceid(0)
+ , format({ 0 })
+ , effectbuffer(0)
+ , volume(1)
{
- effectbuffer = 0;
- volume = 1;
for (size_t i = 0; i < Util::CountOf(css1sources); i++) {
css1sources[i] = 0;
}
@@ -565,7 +566,7 @@ void Mixer::SetVolume(float volume)
void SDLCALL Mixer::Callback(void* arg, uint8* stream, int length)
{
- Mixer* mixer = (Mixer*)arg;
+ Mixer* mixer = static_cast<Mixer*>(arg);
memset(stream, 0, length);
std::list<Channel*>::iterator i = mixer->channels.begin();
while (i != mixer->channels.end()) {
@@ -574,7 +575,7 @@ void SDLCALL Mixer::Callback(void* arg, uint8* stream, int length)
delete (*i);
i = mixer->channels.erase(i);
} else {
- i++;
+ ++i;
}
}
}
@@ -845,15 +846,15 @@ void Mixer_Stop_Channel(void* channel)
{
if (gOpenRCT2Headless) return;
- gMixer.Stop(*(Channel*)channel);
+ gMixer.Stop(*static_cast<Channel*>(channel));
}
void Mixer_Channel_Volume(void* channel, int volume)
{
if (gOpenRCT2Headless) return;
gMixer.Lock();
- ((Channel*)channel)->SetVolume(volume);
+ static_cast<Channel*>(channel)->SetVolume(volume);
gMixer.Unlock();
}
@@ -862,7 +863,7 @@ void Mixer_Channel_Pan(void* channel, float pan)
if (gOpenRCT2Headless) return;
gMixer.Lock();
- ((Channel*)channel)->SetPan(pan);
+ static_cast<Channel*>(channel)->SetPan(pan);
gMixer.Unlock();
}
@@ -871,36 +872,36 @@ void Mixer_Channel_Rate(void* channel, double rate)
if (gOpenRCT2Headless) return;
gMixer.Lock();
- ((Channel*)channel)->SetRate(rate);
+ static_cast<Channel*>(channel)->SetRate(rate);
gMixer.Unlock();
}
int Mixer_Channel_IsPlaying(void* channel)
{
if (gOpenRCT2Headless) return false;
- return ((Channel*)channel)->IsPlaying();
+ return static_cast<Channel*>(channel)->IsPlaying();
}
unsigned long Mixer_Channel_GetOffset(void* channel)
{
if (gOpenRCT2Headless) return 0;
- return ((Channel*)channel)->GetOffset();
+ return static_cast<Channel*>(channel)->GetOffset();
}
int Mixer_Channel_SetOffset(void* channel, unsigned long offset)
{
if (gOpenRCT2Headless) return 0;
- return ((Channel*)channel)->SetOffset(offset);
+ return static_cast<Channel*>(channel)->SetOffset(offset);
}
void Mixer_Channel_SetGroup(void* channel, int group)
{
if (gOpenRCT2Headless) return;
- ((Channel*)channel)->SetGroup(group);
+ static_cast<Channel*>(channel)->SetGroup(group);
}
void* Mixer_Play_Music(int pathId, int loop, int streaming)
@@ -129,7 +129,7 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator * enumerat
scenario_begin();
}
}
- catch (Exception ex)
+ catch (const Exception &ex)
{
Console::Error::WriteLine(ex.GetMessage());
return EXITCODE_FAIL;
View
@@ -522,7 +522,7 @@ bool config_open(const utf8string path)
while ((c = rwopsreadc(file)) != EOF) {
if (c == '\n' || c == '\r') {
- lineBuffer[lineLength++] = 0;
+ lineBuffer[lineLength] = 0;
config_read_properties(&currentSection, (const_utf8string)lineBuffer);
lineLength = 0;
} else {
@@ -25,13 +25,8 @@ class Exception : public std::exception
{
public:
Exception() : Exception("") { }
-
- Exception(const char * message) : Exception(std::string(message)) { }
-
- Exception(const std::string &message) : std::exception()
- {
- _message = message;
- }
+ explicit Exception(const char * message) : Exception(std::string(message)) { }
+ explicit Exception(const std::string &message) : std::exception(), _message(message) { }
virtual ~Exception() { }
@@ -115,6 +115,6 @@ interface IStream
class IOException : public Exception
{
public:
- IOException(const char * message) : Exception(message) { }
- IOException(const std::string &message) : Exception(message) { }
+ explicit IOException(const char * message) : Exception(message) { }
+ explicit IOException(const std::string &message) : Exception(message) { }
};
View
@@ -36,9 +36,9 @@ class JsonException final : public Exception
json_error_t _jsonError = { 0 };
public:
- JsonException(const char * message) : Exception(message) { }
+ explicit JsonException(const char * message) : Exception(message) { }
- JsonException(const json_error_t * jsonError) : JsonException(jsonError->text)
+ explicit JsonException(const json_error_t * jsonError) : JsonException(jsonError->text)
{
_jsonError = *jsonError;
}
@@ -109,42 +109,42 @@ extern "C"
void stopwatch_dispose(stopwatch * stopwatch)
{
- delete ((Stopwatch*)stopwatch->context);
+ delete static_cast<Stopwatch *>(stopwatch->context);
}
uint64 stopwatch_GetElapsedTicks(stopwatch * stopwatch)
{
- Stopwatch * ctx = (Stopwatch*)stopwatch->context;
+ Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
return ctx->GetElapsedTicks();
}
uint64 stopwatch_GetElapsedMilliseconds(stopwatch * stopwatch)
{
- Stopwatch * ctx = (Stopwatch*)stopwatch->context;
+ Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
return ctx->GetElapsedMilliseconds();
}
void stopwatch_Reset(stopwatch * stopwatch)
{
- Stopwatch * ctx = (Stopwatch*)stopwatch->context;
+ Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
return ctx->Reset();
}
void stopwatch_Start(stopwatch * stopwatch)
{
- Stopwatch * ctx = (Stopwatch*)stopwatch->context;
+ Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
return ctx->Start();
}
void stopwatch_Restart(stopwatch * stopwatch)
{
- Stopwatch * ctx = (Stopwatch*)stopwatch->context;
+ Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
return ctx->Restart();
}
void stopwatch_Stop(stopwatch * stopwatch)
{
- Stopwatch * ctx = (Stopwatch*)stopwatch->context;
+ Stopwatch * ctx = static_cast<Stopwatch *>(stopwatch->context);
return ctx->Stop();
}
}
View
@@ -225,8 +225,6 @@ namespace String
utf8 * AppendFormat(utf8 * buffer, size_t bufferSize, const utf8 * format, ...)
{
- va_list args;
-
utf8 * dst = buffer;
size_t i;
for (i = 0; i < bufferSize; i++)
@@ -237,6 +235,7 @@ namespace String
if (i < bufferSize - 1)
{
+ va_list args;
va_start(args, format);
vsnprintf(dst, bufferSize - i - 1, format, args);
va_end(args);
@@ -36,7 +36,7 @@ class StringBuilder final
_length = 0;
}
- StringBuilder(size_t capacity) : StringBuilder()
+ explicit StringBuilder(size_t capacity) : StringBuilder()
{
EnsureCapacity(capacity);
}
@@ -34,7 +34,7 @@ interface IStringReader
class UTF8StringReader final : public IStringReader
{
public:
- UTF8StringReader(const utf8 * text)
+ explicit UTF8StringReader(const utf8 * text)
{
text = String::SkipBOM(text);
@@ -91,7 +91,7 @@ extern "C"
_drawingEngine->Initialise(gWindow);
_drawingEngine->SetUncappedFrameRate(gConfigGeneral.uncap_fps == 1);
}
- catch (Exception ex)
+ catch (const Exception &ex)
{
delete _drawingEngine;
_drawingEngine = nullptr;
@@ -44,4 +44,3 @@ void drawing_engine_set_fps_uncapped(bool uncapped);
#ifdef __cplusplus
}
#endif
-
@@ -165,7 +165,7 @@ class SoftwareDrawingContext final : public IDrawingContext
rct_drawpixelinfo * _dpi;
public:
- SoftwareDrawingContext(SoftwareDrawingEngine * engine);
+ explicit SoftwareDrawingContext(SoftwareDrawingEngine * engine);
~SoftwareDrawingContext() override;
IDrawingEngine * GetEngine() override;
@@ -221,7 +221,7 @@ class SoftwareDrawingEngine final : public IDrawingEngine
SoftwareDrawingContext * _drawingContext;
public:
- SoftwareDrawingEngine(bool hardwareDisplay)
+ explicit SoftwareDrawingEngine(bool hardwareDisplay)
{
_hardwareDisplay = hardwareDisplay;
_drawingContext = new SoftwareDrawingContext(this);
@@ -46,7 +46,8 @@ class OpenGLShaderProgram
OpenGLShader * _fragmentShader = nullptr;
public:
- OpenGLShaderProgram(const char * name);
+ explicit OpenGLShaderProgram(const char * name);
+ explicit OpenGLShaderProgram(const OpenGLShaderProgram&) = default;
virtual ~OpenGLShaderProgram();
GLuint GetAttributeLocation(const char * name);
@@ -56,4 +57,3 @@ class OpenGLShaderProgram
private:
bool Link();
};
-
@@ -35,8 +35,7 @@ struct GlyphId
{
size_t operator()(const GlyphId &k) const
{
- size_t hash = 0x3154A85E;
- hash = k.Image * 7;
+ size_t hash = k.Image * 7;
hash += (k.Palette & 0xFFFFFFFF) * 13;
hash += (k.Palette >> 32) * 23;
return hash;
View
@@ -69,12 +69,9 @@ bool gfx_load_g1()
{
log_verbose("loading g1 graphics");
- SDL_RWops *file;
- rct_g1_header header;
- unsigned int i;
-
- file = SDL_RWFromFile(get_file_path(PATH_ID_G1), "rb");
+ SDL_RWops *file = SDL_RWFromFile(get_file_path(PATH_ID_G1), "rb");
if (file != NULL) {
+ rct_g1_header header;
if (SDL_RWread(file, &header, 8, 1) == 1) {
/* We need to load in the data file, which has an `offset` field,
* which is supposed to hold a pointer, but is only 32 bit long.
@@ -116,7 +113,7 @@ bool gfx_load_g1()
SDL_RWclose(file);
// Fix entry data offsets
- for (i = 0; i < header.num_entries; i++)
+ for (unsigned int i = 0; i < header.num_entries; i++)
g1Elements[i].offset += (uintptr_t)_g1Buffer;
return true;
@@ -148,14 +145,11 @@ bool gfx_load_g2()
{
log_verbose("loading g2 graphics");
- SDL_RWops *file;
- unsigned int i;
-
char path[MAX_PATH];
platform_get_openrct_data_path(path, sizeof(path));
safe_strcat_path(path, "g2.dat", MAX_PATH);
- file = SDL_RWFromFile(path, "rb");
+ SDL_RWops *file = SDL_RWFromFile(path, "rb");
if (file != NULL) {
if (SDL_RWread(file, &g2.header, 8, 1) == 1) {
// Read element headers
@@ -170,7 +164,7 @@ bool gfx_load_g2()
SDL_RWclose(file);
// Fix entry data offsets
- for (i = 0; i < g2.header.num_entries; i++)
+ for (unsigned int i = 0; i < g2.header.num_entries; i++)
g2.elements[i].offset += (uintptr_t)g2.data;
return true;
@@ -447,7 +441,6 @@ void FASTCALL gfx_draw_sprite_palette_set_software(rct_drawpixelinfo *dpi, int i
if (height <= 0)return;
dest_start_y >>= zoom_level;
- dest_end_y >>= zoom_level;
//This will be the width of the drawn image
int width = g1_source->width;
@@ -486,7 +479,6 @@ void FASTCALL gfx_draw_sprite_palette_set_software(rct_drawpixelinfo *dpi, int i
}
dest_start_x >>= zoom_level;
- dest_end_x >>= zoom_level;
uint8* dest_pointer = (uint8*)dpi->bits;
//Move the pointer to the start point of the destination
Oops, something went wrong.

0 comments on commit 6c29bdb

Please sign in to comment.