]> sigrok.org Git - libsigrok.git/commitdiff
uni-t-ut181a: silence compiler warning, use of uninitialized variable
authorGerhard Sittig <redacted>
Wed, 22 Dec 2021 13:12:31 +0000 (14:12 +0100)
committerGerhard Sittig <redacted>
Wed, 22 Dec 2021 19:06:02 +0000 (20:06 +0100)
The ut181a driver's acquisition start routine may face a previously
unknown data source value, which is potentially unhandled when the
source code becomes inconsistent during maintenance. Add a default
case to handle the condition, which silences a compiler warning.

    src/hardware/uni-t-ut181a/api.c:505:13: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
            } else if (devc->data_source >= DATA_SOURCE_REC_FIRST) {
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    src/hardware/uni-t-ut181a/api.c:536:6: note: uninitialized use occurs here
            if (ret < 0)
                ^~~
    src/hardware/uni-t-ut181a/api.c:505:9: note: remove the 'if' if its condition is always true
            } else if (devc->data_source >= DATA_SOURCE_REC_FIRST) {
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    src/hardware/uni-t-ut181a/api.c:467:9: note: initialize the variable 'ret' to silence this warning
            int ret;
                   ^
                    = 0

src/hardware/uni-t-ut181a/api.c

index de64f2f273f1319f6fbeb207ed433014b70e1525..5e12e7dae60cc2880cd4744bd0e3c5c160135f01 100644 (file)
@@ -532,6 +532,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                devc->info.rec_data.samples_total = devc->wait_state.data_value;
                devc->info.rec_data.samples_curr = 0;
                ret = ut181a_send_cmd_get_rec_samples(serial, rec_idx, 0);
+       } else {
+               sr_err("Unhandled data source %d, programming error?",
+                       (int)devc->data_source);
+               ret = SR_ERR_BUG;
        }
        if (ret < 0)
                return ret;