From 9db3809c7b46bce1b154c20900feb37d239644c5 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 31 Jan 2020 20:04:44 -0800 Subject: [PATCH 1/6] [clang-tidy] use bool literals where appropriate Found with modernize-use-bool-literals Signed-off-by: Rosen Penev --- src/player/CrossFade.cxx | 2 +- src/player/Thread.cxx | 2 +- src/playlist/plugins/SoundCloudPlaylistPlugin.cxx | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/player/CrossFade.cxx b/src/player/CrossFade.cxx index 7efed3e55..ce86d3f0a 100644 --- a/src/player/CrossFade.cxx +++ b/src/player/CrossFade.cxx @@ -44,7 +44,7 @@ mixramp_interpolate(const char *ramp_list, float required_db) noexcept * between the dB and seconds of a pair. * The dB values must be monotonically increasing for this to work. */ - while (1) { + while (true) { /* Parse the dB value. */ char *endptr; const float db = ParseFloat(ramp_list, &endptr); diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 9af45352b..6a3a90963 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -1155,7 +1155,7 @@ try { std::unique_lock lock(mutex); - while (1) { + while (true) { switch (command) { case PlayerCommand::SEEK: case PlayerCommand::QUEUE: diff --git a/src/playlist/plugins/SoundCloudPlaylistPlugin.cxx b/src/playlist/plugins/SoundCloudPlaylistPlugin.cxx index 454ba2ba4..0f23b2df8 100644 --- a/src/playlist/plugins/SoundCloudPlaylistPlugin.cxx +++ b/src/playlist/plugins/SoundCloudPlaylistPlugin.cxx @@ -177,11 +177,11 @@ SoundCloudJsonData::EndMap() noexcept { if (got_url > 1) { got_url--; - return 1; + return true; } if (got_url == 0) - return 1; + return true; /* got_url == 1, track finished, make it into a song */ got_url = 0; From 15fa780c99deaf4e6fb174c60c0ecce18ae8ee0e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 31 Jan 2020 20:09:15 -0800 Subject: [PATCH 2/6] [clang-tidy] convert several loops to range based ones Found with modernize-loop-convert Signed-off-by: Rosen Penev --- src/command/AllCommands.cxx | 8 ++++---- src/decoder/plugins/MadDecoderPlugin.cxx | 4 ++-- src/neighbor/Glue.cxx | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx index 8943f44e0..86830ed90 100644 --- a/src/command/AllCommands.cxx +++ b/src/command/AllCommands.cxx @@ -246,8 +246,8 @@ static CommandResult PrintAvailableCommands(Response &r, const Partition &partition, unsigned permission) noexcept { - for (unsigned i = 0; i < num_commands; ++i) { - const struct command *cmd = &commands[i]; + for (const auto & i : commands) { + const struct command *cmd = &i; if (cmd->permission == (permission & cmd->permission) && command_available(partition, cmd)) @@ -260,8 +260,8 @@ PrintAvailableCommands(Response &r, const Partition &partition, static CommandResult PrintUnavailableCommands(Response &r, unsigned permission) noexcept { - for (unsigned i = 0; i < num_commands; ++i) { - const struct command *cmd = &commands[i]; + for (const auto & i : commands) { + const struct command *cmd = &i; if (cmd->permission != (permission & cmd->permission)) r.Format("command: %s\n", cmd->cmd); diff --git a/src/decoder/plugins/MadDecoderPlugin.cxx b/src/decoder/plugins/MadDecoderPlugin.cxx index 8f8db69c0..e72841155 100644 --- a/src/decoder/plugins/MadDecoderPlugin.cxx +++ b/src/decoder/plugins/MadDecoderPlugin.cxx @@ -516,8 +516,8 @@ parse_xing(struct xing *xing, struct mad_bitptr *ptr, int *oldbitlen) noexcept if (xing->flags & XING_TOC) { if (bitlen < 800) return false; - for (unsigned i = 0; i < 100; ++i) - xing->toc[i] = mad_bit_read(ptr, 8); + for (unsigned char & i : xing->toc) + i = mad_bit_read(ptr, 8); bitlen -= 800; } diff --git a/src/neighbor/Glue.cxx b/src/neighbor/Glue.cxx index 69df3a195..992dab4dd 100644 --- a/src/neighbor/Glue.cxx +++ b/src/neighbor/Glue.cxx @@ -84,8 +84,8 @@ NeighborGlue::Open() void NeighborGlue::Close() noexcept { - for (auto i = explorers.begin(), end = explorers.end(); i != end; ++i) - i->explorer->Close(); + for (auto & explorer : explorers) + explorer.explorer->Close(); } NeighborGlue::List From afb29942b07a2fd217d802495bc4f3f3f320db45 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 31 Jan 2020 21:25:24 -0800 Subject: [PATCH 3/6] [clang-tidy] simplify boolean expressions Found with readability-simplify-boolean-expr Signed-off-by: Rosen Penev --- src/CommandLine.cxx | 2 +- src/db/plugins/ProxyDatabasePlugin.cxx | 5 +---- src/event/FullyBufferedSocket.cxx | 5 +---- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx index 6ea1980e7..cbaaeaa9a 100644 --- a/src/CommandLine.cxx +++ b/src/CommandLine.cxx @@ -283,7 +283,7 @@ static void help(void) "Options:\n"); for (const auto &i : option_defs) - if(i.HasDescription() == true) // hide hidden options from help print + if(i.HasDescription()) // hide hidden options from help print PrintOption(i); exit(EXIT_SUCCESS); diff --git a/src/db/plugins/ProxyDatabasePlugin.cxx b/src/db/plugins/ProxyDatabasePlugin.cxx index c3dfae850..c393fea72 100644 --- a/src/db/plugins/ProxyDatabasePlugin.cxx +++ b/src/db/plugins/ProxyDatabasePlugin.cxx @@ -863,10 +863,7 @@ IsFilterSupported(const ISongFilter &f) noexcept return true; const auto tag = Convert(t->GetTagType()); - if (tag == MPD_TAG_COUNT) - return false; - - return true; + return tag != MPD_TAG_COUNT; } else if (auto u = dynamic_cast(&f)) { if (u->IsNegated()) // TODO implement diff --git a/src/event/FullyBufferedSocket.cxx b/src/event/FullyBufferedSocket.cxx index d8ace8a2b..c095229cd 100644 --- a/src/event/FullyBufferedSocket.cxx +++ b/src/event/FullyBufferedSocket.cxx @@ -102,10 +102,7 @@ FullyBufferedSocket::OnSocketReady(unsigned flags) noexcept return false; } - if (!BufferedSocket::OnSocketReady(flags)) - return false; - - return true; + return BufferedSocket::OnSocketReady(flags); } void From 40d04206482891d53fbf39911824f02a79ec99cc Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 31 Jan 2020 21:03:57 -0800 Subject: [PATCH 4/6] [clang-tidy] convert several loops to const auto& Found with performance-for-range-copy Signed-off-by: Rosen Penev --- src/input/InputPlugin.cxx | 2 +- src/ls.cxx | 4 ++-- src/storage/StorageState.cxx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/input/InputPlugin.cxx b/src/input/InputPlugin.cxx index 547fd0dd7..4b0f61bfc 100644 --- a/src/input/InputPlugin.cxx +++ b/src/input/InputPlugin.cxx @@ -33,7 +33,7 @@ InputPlugin::SupportsUri(const char *uri) const noexcept if (StringStartsWithIgnoreCase(uri, *i)) return true; } else { - for (auto schema : protocols()) { + for (const auto& schema : protocols()) { if (StringStartsWithIgnoreCase(uri, schema.c_str())){ return true; } diff --git a/src/ls.cxx b/src/ls.cxx index 9e45e8b21..1b8e2ced2 100644 --- a/src/ls.cxx +++ b/src/ls.cxx @@ -39,7 +39,7 @@ void print_supported_uri_schemes_to_fp(FILE *fp) protocols.emplace(uri); }); - for (auto protocol : protocols) { + for (const auto& protocol : protocols) { fprintf(fp, " %s", protocol.c_str()); } fprintf(fp,"\n"); @@ -54,7 +54,7 @@ print_supported_uri_schemes(Response &r) protocols.emplace(uri); }); - for (auto protocol : protocols) { + for (const auto& protocol : protocols) { r.Format("handler: %s\n", protocol.c_str()); } } diff --git a/src/storage/StorageState.cxx b/src/storage/StorageState.cxx index b5fba35af..a93ed6f28 100644 --- a/src/storage/StorageState.cxx +++ b/src/storage/StorageState.cxx @@ -139,7 +139,7 @@ storage_state_get_hash(const Instance &instance) boost::crc_32_type result; - for (auto mount: mounts) { + for (const auto& mount : mounts) { result.process_bytes(mount.c_str(), mount.length()); } From 568deefd6814c233bf629f190290a657e66fbe33 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 31 Jan 2020 20:12:05 -0800 Subject: [PATCH 5/6] [clang-tidy] remove pointless void arg Found with modernize-redundant-void-arg Signed-off-by: Rosen Penev --- src/CommandLine.cxx | 4 ++-- src/LogInit.cxx | 2 +- src/archive/ArchiveList.cxx | 2 +- src/db/update/InotifyUpdate.cxx | 2 +- src/decoder/plugins/FlacDecoderPlugin.cxx | 2 +- src/decoder/plugins/MikmodDecoderPlugin.cxx | 8 ++++---- src/input/plugins/CdioParanoiaInputPlugin.cxx | 2 +- src/output/State.cxx | 2 +- src/output/plugins/JackOutputPlugin.cxx | 2 +- src/output/plugins/PulseOutputPlugin.cxx | 2 +- src/unix/Daemon.cxx | 8 ++++---- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx index 6ea1980e7..44843301d 100644 --- a/src/CommandLine.cxx +++ b/src/CommandLine.cxx @@ -107,7 +107,7 @@ static constexpr OptionDef option_defs[] = { static constexpr Domain cmdline_domain("cmdline"); gcc_noreturn -static void version(void) +static void version() { printf("Music Player Daemon " VERSION " (%s)" "\n" @@ -273,7 +273,7 @@ static void PrintOption(const OptionDef &opt) } gcc_noreturn -static void help(void) +static void help() { printf("Usage:\n" " mpd [OPTION...] [path/to/mpd.conf]\n" diff --git a/src/LogInit.cxx b/src/LogInit.cxx index b3dc89e31..629716f51 100644 --- a/src/LogInit.cxx +++ b/src/LogInit.cxx @@ -63,7 +63,7 @@ static void redirect_logs(int fd) } static int -open_log_file(void) +open_log_file() { assert(!out_path.IsNull()); diff --git a/src/archive/ArchiveList.cxx b/src/archive/ArchiveList.cxx index 50a3ccf6a..4e371c0bb 100644 --- a/src/archive/ArchiveList.cxx +++ b/src/archive/ArchiveList.cxx @@ -73,7 +73,7 @@ archive_plugin_from_name(const char *name) noexcept return nullptr; } -void archive_plugin_init_all(void) +void archive_plugin_init_all() { for (unsigned i = 0; archive_plugins[i] != nullptr; ++i) { const ArchivePlugin *plugin = archive_plugins[i]; diff --git a/src/db/update/InotifyUpdate.cxx b/src/db/update/InotifyUpdate.cxx index f982cbaac..af27b7bba 100644 --- a/src/db/update/InotifyUpdate.cxx +++ b/src/db/update/InotifyUpdate.cxx @@ -330,7 +330,7 @@ mpd_inotify_init(EventLoop &loop, Storage &storage, UpdateService &update, } void -mpd_inotify_finish(void) noexcept +mpd_inotify_finish() noexcept { if (inotify_source == nullptr) return; diff --git a/src/decoder/plugins/FlacDecoderPlugin.cxx b/src/decoder/plugins/FlacDecoderPlugin.cxx index 988d4ba0d..ca36180ad 100644 --- a/src/decoder/plugins/FlacDecoderPlugin.cxx +++ b/src/decoder/plugins/FlacDecoderPlugin.cxx @@ -102,7 +102,7 @@ flac_scan_stream(InputStream &is, TagHandler &handler) noexcept * Some glue code around FLAC__stream_decoder_new(). */ static FlacStreamDecoder -flac_decoder_new(void) +flac_decoder_new() { FlacStreamDecoder sd; if(!FLAC__stream_decoder_set_metadata_respond(sd.get(), FLAC__METADATA_TYPE_VORBIS_COMMENT)) diff --git a/src/decoder/plugins/MikmodDecoderPlugin.cxx b/src/decoder/plugins/MikmodDecoderPlugin.cxx index 94b94b0d1..e365adf69 100644 --- a/src/decoder/plugins/MikmodDecoderPlugin.cxx +++ b/src/decoder/plugins/MikmodDecoderPlugin.cxx @@ -38,24 +38,24 @@ static constexpr Domain mikmod_domain("mikmod"); static constexpr size_t MIKMOD_FRAME_SIZE = 4096; static BOOL -mikmod_mpd_init(void) +mikmod_mpd_init() { return VC_Init(); } static void -mikmod_mpd_exit(void) +mikmod_mpd_exit() { VC_Exit(); } static void -mikmod_mpd_update(void) +mikmod_mpd_update() { } static BOOL -mikmod_mpd_is_present(void) +mikmod_mpd_is_present() { return true; } diff --git a/src/input/plugins/CdioParanoiaInputPlugin.cxx b/src/input/plugins/CdioParanoiaInputPlugin.cxx index 00bd8c84a..4d1903571 100644 --- a/src/input/plugins/CdioParanoiaInputPlugin.cxx +++ b/src/input/plugins/CdioParanoiaInputPlugin.cxx @@ -162,7 +162,7 @@ parse_cdio_uri(const char *src) } static AllocatedPath -cdio_detect_device(void) +cdio_detect_device() { char **devices = cdio_get_devices_with_cap(nullptr, CDIO_FS_AUDIO, false); diff --git a/src/output/State.cxx b/src/output/State.cxx index e5da97d69..3f2c801f3 100644 --- a/src/output/State.cxx +++ b/src/output/State.cxx @@ -80,7 +80,7 @@ audio_output_state_read(const char *line, MultipleOutputs &outputs) } unsigned -audio_output_state_get_version(void) +audio_output_state_get_version() { return audio_output_state_version; } diff --git a/src/output/plugins/JackOutputPlugin.cxx b/src/output/plugins/JackOutputPlugin.cxx index d9c8634f4..4ce6a7a5e 100644 --- a/src/output/plugins/JackOutputPlugin.cxx +++ b/src/output/plugins/JackOutputPlugin.cxx @@ -419,7 +419,7 @@ JackOutput::Connect() } static bool -mpd_jack_test_default_device(void) +mpd_jack_test_default_device() { return true; } diff --git a/src/output/plugins/PulseOutputPlugin.cxx b/src/output/plugins/PulseOutputPlugin.cxx index 7bc4f3c31..2ae5a7d41 100644 --- a/src/output/plugins/PulseOutputPlugin.cxx +++ b/src/output/plugins/PulseOutputPlugin.cxx @@ -872,7 +872,7 @@ try { } static bool -pulse_output_test_default_device(void) +pulse_output_test_default_device() { return PulseOutput::TestDefaultDevice(); } diff --git a/src/unix/Daemon.cxx b/src/unix/Daemon.cxx index 1aea2034e..d20f7d7e1 100644 --- a/src/unix/Daemon.cxx +++ b/src/unix/Daemon.cxx @@ -66,7 +66,7 @@ static bool had_group = false; static int detach_fd = -1; void -daemonize_kill(void) +daemonize_kill() { if (pidfile.IsNull()) throw std::runtime_error("no pid_file specified in the config file"); @@ -85,14 +85,14 @@ daemonize_kill(void) } void -daemonize_close_stdin(void) +daemonize_close_stdin() { close(STDIN_FILENO); open("/dev/null", O_RDONLY); } void -daemonize_set_user(void) +daemonize_set_user() { if (user_name == nullptr) return; @@ -245,7 +245,7 @@ daemonize_init(const char *user, const char *group, AllocatedPath &&_pidfile) } void -daemonize_finish(void) +daemonize_finish() { if (!pidfile.IsNull()) { unlink(pidfile.c_str()); From ecad6d936adcecd6e094dc2054d2d32e6aeea141 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 31 Jan 2020 19:59:48 -0800 Subject: [PATCH 6/6] [clang-tidy] pass by value where appropriate Found with modernize-pass-by-value Signed-off-by: Rosen Penev --- src/archive/plugins/Bzip2ArchivePlugin.cxx | 7 ++++--- src/archive/plugins/Iso9660ArchivePlugin.cxx | 6 ++++-- src/db/VHelper.cxx | 5 +++-- src/db/VHelper.hxx | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/archive/plugins/Bzip2ArchivePlugin.cxx b/src/archive/plugins/Bzip2ArchivePlugin.cxx index 79c0bf138..1443b1f60 100644 --- a/src/archive/plugins/Bzip2ArchivePlugin.cxx +++ b/src/archive/plugins/Bzip2ArchivePlugin.cxx @@ -32,6 +32,7 @@ #include #include +#include class Bzip2ArchiveFile final : public ArchiveFile { std::string name; @@ -65,7 +66,7 @@ class Bzip2InputStream final : public InputStream { char buffer[5000]; public: - Bzip2InputStream(const std::shared_ptr &_input, + Bzip2InputStream(std::shared_ptr _input, const char *uri, Mutex &mutex); ~Bzip2InputStream() override; @@ -111,11 +112,11 @@ bz2_open(Path pathname) /* single archive handling */ -Bzip2InputStream::Bzip2InputStream(const std::shared_ptr &_input, +Bzip2InputStream::Bzip2InputStream(std::shared_ptr _input, const char *_uri, Mutex &_mutex) :InputStream(_uri, _mutex), - input(_input) + input(std::move(_input)) { Open(); } diff --git a/src/archive/plugins/Iso9660ArchivePlugin.cxx b/src/archive/plugins/Iso9660ArchivePlugin.cxx index eb76cc228..8e698ae4d 100644 --- a/src/archive/plugins/Iso9660ArchivePlugin.cxx +++ b/src/archive/plugins/Iso9660ArchivePlugin.cxx @@ -34,6 +34,8 @@ #include #include +#include + #define CEILING(x, y) ((x+(y-1))/y) struct Iso9660 { @@ -141,12 +143,12 @@ class Iso9660InputStream final : public InputStream { iso9660_stat_t *statbuf; public: - Iso9660InputStream(const std::shared_ptr &_iso, + Iso9660InputStream(std::shared_ptr _iso, const char *_uri, Mutex &_mutex, iso9660_stat_t *_statbuf) :InputStream(_uri, _mutex), - iso(_iso), statbuf(_statbuf) { + iso(std::move(_iso)), statbuf(_statbuf) { size = statbuf->size; seekable = true; SetReady(); diff --git a/src/db/VHelper.cxx b/src/db/VHelper.cxx index c412567be..83470fafa 100644 --- a/src/db/VHelper.cxx +++ b/src/db/VHelper.cxx @@ -23,14 +23,15 @@ #include "song/Filter.hxx" #include +#include #include #include #include -DatabaseVisitorHelper::DatabaseVisitorHelper(const DatabaseSelection &_selection, +DatabaseVisitorHelper::DatabaseVisitorHelper(DatabaseSelection _selection, VisitSong &visit_song) noexcept - :selection(_selection) + :selection(std::move(_selection)) { // TODO: apply URI and SongFilter assert(selection.uri.empty()); diff --git a/src/db/VHelper.hxx b/src/db/VHelper.hxx index 79e9041ea..1951a8f11 100644 --- a/src/db/VHelper.hxx +++ b/src/db/VHelper.hxx @@ -60,7 +60,7 @@ public: * @param visit_song the callback function passed to * Database::Visit(); may be replaced by this class */ - DatabaseVisitorHelper(const DatabaseSelection &selection, + DatabaseVisitorHelper(DatabaseSelection selection, VisitSong &visit_song) noexcept; ~DatabaseVisitorHelper() noexcept;