From e4241469d49551b92478afbd2209939ff89441d5 Mon Sep 17 00:00:00 2001 From: jjceresa <32781294+jjceresa@users.noreply.github.com> Date: Thu, 4 Mar 2021 21:47:59 +0100 Subject: [PATCH] Fix return in fluid_synth_chorus_set_param(), fluid_synth_reverb_set_param() (#789) --- src/bindings/fluid_cmd.c | 30 ++++++++++++++++++++++++++++-- src/synth/fluid_synth.c | 15 ++++++++++++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c index 896eeb35..67f3f4ce 100644 --- a/src/bindings/fluid_cmd.c +++ b/src/bindings/fluid_cmd.c @@ -1406,6 +1406,13 @@ fluid_handle_chorus_command(void *data, int ac, char **av, fluid_ostream_t out, static const char *const name_value[FLUID_CHORUS_PARAM_LAST - 1] = {"nr", "level", "speed", "depth"}; + /* setting name (except lfo waveform type) */ + static const char *name[FLUID_CHORUS_PARAM_LAST-1] = + { + "synth.chorus.nr", "synth.chorus.level", + "synth.chorus.speed", "synth.chorus.depth" + }; + FLUID_ENTRY_COMMAND(data); /* get and check index fx group index argument */ @@ -1424,16 +1431,35 @@ fluid_handle_chorus_command(void *data, int ac, char **av, fluid_ostream_t out, return FLUID_FAILED; } - /* run chorus function */ if(param == FLUID_CHORUS_NR) /* commands with integer parameter */ { - value = (double)atoi(av[ac]); + int min, max; + int int_value = atoi(av[ac]); + + fluid_settings_getint_range(handler->settings, name[param], &min, &max); + if(int_value < min || int_value > max) + { + fluid_ostream_printf(out, "%s: %s \"%s\" must be in range [%d..%d]\n", + name_cde[param], name_value[param], av[ac], min, max); + return FLUID_FAILED; + } + value = (double)int_value; } else /* commands with float parameter */ { + double min, max; value = atof(av[ac]); + + fluid_settings_getnum_range(handler->settings, name[param], &min, &max); + if(value < min || value > max) + { + fluid_ostream_printf(out, "%s: %s \"%s\" must be in range [%f..%f]\n", + name_cde[param], name_value[param], av[ac], min, max); + return FLUID_FAILED; + } } + /* run chorus function */ fluid_synth_chorus_set_param(handler->synth, fx_group, param, value); return FLUID_OK; } diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 8fdc65b7..1eb5d737 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -5922,7 +5922,10 @@ fluid_synth_reverb_set_param(fluid_synth_t *synth, int fx_group, /* check if reverb value is in max min range */ fluid_settings_getnum_range(synth->settings, name[param], &min, &max); - fluid_return_val_if_fail( min <= value && value <= max, FLUID_FAILED); + if(value < min || value > max) + { + FLUID_API_RETURN(FLUID_FAILED); + } /* set the value */ values[param] = value; @@ -6407,14 +6410,20 @@ fluid_synth_chorus_set_param(fluid_synth_t *synth, int fx_group, int param, { fluid_settings_getint_range(synth->settings, name[param], &min, &max); } - fluid_return_val_if_fail(min <= (int)value && (int)value <= max, FLUID_FAILED); + if((int)value < min || (int)value > max) + { + FLUID_API_RETURN(FLUID_FAILED); + } } else /* float value */ { double min; double max; fluid_settings_getnum_range(synth->settings, name[param], &min, &max); - fluid_return_val_if_fail(min <= value && value <= max, FLUID_FAILED); + if(value < min || value > max) + { + FLUID_API_RETURN(FLUID_FAILED); + } } /* set the value */