From c4d38a7125679d693430c0f17c40d05d9541ad51 Mon Sep 17 00:00:00 2001 From: Marcus Weseloh Date: Sat, 27 Mar 2021 15:49:41 +0100 Subject: [PATCH] Fix preset generator validity checks The previous implementation used 0 as end-of-list sentinel value. But 0 is also the id of the first generator in the invalid_preset_gen list. This effectively prevented checks for invalid preset generators. Also contains some code cleanup to make the check for invalid instrument generators similar to invalid preset generators. Fixes #821 --- src/sfloader/fluid_sffile.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/sfloader/fluid_sffile.c b/src/sfloader/fluid_sffile.c index 677b0cfd..191f09c0 100644 --- a/src/sfloader/fluid_sffile.c +++ b/src/sfloader/fluid_sffile.c @@ -187,7 +187,6 @@ static const unsigned short invalid_inst_gen[] = Gen_Reserved1, Gen_Reserved2, Gen_Reserved3, - 0 }; static const unsigned short invalid_preset_gen[] = @@ -205,7 +204,6 @@ static const unsigned short invalid_preset_gen[] = Gen_SampleModes, Gen_ExclusiveClass, Gen_OverrideRootKey, - 0 }; @@ -2370,37 +2368,43 @@ static fluid_list_t *find_gen_by_id(int gen, fluid_list_t *genlist) /* check validity of instrument generator */ static int valid_inst_genid(unsigned short genid) { - int i = 0; + size_t i; if(genid >= Gen_Last) { return FALSE; } - while(invalid_inst_gen[i] && invalid_inst_gen[i] != genid) + for(i = 0; i < FLUID_N_ELEMENTS(invalid_inst_gen); i++) { - i++; + if (invalid_inst_gen[i] == genid) + { + return FALSE; + } } - return (invalid_inst_gen[i] == 0); + return TRUE; } /* check validity of preset generator */ static int valid_preset_genid(unsigned short genid) { - int i = 0; + size_t i; if(!valid_inst_genid(genid)) { return FALSE; } - while(invalid_preset_gen[i] && invalid_preset_gen[i] != genid) + for(i = 0; i < FLUID_N_ELEMENTS(invalid_preset_gen); i++) { - i++; + if (invalid_preset_gen[i] == genid) + { + return FALSE; + } } - return (invalid_preset_gen[i] == 0); + return TRUE; }