mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2024-12-03 17:42:21 +00:00
Make use of fluid_tuning_set_name where appropriate
Also add memory allocation error checks and initialize fluid_tuning_t after allocation.
This commit is contained in:
parent
c605380aa8
commit
432929c18c
2 changed files with 15 additions and 17 deletions
|
@ -34,11 +34,11 @@ fluid_tuning_t* new_fluid_tuning(const char* name, int bank, int prog)
|
||||||
FLUID_LOG(FLUID_PANIC, "Out of memory");
|
FLUID_LOG(FLUID_PANIC, "Out of memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
FLUID_MEMSET(tuning, 0, sizeof(fluid_tuning_t));
|
||||||
|
|
||||||
tuning->name = NULL;
|
if (fluid_tuning_set_name(tuning, name) != FLUID_OK) {
|
||||||
|
delete_fluid_tuning(tuning);
|
||||||
if (name != NULL) {
|
return NULL;
|
||||||
tuning->name = FLUID_STRDUP(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tuning->bank = bank;
|
tuning->bank = bank;
|
||||||
|
@ -66,19 +66,12 @@ fluid_tuning_duplicate (fluid_tuning_t *tuning)
|
||||||
FLUID_LOG (FLUID_PANIC, "Out of memory");
|
FLUID_LOG (FLUID_PANIC, "Out of memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
FLUID_MEMSET(new_tuning, 0, sizeof(fluid_tuning_t));
|
||||||
|
|
||||||
if (tuning->name)
|
if (fluid_tuning_set_name(new_tuning, tuning->name) != FLUID_OK) {
|
||||||
{
|
delete_fluid_tuning(new_tuning);
|
||||||
new_tuning->name = FLUID_STRDUP (tuning->name);
|
|
||||||
|
|
||||||
if (!new_tuning->name)
|
|
||||||
{
|
|
||||||
FLUID_FREE (new_tuning);
|
|
||||||
FLUID_LOG (FLUID_PANIC, "Out of memory");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else new_tuning->name = NULL;
|
|
||||||
|
|
||||||
new_tuning->bank = tuning->bank;
|
new_tuning->bank = tuning->bank;
|
||||||
new_tuning->prog = tuning->prog;
|
new_tuning->prog = tuning->prog;
|
||||||
|
@ -129,7 +122,7 @@ fluid_tuning_unref (fluid_tuning_t *tuning, int count)
|
||||||
else return FALSE;
|
else return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fluid_tuning_set_name(fluid_tuning_t* tuning, char* name)
|
int fluid_tuning_set_name(fluid_tuning_t* tuning, const char* name)
|
||||||
{
|
{
|
||||||
if (tuning->name != NULL) {
|
if (tuning->name != NULL) {
|
||||||
FLUID_FREE(tuning->name);
|
FLUID_FREE(tuning->name);
|
||||||
|
@ -137,8 +130,13 @@ void fluid_tuning_set_name(fluid_tuning_t* tuning, char* name)
|
||||||
}
|
}
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
tuning->name = FLUID_STRDUP(name);
|
tuning->name = FLUID_STRDUP(name);
|
||||||
|
if (tuning->name == NULL) {
|
||||||
|
FLUID_LOG(FLUID_ERR, "Out of memory");
|
||||||
|
return FLUID_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return FLUID_OK;
|
||||||
|
}
|
||||||
|
|
||||||
char* fluid_tuning_get_name(fluid_tuning_t* tuning)
|
char* fluid_tuning_get_name(fluid_tuning_t* tuning)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,7 @@ fluid_tuning_t *fluid_tuning_duplicate (fluid_tuning_t *tuning);
|
||||||
void fluid_tuning_ref (fluid_tuning_t *tuning);
|
void fluid_tuning_ref (fluid_tuning_t *tuning);
|
||||||
int fluid_tuning_unref (fluid_tuning_t *tuning, int count);
|
int fluid_tuning_unref (fluid_tuning_t *tuning, int count);
|
||||||
|
|
||||||
void fluid_tuning_set_name(fluid_tuning_t* tuning, char* name);
|
int fluid_tuning_set_name(fluid_tuning_t* tuning, const char* name);
|
||||||
char* fluid_tuning_get_name(fluid_tuning_t* tuning);
|
char* fluid_tuning_get_name(fluid_tuning_t* tuning);
|
||||||
|
|
||||||
#define fluid_tuning_get_bank(_t) ((_t)->bank)
|
#define fluid_tuning_get_bank(_t) ((_t)->bank)
|
||||||
|
|
Loading…
Reference in a new issue