zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit 8cbdeff928a708523ab6191b6b8074d66b680808
parent ce43dc70254924e55e8db9744ce2db50371d78e1
Author: fundamental <mark.d.mccurry@gmail.com>
Date:   Sat, 10 Oct 2015 23:54:25 -0400

Fix Undefined Behavior In EnvelopeParams::paste

Yep, overwriting the vtable pointer via memcpy isn't a great idea.

Diffstat:
Msrc/Params/EnvelopeParams.cpp | 9++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/Params/EnvelopeParams.cpp b/src/Params/EnvelopeParams.cpp @@ -22,6 +22,7 @@ #include <cmath> #include <cstdlib> +#include <cassert> #include <rtosc/ports.h> #include <rtosc/port-sugar.h> @@ -131,7 +132,13 @@ void EnvelopeParams::paste(const EnvelopeParams &ep) //Avoid undefined behavior if(&ep == this) return; - memcpy((char*)this, (const char*)&ep, sizeof(*this)); + + + 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); } float EnvelopeParams::getdt(char i) const