Fixed documented bugs by Clemens Ladisch <clemens@ladisch.de>

This commit is contained in:
Jaroslav Kysela 2003-04-23 08:01:07 +00:00
parent 05d57ff3be
commit 7340d20729

View file

@ -1497,16 +1497,17 @@ int snd_config_get_id(const snd_config_t *config, const char **id)
* \param config Handle to the configuration node. * \param config Handle to the configuration node.
* \param id The new node id. * \param id The new node id.
* \return Zero if successful, otherwise a negative error code. * \return Zero if successful, otherwise a negative error code.
* \bug \p id must not be a pointer to the node's current id.
*/ */
int snd_config_set_id(snd_config_t *config, const char *id) int snd_config_set_id(snd_config_t *config, const char *id)
{ {
char *new_id;
assert(config && id); assert(config && id);
new_id = strdup(id);
if (!new_id)
return -ENOMEM;
if (config->id) if (config->id)
free(config->id); free(config->id);
config->id = strdup(id); config->id = new_id;
if (!config->id)
return -ENOMEM;
return 0; return 0;
} }
@ -1981,23 +1982,23 @@ int snd_config_set_real(snd_config_t *config, double value)
* *
* This function deletes the old string in the node and stores a copy of * This function deletes the old string in the node and stores a copy of
* the passed string in the node. * the passed string in the node.
*
* \bug \p value must not be a pointer to the node's current value.
*/ */
int snd_config_set_string(snd_config_t *config, const char *value) int snd_config_set_string(snd_config_t *config, const char *value)
{ {
char *new_string;
assert(config); assert(config);
if (config->type != SND_CONFIG_TYPE_STRING) if (config->type != SND_CONFIG_TYPE_STRING)
return -EINVAL; return -EINVAL;
if (config->u.string)
free(config->u.string);
if (value) { if (value) {
config->u.string = strdup(value); new_string = strdup(value);
if (!config->u.string) if (!new_string)
return -ENOMEM; return -ENOMEM;
} else { } else {
config->u.string = NULL; new_string = NULL;
} }
if (config->u.string)
free(config->u.string);
config->u.string = new_string;
return 0; return 0;
} }
@ -2026,8 +2027,6 @@ int snd_config_set_pointer(snd_config_t *config, const void *value)
* \return Zero if successful, otherwise a negative error code. * \return Zero if successful, otherwise a negative error code.
* *
* The node must have a simple type, and the new value must have the same type. * The node must have a simple type, and the new value must have the same type.
*
* \bug For string nodes, changing the length of the string doesn't work.
*/ */
int snd_config_set_ascii(snd_config_t *config, const char *ascii) int snd_config_set_ascii(snd_config_t *config, const char *ascii)
{ {
@ -2062,10 +2061,12 @@ int snd_config_set_ascii(snd_config_t *config, const char *ascii)
} }
case SND_CONFIG_TYPE_STRING: case SND_CONFIG_TYPE_STRING:
{ {
char *ptr = realloc(config->u.string, strlen(ascii) + 1); char *ptr = strdup(ascii);
if (ptr == NULL) if (ptr == NULL)
return -ENOMEM; return -ENOMEM;
strcpy(config->u.string, ascii); if (config->u.string)
free(config->u.string);
config->u.string = ptr;
} }
break; break;
default: default: