aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-12-11 20:01:08 -0500
committerDavid Robillard <d@drobilla.net>2024-12-11 20:01:23 -0500
commit79c318c7efffeee46ed301d1fc4724ac90ff03a8 (patch)
tree1897b949ce7351c2a5af847787342255e9d6db0e
parent446e1a1e8817fb0f68662762e53828b6e1ff152e (diff)
downloadlv2-79c318c7efffeee46ed301d1fc4724ac90ff03a8.tar.xz
Avoid potential division by zeroHEADmain
It shouldn't normally be possible for this to happen, but this change makes it statically impossible.
-rw-r--r--plugins/eg-metro.lv2/metro.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/plugins/eg-metro.lv2/metro.c b/plugins/eg-metro.lv2/metro.c
index d29638d..e60a33f 100644
--- a/plugins/eg-metro.lv2/metro.c
+++ b/plugins/eg-metro.lv2/metro.c
@@ -199,6 +199,7 @@ play(Metro* self, uint32_t begin, uint32_t end)
{
float* const output = self->ports.output;
const uint32_t frames_per_beat = (uint32_t)(60.0f / self->bpm * self->rate);
+ const float attack_den = self->attack_len ? (float)self->attack_len : 1.0f;
if (self->speed == 0.0f) {
memset(output, 0, (end - begin) * sizeof(float));
@@ -209,8 +210,8 @@ play(Metro* self, uint32_t begin, uint32_t end)
switch (self->state) {
case STATE_ATTACK:
// Amplitude increases from 0..1 until attack_len
- output[i] = self->wave[self->wave_offset] * (float)self->elapsed_len /
- (float)self->attack_len;
+ output[i] =
+ self->wave[self->wave_offset] * (float)self->elapsed_len / attack_den;
if (self->elapsed_len >= self->attack_len) {
self->state = STATE_DECAY;
}