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:
Robbert van der Helm
2020-12-04 18:52:33 +01:00
parent c1e7f53cd0
commit 426231a22b
9 changed files with 76 additions and 22 deletions
+21 -2
View File
@@ -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