1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-16 08:34:10 +02:00

fixed strict-aliasing violations in VSTEffect.cpp

also removed an unused variable in the same file
This commit is contained in:
andheh 2018-03-22 09:16:00 +01:00 committed by James Crook
parent b56059a77c
commit 430e91d834

View File

@ -98,6 +98,23 @@
#include "VSTEffect.h"
#include "../../MemoryX.h"
#include <cstring>
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));
}
}