]> git.alsa-project.org Git - alsa-lib.git/commitdiff
topology: various coverity fixes
authorJaroslav Kysela <perex@perex.cz>
Fri, 24 May 2019 18:52:00 +0000 (20:52 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 24 May 2019 19:25:50 +0000 (21:25 +0200)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/topology/ctl.c
src/topology/data.c
src/topology/parser.c

index 9c13b12c4bf4ad758587fbe42f212b7a223d3105..a096252263a5a51802304021b1b8aeb07e358d82 100644 (file)
@@ -880,8 +880,8 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl,
        if (enum_ctl->texts != NULL) {
                for (i = 0; i < num_items; i++) {
                        if (enum_ctl->texts[i] != NULL)
-                               strncpy(ec->texts[i], enum_ctl->texts[i],
-                                       SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
+                               snd_strlcpy(ec->texts[i], enum_ctl->texts[i],
+                                           SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
                }
        }
 
index fd72abbb5e08f8ac04a1a144ba2a243179531176..aa2b87e73f50c7c832dbb7ed27e0a3057eeee9e1 100644 (file)
@@ -124,12 +124,12 @@ static int tplg_parse_data_file(snd_config_t *cfg, struct tplg_elem *elem)
 
        if (fclose(fp) == EOF) {
                SNDERR("Cannot close data file.");
-               ret = -errno;
-               goto err;
+               return -errno;
        }
        return 0;
 
 err:
+       fclose(fp);
        if (priv)
                free(priv);
        return ret;
@@ -422,7 +422,7 @@ static unsigned int get_tuple_size(int type)
 static int copy_tuples(struct tplg_elem *elem,
        struct tplg_vendor_tuples *tuples, struct tplg_vendor_tokens *tokens)
 {
-       struct snd_soc_tplg_private *priv = elem->data;
+       struct snd_soc_tplg_private *priv = elem->data, *priv2;
        struct tplg_tuple_set *tuple_set;
        struct tplg_tuple *tuple;
        struct snd_soc_tplg_vendor_array *array;
@@ -447,10 +447,17 @@ static int copy_tuples(struct tplg_elem *elem,
                        return -EINVAL;
                }
 
-               if (priv != NULL)
-                       priv = realloc(priv, sizeof(*priv) + size);
-               else
+               if (priv != NULL) {
+                       priv2 = realloc(priv, sizeof(*priv) + size);
+                       if (priv2 == NULL) {
+                               free(priv);
+                               priv = NULL;
+                       } else {
+                               priv = priv2;
+                       }
+               } else {
                        priv = calloc(1, sizeof(*priv) + size);
+               }
                if (!priv)
                        return -ENOMEM;
 
index cfc20e000e5c7fb1fb5b605df5e7140c4e8adac0..a7cff1c30edce4ea14e43831ee6b054213d76c91 100644 (file)
@@ -237,8 +237,9 @@ static int tplg_load_config(const char *file, snd_config_t **cfg)
 
        ret = snd_input_stdio_attach(&in, fp, 1);
        if (ret < 0) {
+               fclose(fp);
                SNDERR("error: could not attach stdio %s", file);
-               goto err;
+               return ret;
        }
        ret = snd_config_top(&top);
        if (ret < 0)
@@ -261,7 +262,7 @@ static int tplg_load_config(const char *file, snd_config_t **cfg)
 err_load:
        snd_config_delete(top);
 err:
-       fclose(fp);
+       snd_input_close(in);
        return ret;
 }