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
This commit is contained in:
Marcus Weseloh 2021-03-27 15:49:41 +01:00
parent 259aecedf2
commit c4d38a7125

View file

@ -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;
}