File 0064-topology-builder-Fix-possibly-uninitialized-variable.patch of Package alsa

From 76b9cae026bf73a00ccf3ec8833ec56f0e64f451 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Tue, 8 Sep 2015 22:04:48 +0200
Subject: [PATCH] topology: builder: Fix possibly uninitialized variable in
 write_elem_block()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When an empty list is passed to write_elem_block(), it may leave
vendor_type uninitialized.
  builder.c: In function ‘write_elem_block’:
  builder.c:127:8: warning: ‘vendor_type’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    ret = write_block_header(tplg, tplg_type, vendor_type,
          ^
  builder.c:114:33: note: ‘vendor_type’ was declared here
    int ret, wsize = 0, count = 0, vendor_type;
                                   ^

Add an immediate return for count = 0 for avoiding it, and simplify
the code initializing vendor_type without using a one-shot loop.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 src/topology/builder.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/topology/builder.c b/src/topology/builder.c
index 3bccd44827cc..91412aadd098 100644
--- a/src/topology/builder.c
+++ b/src/topology/builder.c
@@ -116,13 +116,12 @@ static int write_elem_block(snd_tplg_t *tplg,
 	/* count number of elements */
 	list_for_each(pos, base)
 		count++;
+	if (!count)
+		return 0;
 
 	/* write the header for this block */
-	list_for_each(pos, base) {
-		elem = list_entry(pos, struct tplg_elem, list);
-		vendor_type = elem->vendor_type;
-		break;
-	}
+	elem = list_entry(base->next, struct tplg_elem, list);
+	vendor_type = elem->vendor_type;
 
 	ret = write_block_header(tplg, tplg_type, vendor_type,
 		SND_SOC_TPLG_ABI_VERSION, 0, size, count);
-- 
2.5.3

openSUSE Build Service is sponsored by