From: Jaroslav Kysela Date: Wed, 23 Apr 2003 08:01:07 +0000 (+0000) Subject: Fixed documented bugs by Clemens Ladisch X-Git-Tag: v1.0.3~183 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=7340d20729526d0176a83e8a61cb9806b963bbc3;p=alsa-lib.git Fixed documented bugs by Clemens Ladisch --- diff --git a/src/conf.c b/src/conf.c index 0f4aac60..54798f0c 100644 --- a/src/conf.c +++ b/src/conf.c @@ -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 id The new node id. * \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) { + char *new_id; assert(config && id); + new_id = strdup(id); + if (!new_id) + return -ENOMEM; if (config->id) free(config->id); - config->id = strdup(id); - if (!config->id) - return -ENOMEM; + config->id = new_id; 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 * 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) { + char *new_string; assert(config); if (config->type != SND_CONFIG_TYPE_STRING) return -EINVAL; - if (config->u.string) - free(config->u.string); if (value) { - config->u.string = strdup(value); - if (!config->u.string) + new_string = strdup(value); + if (!new_string) return -ENOMEM; } else { - config->u.string = NULL; + new_string = NULL; } + if (config->u.string) + free(config->u.string); + config->u.string = new_string; 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. * * 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) { @@ -2062,10 +2061,12 @@ int snd_config_set_ascii(snd_config_t *config, const char *ascii) } case SND_CONFIG_TYPE_STRING: { - char *ptr = realloc(config->u.string, strlen(ascii) + 1); + char *ptr = strdup(ascii); if (ptr == NULL) return -ENOMEM; - strcpy(config->u.string, ascii); + if (config->u.string) + free(config->u.string); + config->u.string = ptr; } break; default: