]> sigrok.org Git - libsigrok.git/commit
rigol-ds: improve robustness in samplerate getting code path
authorGerhard Sittig <redacted>
Wed, 22 Dec 2021 13:01:42 +0000 (14:01 +0100)
committerGerhard Sittig <redacted>
Sat, 8 Jan 2022 09:13:21 +0000 (10:13 +0100)
commit713a3f352496f928b9911bfdc7e87a67134113df
tree09e0520a64efc85ec7b1cece1286d5893f59c200
parent64f26f744bf3185eddb07e8bfe9855e3c7bfac19
rigol-ds: improve robustness in samplerate getting code path

The rigol-ds driver's acquisition start routine tries to determine the
samplerate, which depends on devices' protocol version and communication
of SCPI requests. The logic potentially used an uninitialized variable
(for protocol versions below V3).

Rephrase the samplerate getting code path, apply stricter checks and
extend diagnostics. Make sure the XINC retrieval did yield a non-zero
value, to also avoid a division by zero.

Address style issues while we are here. Use braces for all branches when
one of them is complex. Eliminate trailing whitespace at ends of lines.

    src/hardware/rigol-ds/api.c:1029:7: warning: variable 'xinc' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]
                    if (devc->model->series->protocol >= PROTOCOL_V3 &&
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    src/hardware/rigol-ds/api.c:1034:28: note: uninitialized use occurs here
                    devc->sample_rate = 1. / xinc;
                                             ^~~~
    src/hardware/rigol-ds/api.c:1029:7: note: remove the '&&' if its condition is always true
                    if (devc->model->series->protocol >= PROTOCOL_V3 &&
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    src/hardware/rigol-ds/api.c:1028:13: note: initialize the variable 'xinc' to silence this warning
                    float xinc;
                              ^
                               = 0.0
src/hardware/rigol-ds/api.c