Skip to content

Commit 5cb721b

Browse files
committed
Fix some more clang-tidy warnings
1 parent a03f1d2 commit 5cb721b

10 files changed

+28
-29
lines changed

Diff for: .clang-tidy

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
Checks: 'clang-diagnostic-*,clang-analyzer-*,portability-*,performance-*,bugprone-*,misc-*,-misc-unused-parameters'
3-
WarningsAsErrors: '*,-bugprone-parent-virtual-call'
3+
WarningsAsErrors: '*,-bugprone-parent-virtual-call,-clang-analyzer-optin.cplusplus.VirtualCall'
44
HeaderFilterRegex: 'src/.*hpp'
55
AnalyzeTemporaryDtors: true
66
...

Diff for: src/audio/sound_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
SoundManager::SoundManager() :
3131
m_device(alcOpenDevice(nullptr)),
32-
m_context(alcCreateContext(m_device, /* attributes = */ nullptr)),
32+
m_context(alcCreateContext(m_device, nullptr)),
3333
m_sound_enabled(false),
3434
m_sound_volume(0),
3535
m_buffers(),

Diff for: src/editor/object_settings.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ ObjectSettings::add_sprite(const std::string& text, std::string* value_ptr,
242242
boost::optional<std::string> default_value,
243243
unsigned int flags)
244244
{
245-
add_file(text, value_ptr, key, default_value, {".jpg", ".png", ".sprite"}, {}, flags);
245+
add_file(text, value_ptr, key, std::move(default_value), {".jpg", ".png", ".sprite"}, {}, flags);
246246
}
247247

248248
void
@@ -251,7 +251,7 @@ ObjectSettings::add_surface(const std::string& text, std::string* value_ptr,
251251
boost::optional<std::string> default_value,
252252
unsigned int flags)
253253
{
254-
add_file(text, value_ptr, key, default_value, {".jpg", ".png", ".surface"}, {}, flags);
254+
add_file(text, value_ptr, key, std::move(default_value), {".jpg", ".png", ".surface"}, {}, flags);
255255
}
256256

257257
void
@@ -260,7 +260,7 @@ ObjectSettings::add_sound(const std::string& text, std::string* value_ptr,
260260
boost::optional<std::string> default_value,
261261
unsigned int flags)
262262
{
263-
add_file(text, value_ptr, key, default_value, {".wav", ".ogg"}, {}, flags);
263+
add_file(text, value_ptr, key, std::move(default_value), {".wav", ".ogg"}, {}, flags);
264264
}
265265

266266
void
@@ -269,12 +269,12 @@ ObjectSettings::add_music(const std::string& text, std::string* value_ptr,
269269
boost::optional<std::string> default_value,
270270
unsigned int flags)
271271
{
272-
add_file(text, value_ptr, key, default_value, {".ogg", ".music"}, {}, flags);
272+
add_file(text, value_ptr, key, std::move(default_value), {".ogg", ".music"}, {}, flags);
273273
}
274274

275275
void
276276
ObjectSettings::add_worldmap(const std::string& text, std::string* value_ptr, const std::string& key,
277-
unsigned int flags)
277+
unsigned int flags)
278278
{
279279
add_file(text, value_ptr, key, {}, {".stwm"}, {}, flags);
280280
}

Diff for: src/editor/toolbox_widget.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ EditorToolboxWidget::normalize_selection() const
210210
{
211211
Vector drag_start_ = m_drag_start;
212212
Vector drag_end = Vector(static_cast<float>(m_hovered_tile % 4),
213-
static_cast<float>(m_hovered_tile / 4));
213+
static_cast<float>(m_hovered_tile / 4)); // NOLINT
214214
if (drag_start_.x > drag_end.x) {
215215
std::swap(drag_start_.x, drag_end.x);
216216
}
@@ -310,7 +310,7 @@ EditorToolboxWidget::on_mouse_button_down(const SDL_MouseButtonEvent& button)
310310
{
311311
m_dragging = true;
312312
m_drag_start = Vector(static_cast<float>(m_hovered_tile % 4),
313-
static_cast<float>(m_hovered_tile / 4));
313+
static_cast<float>(m_hovered_tile / 4)); // NOLINT
314314
int size = static_cast<int>(m_active_tilegroup->tiles.size());
315315
int tile_pos = m_hovered_tile + m_starting_tile;
316316
if (tile_pos < size && tile_pos >= 0) {

Diff for: src/gui/item_back.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ ItemBack::ItemBack(const std::string& text, int id) :
2828
}
2929

