aft.c: Silence scan-build warning.
authorAndre Noll <maan@systemlinux.org>
Fri, 1 Jun 2012 08:24:58 +0000 (10:24 +0200)
committerAndre Noll <maan@systemlinux.org>
Wed, 13 Jun 2012 14:43:15 +0000 (16:43 +0200)
scan-build issues the following warning in prepare_ls_row():

aft.c:1338:3: warning: Assigned value is garbage or undefined
GET_NUM_DIGITS(score, &num_digits);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aft.c:719:21: note: expanded from:
typeof((x)) _tmp = PARA_ABS(x); \
   ^
./para.h:50:2: note: expanded from:
typeof(x) _x = (x); \
^              ~~~

This is because clang can not prove that the "score" variable is
always initialized at this point. However, I can: The problematic
GET_NUM_DIGITS() statement is only executed if LS_FLAG_ADMISSIBLE_ONLY
is set in options->flags, but in this case "score" will be set by
get_score_and_aft_row() because this function only fails to do so if it
returns negative. In this case we return early from prepare_ls_row().

Let's make it easier for clang and initialize it anyway.

aft.c

diff --git a/aft.c b/aft.c
index 7516e32..9e991da 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1276,8 +1276,10 @@ static int prepare_ls_row(struct osl_row *row, void *ls_opts)
                ret = get_score_and_aft_row(row, &score, &aft_row);
                if (ret < 0)
                        return ret;
-       } else
+       } else {
                aft_row = row;
+               score = 0;
+       }
        ret = get_audio_file_path_of_row(aft_row, &path);
        if (ret < 0)
                return ret;