From 380fd258d7fa003d911c049bfadef3802521c06b Mon Sep 17 00:00:00 2001 From: Surabhi Mishra Date: Tue, 1 Jul 2014 14:40:01 +0200 Subject: [PATCH] Fix dereference of voice->sample before NULL check Signed-off-by: David Henningsson --- fluidsynth/src/synth/fluid_voice.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fluidsynth/src/synth/fluid_voice.c b/fluidsynth/src/synth/fluid_voice.c index 05287c12..8258c68e 100644 --- a/fluidsynth/src/synth/fluid_voice.c +++ b/fluidsynth/src/synth/fluid_voice.c @@ -763,15 +763,19 @@ fluid_voice_update_param(fluid_voice_t* voice, int gen) * which offsets the original rate. This means that the fine tuning is * inverted with respect to the root note (so subtract it, not add). */ - if (voice->gen[GEN_OVERRIDEROOTKEY].val > -1) { //FIXME: use flag instead of -1 - voice->root_pitch = voice->gen[GEN_OVERRIDEROOTKEY].val * 100.0f - - voice->sample->pitchadj; - } else { - voice->root_pitch = voice->sample->origpitch * 100.0f - voice->sample->pitchadj; - } - x = fluid_ct2hz(voice->root_pitch); if (voice->sample != NULL) { - x *= (fluid_real_t) voice->output_rate / voice->sample->samplerate; + if (voice->gen[GEN_OVERRIDEROOTKEY].val > -1) //FIXME: use flag instead of -1 + voice->root_pitch = voice->gen[GEN_OVERRIDEROOTKEY].val * 100.0f + - voice->sample->pitchadj; + else + voice->root_pitch = voice->sample->origpitch * 100.0f - voice->sample->pitchadj; + x = (fluid_ct2hz(voice->root_pitch) * ((fluid_real_t) voice->output_rate / voice->sample->samplerate)); + } else { + if (voice->gen[GEN_OVERRIDEROOTKEY].val > -1) //FIXME: use flag instead of -1 + voice->root_pitch = voice->gen[GEN_OVERRIDEROOTKEY].val * 100.0f; + else + voice->root_pitch = 0; + x = fluid_ct2hz(voice->root_pitch); } /* voice->pitch depends on voice->root_pitch, so calculate voice->pitch now */ fluid_voice_calculate_gen_pitch(voice);