* \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;
}
*
* 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;
}
* \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)
{
}
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: