From 49370105577181b8dd33c38797806c22571214eb Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 14 Apr 2021 16:09:46 +0200 Subject: [PATCH] Fix some of the clang-tidy lints --- src/common/communication/vst3.h | 1 + src/common/serialization/vst2.cpp | 8 +++++--- src/common/serialization/vst3/bstream.cpp | 16 +++++++++------- src/common/serialization/vst3/event-list.cpp | 8 +++++--- .../serialization/vst3/param-value-queue.cpp | 4 ++-- .../serialization/vst3/parameter-changes.cpp | 4 ++-- src/common/serialization/vst3/process-data.cpp | 11 +++++++---- src/plugin/bridges/vst3-impls/plugin-proxy.cpp | 2 +- src/plugin/bridges/vst3.cpp | 2 +- src/plugin/utils.cpp | 1 + src/plugin/vst3-plugin.cpp | 1 + src/wine-host/bridges/vst2.cpp | 5 ++++- src/wine-host/bridges/vst3.cpp | 1 + 13 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/common/communication/vst3.h b/src/common/communication/vst3.h index 9460b52c..53449f91 100644 --- a/src/common/communication/vst3.h +++ b/src/common/communication/vst3.h @@ -304,6 +304,7 @@ class Vst3Sockets : public Sockets { listen), io_context(io_context) {} + // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.VirtualCall) ~Vst3Sockets() { close(); } void connect() override { diff --git a/src/common/serialization/vst2.cpp b/src/common/serialization/vst2.cpp index 319145ba..9323fa68 100644 --- a/src/common/serialization/vst2.cpp +++ b/src/common/serialization/vst2.cpp @@ -36,14 +36,16 @@ VstEvents& DynamicVstEvents::as_c_events() { // number of events minus one pointers. static_assert(std::extent_v == 1); const size_t buffer_size = - sizeof(VstEvents) + ((events.size() - 1) * sizeof(VstEvent*)); + sizeof(VstEvents) + + ((events.size() - 1) * + sizeof(VstEvent*)); // NOLINT(bugprone-sizeof-expression) vst_events_buffer.resize(buffer_size); // Now we can populate the VLA with pointers to the objects in the `events` // vector VstEvents* vst_events = reinterpret_cast(vst_events_buffer.data()); - vst_events->numEvents = events.size(); + vst_events->numEvents = static_cast(events.size()); std::transform(events.begin(), events.end(), vst_events->events, [](VstEvent& event) -> VstEvent* { return &event; }); @@ -76,7 +78,7 @@ VstSpeakerArrangement& DynamicSpeakerArrangement::as_c_speaker_arrangement() { reinterpret_cast( speaker_arrangement_buffer.data()); speaker_arrangement->flags = flags; - speaker_arrangement->num_speakers = speakers.size(); + speaker_arrangement->num_speakers = static_cast(speakers.size()); std::copy(speakers.begin(), speakers.end(), speaker_arrangement->speakers); return *speaker_arrangement; diff --git a/src/common/serialization/vst3/bstream.cpp b/src/common/serialization/vst3/bstream.cpp index 312f8e4a..6518674b 100644 --- a/src/common/serialization/vst3/bstream.cpp +++ b/src/common/serialization/vst3/bstream.cpp @@ -40,7 +40,8 @@ YaBStream::YaBStream(Steinberg::IBStream* stream) { int32 num_bytes_read = 0; buffer.resize(size); stream->seek(0, Steinberg::IBStream::IStreamSeekMode::kIBSeekSet); - stream->read(buffer.data(), size, &num_bytes_read); + stream->read(buffer.data(), static_cast(size), + &num_bytes_read); assert(num_bytes_read == 0 || num_bytes_read == size); } } @@ -103,7 +104,8 @@ tresult YaBStream::write_back(Steinberg::IBStream* stream) const { // A `stream->seek(0, kIBSeekSet)` breaks restoring states in Bitwig. Not // sure if Bitwig is prepending a header or if this is expected behaviour. int32 num_bytes_written = 0; - if (stream->write(const_cast(buffer.data()), buffer.size(), + if (stream->write(const_cast(buffer.data()), + static_cast(buffer.size()), &num_bytes_written) == Steinberg::kResultOk) { // Some implementations will return `kResultFalse` when writing 0 bytes assert(num_bytes_written == 0 || @@ -145,7 +147,7 @@ tresult PLUGIN_API YaBStream::read(void* buffer, seek_position += bytes_to_read; if (numBytesRead) { - *numBytesRead = bytes_to_read; + *numBytesRead = static_cast(bytes_to_read); } return Steinberg::kResultOk; @@ -163,7 +165,7 @@ tresult PLUGIN_API YaBStream::write(void* buffer, } std::copy_n(reinterpret_cast(buffer), numBytes, - this->buffer.begin() + seek_position); + this->buffer.begin() + static_cast(seek_position)); seek_position += numBytes; if (numBytesWritten) { @@ -190,7 +192,7 @@ tresult PLUGIN_API YaBStream::seek(int64 pos, int32 mode, int64* result) { } if (result) { - *result = seek_position; + *result = static_cast(seek_position); } return Steinberg::kResultOk; @@ -198,7 +200,7 @@ tresult PLUGIN_API YaBStream::seek(int64 pos, int32 mode, int64* result) { tresult PLUGIN_API YaBStream::tell(int64* pos) { if (pos) { - *pos = seek_position; + *pos = static_cast(seek_position); return Steinberg::kResultOk; } else { return Steinberg::kInvalidArgument; @@ -206,7 +208,7 @@ tresult PLUGIN_API YaBStream::tell(int64* pos) { } tresult PLUGIN_API YaBStream::getStreamSize(int64& size) { - size = seek_position; + size = static_cast(seek_position); return Steinberg::kResultOk; } diff --git a/src/common/serialization/vst3/event-list.cpp b/src/common/serialization/vst3/event-list.cpp index 10aca0f7..afea7227 100644 --- a/src/common/serialization/vst3/event-list.cpp +++ b/src/common/serialization/vst3/event-list.cpp @@ -215,7 +215,7 @@ IMPLEMENT_FUNKNOWN_METHODS(YaEventList, #pragma GCC diagnostic pop int32 PLUGIN_API YaEventList::getEventCount() { - return events.size(); + return static_cast(events.size()); } tresult PLUGIN_API YaEventList::getEvent(int32 index, @@ -231,8 +231,10 @@ tresult PLUGIN_API YaEventList::getEvent(int32 index, if (index >= static_cast(num_already_reconstructed_events)) { reconstructed_events.resize(events.size()); std::transform( - events.begin() + num_already_reconstructed_events, events.end(), - reconstructed_events.begin() + num_already_reconstructed_events, + events.begin() + static_cast(num_already_reconstructed_events), + events.end(), + reconstructed_events.begin() + + static_cast(num_already_reconstructed_events), [](const YaEvent& event) { return event.get(); }); } diff --git a/src/common/serialization/vst3/param-value-queue.cpp b/src/common/serialization/vst3/param-value-queue.cpp index 781cd85a..14c7b5aa 100644 --- a/src/common/serialization/vst3/param-value-queue.cpp +++ b/src/common/serialization/vst3/param-value-queue.cpp @@ -62,7 +62,7 @@ Steinberg::Vst::ParamID PLUGIN_API YaParamValueQueue::getParameterId() { } int32 PLUGIN_API YaParamValueQueue::getPointCount() { - return queue.size(); + return static_cast(queue.size()); } tresult PLUGIN_API @@ -81,7 +81,7 @@ YaParamValueQueue::getPoint(int32 index, tresult PLUGIN_API YaParamValueQueue::addPoint(int32 sampleOffset, Steinberg::Vst::ParamValue value, int32& index /*out*/) { - index = queue.size(); + index = static_cast(queue.size()); queue.push_back({sampleOffset, value}); return Steinberg::kResultOk; diff --git a/src/common/serialization/vst3/parameter-changes.cpp b/src/common/serialization/vst3/parameter-changes.cpp index b3743a21..608d7c03 100644 --- a/src/common/serialization/vst3/parameter-changes.cpp +++ b/src/common/serialization/vst3/parameter-changes.cpp @@ -59,7 +59,7 @@ void YaParameterChanges::write_back_outputs( } int32 PLUGIN_API YaParameterChanges::getParameterCount() { - return queues.size(); + return static_cast(queues.size()); } Steinberg::Vst::IParamValueQueue* PLUGIN_API @@ -74,7 +74,7 @@ YaParameterChanges::getParameterData(int32 index) { Steinberg::Vst::IParamValueQueue* PLUGIN_API YaParameterChanges::addParameterData(const Steinberg::Vst::ParamID& id, int32& index /*out*/) { - index = queues.size(); + index = static_cast(queues.size()); queues.push_back(YaParamValueQueue(id)); return &queues[index]; diff --git a/src/common/serialization/vst3/process-data.cpp b/src/common/serialization/vst3/process-data.cpp index 899d06e6..406b1d6f 100644 --- a/src/common/serialization/vst3/process-data.cpp +++ b/src/common/serialization/vst3/process-data.cpp @@ -72,7 +72,8 @@ Steinberg::Vst::AudioBusBuffers YaAudioBusBuffers::get() { buffer_pointers.push_back(buffer.data()); } - reconstructed_buffers.numChannels = buffers.size(); + reconstructed_buffers.numChannels = + static_cast(buffers.size()); reconstructed_buffers.channelBuffers64 = reinterpret_cast(buffer_pointers.data()); }, @@ -82,7 +83,8 @@ Steinberg::Vst::AudioBusBuffers YaAudioBusBuffers::get() { buffer_pointers.push_back(buffer.data()); } - reconstructed_buffers.numChannels = buffers.size(); + reconstructed_buffers.numChannels = + static_cast(buffers.size()); reconstructed_buffers.channelBuffers32 = reinterpret_cast(buffer_pointers.data()); }, @@ -194,8 +196,9 @@ Steinberg::Vst::ProcessData& YaProcessData::get() { reconstructed_process_data.processMode = process_mode; reconstructed_process_data.symbolicSampleSize = symbolic_sample_size; reconstructed_process_data.numSamples = num_samples; - reconstructed_process_data.numInputs = inputs.size(); - reconstructed_process_data.numOutputs = outputs_num_channels.size(); + reconstructed_process_data.numInputs = static_cast(inputs.size()); + reconstructed_process_data.numOutputs = + static_cast(outputs_num_channels.size()); reconstructed_process_data.inputs = inputs_audio_bus_buffers.data(); reconstructed_process_data.outputs = outputs_audio_bus_buffers.data(); diff --git a/src/plugin/bridges/vst3-impls/plugin-proxy.cpp b/src/plugin/bridges/vst3-impls/plugin-proxy.cpp index 7f210a42..1346cd80 100644 --- a/src/plugin/bridges/vst3-impls/plugin-proxy.cpp +++ b/src/plugin/bridges/vst3-impls/plugin-proxy.cpp @@ -48,7 +48,7 @@ size_t Vst3PluginProxyImpl::register_context_menu( std::lock_guard lock(context_menus_mutex); const size_t context_menu_id = current_context_menu_id.fetch_add(1); - context_menus.emplace(context_menu_id, std::move(menu)); + context_menus.emplace(context_menu_id, menu); return context_menu_id; } diff --git a/src/plugin/bridges/vst3.cpp b/src/plugin/bridges/vst3.cpp index 1f6ed9fc..2cdea34f 100644 --- a/src/plugin/bridges/vst3.cpp +++ b/src/plugin/bridges/vst3.cpp @@ -144,7 +144,7 @@ Vst3PluginBridge::Vst3PluginBridge() const size_t context_menu_id = plugin_proxies.at(request.owner_instance_id) .get() - .register_context_menu(std::move(context_menu)); + .register_context_menu(context_menu); return YaComponentHandler3::CreateContextMenuResponse{ .context_menu_args = diff --git a/src/plugin/utils.cpp b/src/plugin/utils.cpp index c58b05d6..7f65f393 100644 --- a/src/plugin/utils.cpp +++ b/src/plugin/utils.cpp @@ -163,6 +163,7 @@ fs::path find_plugin_library(const fs::path& this_plugin_path, // _actual_ (with yabridgectl `x86_64-win` should only contain a // 64-bit plugin and `x86-win` should only contain a 32-bit plugin, // but you never know!) + // NOLINTNEXTLINE(bugprone-branch-clone) if (prefer_32bit_vst3 && fs::exists(candidate_path_32bit)) { return fs::canonical(candidate_path_32bit); } else if (fs::exists(candidate_path_64bit)) { diff --git a/src/plugin/vst3-plugin.cpp b/src/plugin/vst3-plugin.cpp index 6d9eff1e..64e2d885 100644 --- a/src/plugin/vst3-plugin.cpp +++ b/src/plugin/vst3-plugin.cpp @@ -24,6 +24,7 @@ // as close to the vanilla SDK as possible. #define InitModule init_module #define DeinitModule deinit_module +// NOLINTNEXTLINE(bugprone-suspicious-include) #include // Because VST3 plugins consist of completely independent components that have diff --git a/src/wine-host/bridges/vst2.cpp b/src/wine-host/bridges/vst2.cpp index 780d93d3..502a6970 100644 --- a/src/wine-host/bridges/vst2.cpp +++ b/src/wine-host/bridges/vst2.cpp @@ -100,8 +100,11 @@ Vst2Bridge::Vst2Bridge(MainContext& main_context, // `get_bridge_instance` trick as in `plugin/bridges/vst2.cpp`, but since // the plugin will probably call the host callback while it's initializing // we sadly have to use a global here. + // Note that this reinterpret cast is not needed at all since the function + // pointer types are exactly the same, but clangd will complain otherwise current_bridge_instance = this; - plugin = vst_entry_point(host_callback_proxy); + plugin = vst_entry_point( + reinterpret_cast(host_callback_proxy)); if (!plugin) { throw std::runtime_error("VST plugin at '" + plugin_dll_path + "' failed to initialize."); diff --git a/src/wine-host/bridges/vst3.cpp b/src/wine-host/bridges/vst3.cpp index abef7c66..9dd2cc98 100644 --- a/src/wine-host/bridges/vst3.cpp +++ b/src/wine-host/bridges/vst3.cpp @@ -33,6 +33,7 @@ // // https://bugs.winehq.org/show_bug.cgi?id=50670 #define __IFileOperation_INTERFACE_DEFINED__ +// NOLINTNEXTLINE(bugprone-suspicious-include) #include /**