3030
void
31-
ItemBack::draw(DrawingContext& context, const Vector& pos, int menu_width, bool active) {
31+
ItemBack::draw(DrawingContext& context, const Vector& pos, int menu_width, bool active)
32+
{
3233
float text_width = Resources::normal_font->get_text_width(get_text());
3334
context.color().draw_text(Resources::normal_font, get_text(),
3435
Vector( pos.x + static_cast<float>(menu_width) / 2.0f,
3536
pos.y - static_cast<float>(int(Resources::normal_font->get_height()/2))),
3637
ALIGN_CENTER, LAYER_GUI, active ? ColorScheme::Menu::active_color : get_color());
3738
context.color().draw_surface(Resources::back,
38-
Vector(pos.x + static_cast<float>(menu_width / 2) + text_width / 2.0f + 16.0f,
39+
Vector(pos.x + static_cast<float>(menu_width) / 2.0f + text_width / 2.0f + 16.0f,
3940
pos.y - 8.0f),
4041
LAYER_GUI);
4142
}

Diff for: src/object/decal.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Decal::Decal(const ReaderMapping& reader) :
2424
default_action("default"),
2525
solid()
2626
{
27-
m_layer = reader_get_layer (reader, /* default = */ LAYER_OBJECTS);
27+
m_layer = reader_get_layer(reader, LAYER_OBJECTS);
2828

2929
reader.get("solid", solid, false);
3030
if (solid)

Diff for: src/supertux/command_line_arguments.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,11 @@ CommandLineArguments::parse_args(int argc, char** argv)
242242
}
243243
else
244244
{
245-
float aspect_ratio = static_cast<float>(aspect_width) / static_cast<float>(aspect_height);
246-
247245
// use aspect ratio to calculate logical resolution
248-
if (aspect_ratio > 1) {
249-
aspect_size = Size(static_cast<int>(600 * aspect_ratio + 0.5f),
250-
600);
246+
if (aspect_width / aspect_height > 1) {
247+
aspect_size = Size(600 * aspect_width / aspect_height, 600);
251248
} else {
252-
aspect_size = Size(600,
253-
static_cast<int>(600 * 1/aspect_ratio + 0.5f));
249+
aspect_size = Size(600, 600 * aspect_height / aspect_width);
254250
}
255251
}
256252
}
@@ -398,7 +394,7 @@ CommandLineArguments::parse_args(int argc, char** argv)
398394
void
399395
CommandLineArguments::merge_into(Config& config)
400396
{
401-
#define merge_option(x) if (x) { config.x = *x; }
397+
#define merge_option(x) if (x) { config.x = *(x); }
402398

403399
merge_option(fullscreen_size);
404400
merge_option(fullscreen_refresh_rate);

Diff for: src/supertux/menu/addon_menu.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828

2929
namespace {
3030

31-
#define IS_REPOSITORY_MENU_ID(idx) ((idx - MNID_ADDON_LIST_START) % 2 == 0)
32-
#define IS_INSTALLED_MENU_ID(idx) ((idx - MNID_ADDON_LIST_START) % 2 == 1)
31+
#define IS_REPOSITORY_MENU_ID(idx) (((idx) - MNID_ADDON_LIST_START) % 2 == 0)
32+
#define IS_INSTALLED_MENU_ID(idx) (((idx) - MNID_ADDON_LIST_START) % 2 == 1)
3333

34-
#define MAKE_REPOSITORY_MENU_ID(idx) (MNID_ADDON_LIST_START + 2*idx+0)
35-
#define MAKE_INSTALLED_MENU_ID(idx) (MNID_ADDON_LIST_START + 2*idx+1)
34+
#define MAKE_REPOSITORY_MENU_ID(idx) (MNID_ADDON_LIST_START + 2 * (idx) + 0)
35+
#define MAKE_INSTALLED_MENU_ID(idx) (MNID_ADDON_LIST_START + 2 * (idx) + 1)
3636

37-
#define UNPACK_REPOSITORY_MENU_ID(idx) (((idx - MNID_ADDON_LIST_START) - 0) / 2)
38-
#define UNPACK_INSTALLED_MENU_ID(idx) (((idx - MNID_ADDON_LIST_START) - 1) / 2)
37+
#define UNPACK_REPOSITORY_MENU_ID(idx) ((((idx) - MNID_ADDON_LIST_START) - 0) / 2)
38+
#define UNPACK_INSTALLED_MENU_ID(idx) ((((idx) - MNID_ADDON_LIST_START) - 1) / 2)
3939

4040
std::string addon_type_to_translated_string(Addon::Type type)
4141
{

Diff for: src/util/utf8_iterator.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ uint32_t decode_utf8(const std::string& text, size_t& p)
4343
{
4444
uint32_t c1 = static_cast<unsigned char>(text[p+0]);
4545

46-
if (has_multibyte_mark(static_cast<unsigned char>(c1))) std::runtime_error("Malformed utf-8 sequence");
46+
if (has_multibyte_mark(static_cast<unsigned char>(c1))) {
47+
throw std::runtime_error("Malformed utf-8 sequence");
48+
}
4749

4850
if ((c1 & 0200) == 0000) {
4951
// 0xxx.xxxx: 1 byte sequence

Diff for: tests/random_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ TEST(RandomTest, rand1f)
4848
random.seed(0);
4949
for(int i = 0; i < 1000; ++i)
5050
{
51-
int v = random.randf(10);
51+
float v = random.randf(10);
5252
ASSERT_LE(0.0f, v);
5353
ASSERT_LT(v, 10.0f);
5454
}
@@ -60,7 +60,7 @@ TEST(RandomTest, rand2f)
6060
random.seed(0);
6161
for(int i = 0; i < 1000; ++i)
6262
{
63-
int v = random.randf(10.0f, 20.0f);
63+
float v = random.randf(10.0f, 20.0f);
6464
ASSERT_LE(10.0f, v);
6565
ASSERT_LT(v, 20.0f);
6666
}

0 commit comments

Comments
 (0)