diff mbox series

[4/5] test/parser: Fixed uninitialized variable warning

Message ID 20180306040220.7519-5-joel@jms.id.au
State Accepted
Headers show
Series Misc fixes | expand

Commit Message

Joel Stanley March 6, 2018, 4:02 a.m. UTC
Clang has a problem with list_for_each_entry:

test/parser/utils.c:290:36: error: variable 'file' is used uninitialized whenever 'for' loop exits because its condition is false [-Werror,-Wsometimes-uninitialized]
        list_for_each_entry(&test->files, f, list) {
                                          ^
./lib/list/list.h:30:3: note: expanded from macro 'list_for_each_entry'
                _pos; _pos = list_next_entry(_list, _pos, _member))
                ^~~~
test/parser/utils.c:300:7: note: uninitialized use occurs here
        if (!file) {
             ^~~~
test/parser/utils.c:290:36: note: remove the condition if it is always true
        list_for_each_entry(&test->files, f, list) {
                                          ^
./lib/list/list.h:30:3: note: expanded from macro 'list_for_each_entry'
                _pos; _pos = list_next_entry(_list, _pos, _member))
                ^
test/parser/utils.c:288:28: note: initialize the variable 'file' to silence this warning
        struct test_file *f, *file;
                                  ^
                                   = NULL

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
This is a general problem that clang has with ccan's
list_for_each_entry. I reported it to the maintainer who several months
ago said "yeah, we should fix that".

 test/parser/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/test/parser/utils.c b/test/parser/utils.c
index 8900bd72bebd..47779c86f783 100644
--- a/test/parser/utils.c
+++ b/test/parser/utils.c
@@ -285,7 +285,7 @@  int parser_replace_file(struct discover_context *ctx,
 		char *buf, int len)
 {
 	struct parser_test *test = ctx->test_data;
-	struct test_file *f, *file;
+	struct test_file *f, *file = NULL;
 
 	list_for_each_entry(&test->files, f, list) {
 		if (f->dev != dev)