mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-14 04:19:59 +02:00
Avoid potential UB in loggers using composition
This cast would work fine, but any other fields added to those loggers would be left uninitialized.
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
Vst2Logger::Vst2Logger(Logger& generic_logger) : logger(generic_logger) {}
|
||||
|
||||
std::optional<std::string> opcode_to_string(bool is_dispatch, int opcode) {
|
||||
if (is_dispatch) {
|
||||
// Opcodes for a plugin's dispatch function
|
||||
@@ -316,7 +318,7 @@ std::optional<std::string> opcode_to_string(bool is_dispatch, int opcode) {
|
||||
}
|
||||
|
||||
void Vst2Logger::log_get_parameter(int index) {
|
||||
if (BOOST_UNLIKELY(verbosity >= Verbosity::most_events)) {
|
||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
||||
std::ostringstream message;
|
||||
message << ">> getParameter() " << index;
|
||||
|
||||
@@ -325,7 +327,7 @@ void Vst2Logger::log_get_parameter(int index) {
|
||||
}
|
||||
|
||||
void Vst2Logger::log_get_parameter_response(float value) {
|
||||
if (BOOST_UNLIKELY(verbosity >= Verbosity::most_events)) {
|
||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
||||
std::ostringstream message;
|
||||
message << " getParameter() :: " << value;
|
||||
|
||||
@@ -334,7 +336,7 @@ void Vst2Logger::log_get_parameter_response(float value) {
|
||||
}
|
||||
|
||||
void Vst2Logger::log_set_parameter(int index, float value) {
|
||||
if (BOOST_UNLIKELY(verbosity >= Verbosity::most_events)) {
|
||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
||||
std::ostringstream message;
|
||||
message << ">> setParameter() " << index << " = " << value;
|
||||
|
||||
@@ -343,7 +345,7 @@ void Vst2Logger::log_set_parameter(int index, float value) {
|
||||
}
|
||||
|
||||
void Vst2Logger::log_set_parameter_response() {
|
||||
if (BOOST_UNLIKELY(verbosity >= Verbosity::most_events)) {
|
||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
||||
log(" setParameter() :: OK");
|
||||
}
|
||||
}
|
||||
@@ -355,7 +357,7 @@ void Vst2Logger::log_event(bool is_dispatch,
|
||||
const EventPayload& payload,
|
||||
float option,
|
||||
const std::optional<EventPayload>& value_payload) {
|
||||
if (BOOST_UNLIKELY(verbosity >= Verbosity::most_events)) {
|
||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
||||
if (should_filter_event(is_dispatch, opcode)) {
|
||||
return;
|
||||
}
|
||||
@@ -442,7 +444,7 @@ void Vst2Logger::log_event_response(
|
||||
intptr_t return_value,
|
||||
const EventResultPayload& payload,
|
||||
const std::optional<EventResultPayload>& value_payload) {
|
||||
if (BOOST_UNLIKELY(verbosity >= Verbosity::most_events)) {
|
||||
if (BOOST_UNLIKELY(logger.verbosity >= Logger::Verbosity::most_events)) {
|
||||
if (should_filter_event(is_dispatch, opcode)) {
|
||||
return;
|
||||
}
|
||||
@@ -512,7 +514,7 @@ void Vst2Logger::log_event_response(
|
||||
}
|
||||
|
||||
bool Vst2Logger::should_filter_event(bool is_dispatch, int opcode) const {
|
||||
if (verbosity >= Verbosity::all_events) {
|
||||
if (logger.verbosity >= Logger::Verbosity::all_events) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,10 +33,24 @@
|
||||
std::optional<std::string> opcode_to_string(bool is_dispatch, int opcode);
|
||||
|
||||
/**
|
||||
* Provides VST2 specific logging functionality for debugging plugins.
|
||||
* Wraps around `Logger` to provide VST2 specific logging functionality for
|
||||
* debugging plugins. This way we can have all the complex initialisation be
|
||||
* performed in one place.
|
||||
*/
|
||||
class Vst2Logger : public Logger {
|
||||
class Vst2Logger {
|
||||
public:
|
||||
Vst2Logger(Logger& generic_logger);
|
||||
|
||||
/**
|
||||
* @see Logger::log
|
||||
*/
|
||||
inline void log(const std::string& message) { logger.log(message); }
|
||||
|
||||
/**
|
||||
* @see Logger::log_trace
|
||||
*/
|
||||
inline void log_trace(const std::string& message) { logger.log(message); }
|
||||
|
||||
// The following functions are for logging specific events, they are only
|
||||
// enabled for verbosity levels higher than 1 (i.e. `Verbosity::events`)
|
||||
void log_get_parameter(int index);
|
||||
@@ -60,6 +74,11 @@ class Vst2Logger : public Logger {
|
||||
const EventResultPayload& payload,
|
||||
const std::optional<EventResultPayload>& value_payload);
|
||||
|
||||
/**
|
||||
* The underlying logger instance we're wrapping.
|
||||
*/
|
||||
Logger& logger;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Determine whether an event should be filtered based on the current
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// yabridge: a Wine VST bridge
|
||||
// Copyright (C) 2020 Robbert van der Helm
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "vst3.h"
|
||||
|
||||
Vst3Logger::Vst3Logger(Logger& generic_logger) : logger(generic_logger) {}
|
||||
@@ -19,9 +19,25 @@
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Provides VST3-specific logging functionality for debugging plugins.
|
||||
* Wraps around `Logger` to provide VST3 specific logging functionality for
|
||||
* debugging plugins. This way we can have all the complex initialisation be
|
||||
* performed in one place.
|
||||
*/
|
||||
class Vst3Logger : public Logger {
|
||||
class Vst3Logger {
|
||||
public:
|
||||
Vst3Logger(Logger& generic_logger);
|
||||
|
||||
/**
|
||||
* @see Logger::log
|
||||
*/
|
||||
inline void log(const std::string& message) { logger.log(message); }
|
||||
|
||||
/**
|
||||
* @see Logger::log_trace
|
||||
*/
|
||||
inline void log_trace(const std::string& message) { logger.log(message); }
|
||||
|
||||
// TODO: Logging interface for VST3 plugins
|
||||
|
||||
Logger& logger;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user