diff --git a/src/effects/VST/VSTEffect.cpp b/src/effects/VST/VSTEffect.cpp index 3cd95bd1c..23607c334 100644 --- a/src/effects/VST/VSTEffect.cpp +++ b/src/effects/VST/VSTEffect.cpp @@ -98,6 +98,23 @@ #include "VSTEffect.h" #include "../../MemoryX.h" +#include + +static float reinterpretAsFloat(uint32_t x) +{ + static_assert(sizeof(float) == sizeof(uint32_t)); + float f; + std::memcpy(&f, &x, sizeof(float)); + return f; +} + +static uint32_t reinterpretAsUint32(float f) +{ + static_assert(sizeof(float) == sizeof(uint32_t)); + uint32_t x; + std::memcpy(&x, &f, sizeof(uint32_t)); + return x; +} // NOTE: To debug the subprocess, use wxLogDebug and, on Windows, Debugview // from TechNet (Sysinternals). @@ -503,7 +520,6 @@ unsigned VSTEffectsModule::DiscoverPluginsAtPath( size_t idCnt = 0; size_t idNdx = 0; - bool valid = false; bool cont = true; while (effectTzr.HasMoreTokens() && cont) @@ -526,7 +542,6 @@ unsigned VSTEffectsModule::DiscoverPluginsAtPath( { wxLogMessage(_("VST plugin registration failed for %s\n"), path); error = true; - valid = false; } wxString output; @@ -641,7 +656,6 @@ unsigned VSTEffectsModule::DiscoverPluginsAtPath( if (!skip && cont) { - valid = true; if (callback) callback( this, &proc ); ++nFound; @@ -3322,7 +3336,7 @@ bool VSTEffect::LoadFXProgram(unsigned char **bptr, ssize_t & len, int index, bo for (int i = 0; i < numParams; i++) { uint32_t ival = wxUINT32_SWAP_ON_LE(iptr[14 + i]); - float val = *((float *) &ival); + float val = reinterpretAsFloat(ival); if (val < 0.0 || val > 1.0) { return false; @@ -3343,7 +3357,7 @@ bool VSTEffect::LoadFXProgram(unsigned char **bptr, ssize_t & len, int index, bo for (int i = 0; i < numParams; i++) { wxUint32 val = wxUINT32_SWAP_ON_LE(iptr[14 + i]); - callSetParameter(i, *((float *) &val)); + callSetParameter(i, reinterpretAsFloat(val)); } callDispatcher(effEndSetProgram, 0, 0, NULL, 0.0); } @@ -3602,7 +3616,7 @@ void VSTEffect::SaveFXProgram(wxMemoryBuffer & buf, int index) for (int i = 0; i < mAEffect->numParams; i++) { float val = callGetParameter(i); - wxUint32 ival = wxUINT32_SWAP_ON_LE(*((wxUint32 *) &val)); + wxUint32 ival = wxUINT32_SWAP_ON_LE(reinterpretAsUint32(val)); buf.AppendData(&ival, sizeof(ival)); } }