OSDN Git Service

Fixed documented bugs by Clemens Ladisch <clemens@ladisch.de>
authorJaroslav Kysela <perex@perex.cz>
Wed, 23 Apr 2003 08:01:07 +0000 (08:01 +0000)
committerJaroslav Kysela <perex@perex.cz>
Wed, 23 Apr 2003 08:01:07 +0000 (08:01 +0000)
src/conf.c

index 0f4aac6..54798f0 100644 (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 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: