From: Gerhard Sittig Date: Wed, 22 Dec 2021 13:12:31 +0000 (+0100) Subject: uni-t-ut181a: silence compiler warning, use of uninitialized variable X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=deb7615262ac4f9cc0750a08351afa7cbf9c34d5;p=libsigrok.git uni-t-ut181a: silence compiler warning, use of uninitialized variable 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 --- diff --git a/src/hardware/uni-t-ut181a/api.c b/src/hardware/uni-t-ut181a/api.c index de64f2f2..5e12e7da 100644 --- a/src/hardware/uni-t-ut181a/api.c +++ b/src/hardware/uni-t-ut181a/api.c @@ -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;