commit 0cfbc696e87562b6aa854e17db94fdeb39ef8783
parent 82f19164e80c88c75dad077503140887d206ce0b
Author: fundamental <[email protected]>
Date: Fri, 6 Nov 2015 22:53:25 -0500
Remove Undefined Behavior In EnvelopeParams::Paste
Diffstat:
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/Params/EnvelopeParams.cpp b/src/Params/EnvelopeParams.cpp
@@ -127,19 +127,30 @@ EnvelopeParams::EnvelopeParams(unsigned char Penvstretch_,
EnvelopeParams::~EnvelopeParams()
{}
+#define COPY(y) this->y = ep.y
void EnvelopeParams::paste(const EnvelopeParams &ep)
{
- //Avoid undefined behavior
- if(&ep == this)
- return;
-
- char *base = (char*)&this->Pfreemode;
- char *end = (char*)&this->DR_val;
- assert(end-base > 0);
-
- memcpy((char*)&this->Pfreemode, (const char*)&ep.Pfreemode, 1+end-base);
+ COPY(Pfreemode);
+ COPY(Penvpoints);
+ COPY(Penvsustain);
+ for(int i=0; i<MAX_ENVELOPE_POINTS; ++i) {
+ this->Penvdt[i] = ep.Penvdt[i];
+ this->Penvval[i] = ep.Penvval[i];
+ }
+ COPY(Penvstretch);
+ COPY(Pforcedrelease);
+ COPY(Plinearenvelope);
+
+ COPY(PA_dt);
+ COPY(PD_dt);
+ COPY(PR_dt);
+ COPY(PA_val);
+ COPY(PD_val);
+ COPY(PS_val);
+ COPY(PR_val);
}
+#undef COPY
float EnvelopeParams::getdt(char i) const
{
diff --git a/src/Params/EnvelopeParams.h b/src/Params/EnvelopeParams.h
@@ -54,9 +54,9 @@ class EnvelopeParams:public Presets
static float dt(char val);
/* MIDI Parameters */
- unsigned char Pfreemode; //1 daca este in modul free sau 0 daca este in mod ADSR,ASR,...
+ unsigned char Pfreemode; //1 for free mode, 0 otherwise
unsigned char Penvpoints;
- unsigned char Penvsustain; //127 pentru dezactivat
+ unsigned char Penvsustain; //127 for disabled
unsigned char Penvdt[MAX_ENVELOPE_POINTS];
unsigned char Penvval[MAX_ENVELOPE_POINTS];
unsigned char Penvstretch; //64=normal stretch (piano-like), 0=no stretch