From 79c318c7efffeee46ed301d1fc4724ac90ff03a8 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 11 Dec 2024 20:01:08 -0500 Subject: Avoid potential division by zero It shouldn't normally be possible for this to happen, but this change makes it statically impossible. --- plugins/eg-metro.lv2/metro.c | 5 +++-- 1 file 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; } -- cgit v1.2.1