Skip to content

Commit 2513e84

Browse files
committed
Various style fixed found using cppcheck
1 parent 106006f commit 2513e84

File tree

5 files changed

+9
-17
lines changed

5 files changed

+9
-17
lines changed

src/editor/editor.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,10 @@ Editor::check_save_prerequisites(const std::function<void ()>& callback) const
842842
if (sector->get_name() == "main")
843843
{
844844
sector_valid = true;
845-
for (const auto& spawnpoint : sector->get_objects_by_type<SpawnPointMarker>())
846-
{
847-
if (spawnpoint.get_name() == "main")
848-
{
849-
spawnpoint_valid = true;
850-
}
851-
}
845+
const auto& spawnpoints = sector->get_objects_by_type<SpawnPointMarker>();
846+
spawnpoint_valid = std::any_of(spawnpoints.begin(), spawnpoints.end(), [](const auto& spawnpoint) {
847+
return spawnpoint.get_name() == "main";
848+
});
852849
}
853850
}
854851

src/gui/menu_script.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ ScriptMenu::ScriptMenu(std::string* script_) :
3131
// Split the script to the lines.
3232
std::string script = *base_script;
3333
std::string line_break = "\n";
34-
std::string new_line;
3534
size_t endl_pos = script.find(line_break);
3635
while (endl_pos != std::string::npos) {
37-
new_line = script.substr(0, endl_pos);
36+
const auto& new_line = script.substr(0, endl_pos);
3837
script = script.substr(endl_pos + line_break.length());
3938
push_string(new_line);
4039
endl_pos = script.find(line_break);

src/interface/control_textbox.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "interface/control_textbox.hpp"
1818

1919
#include <math.h>
20+
#include <numeric>
2021

2122
#include <SDL.h>
2223

@@ -363,13 +364,8 @@ ControlTextbox::get_string() const
363364
std::string
364365
ControlTextbox::get_contents() const
365366
{
366-
std::string temp;
367-
368-
for (char c : m_charlist) {
369-
temp += c;
370-
}
371367

372-
return temp;
368+
return std::accumulate(m_charlist.begin(), m_charlist.end(), "");
373369
}
374370

375371
std::string

src/object/brick.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ Brick::try_break(Player* player)
104104
return;
105105

106106
SoundManager::current()->play("sounds/brick.wav", get_pos());
107-
Player& player_one = *Sector::get().get_players()[0];
108107
if (m_coin_counter > 0 ) {
109108
Sector::get().add<BouncyCoin>(get_pos(), true);
110109
m_coin_counter--;
110+
Player& player_one = *Sector::get().get_players()[0];
111111
player_one.get_status().add_coins(1);
112112
if (m_coin_counter == 0)
113113
m_sprite->set_action("empty");

src/supertux/command_line_arguments.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ void
7373
CommandLineArguments::print_acknowledgements() const
7474
{
7575
IFileStream in("ACKNOWLEDGEMENTS.txt");
76-
std::string line;
7776
if (in.good())
7877
{
78+
std::string line;
7979
while (std::getline(in, line))
8080
{
8181
std::cout << line << std::endl;

0 commit comments

Comments
 (0)