]> sigrok.org Git - libsigrok.git/commitdiff
sysclk-lwla: Avoid warning due to bogus range check.
authorDaniel Elstner <redacted>
Tue, 14 Jan 2014 23:52:26 +0000 (00:52 +0100)
committerDaniel Elstner <redacted>
Wed, 15 Jan 2014 20:43:54 +0000 (21:43 +0100)
(lwla_set_clock_source): Checking whether an enum value is greater
than or equal to zero apparently results in a warning with some
compilers.  Assign the enum to an unsigned variable to avoid this,
and return SR_ERR_BUG if the range is exceeded, as this indicates
a bug in the driver code itself.

hardware/sysclk-lwla/protocol.c

index 3618eb11030745e51da0035a8ce298e25549f9a2..65908f99ae7d5723c86f08177146c1e30582dbbd 100644 (file)
@@ -745,20 +745,22 @@ SR_PRIV int lwla_set_clock_source(const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        int ret;
        enum clock_source selected;
+       size_t idx;
 
        devc = sdi->priv;
        selected = devc->selected_clock_source;
 
        if (devc->cur_clock_source != selected) {
                devc->cur_clock_source = CLOCK_SOURCE_NONE;
-
-               if (selected >= 0 && selected < G_N_ELEMENTS(bitstream_map)) {
-                       ret = lwla_send_bitstream(sdi->conn,
-                                                 bitstream_map[selected]);
-                       if (ret == SR_OK)
-                               devc->cur_clock_source = selected;
-                       return ret;
+               idx = selected;
+               if (idx >= G_N_ELEMENTS(bitstream_map)) {
+                       sr_err("Clock source (%d) out of range", selected);
+                       return SR_ERR_BUG;
                }
+               ret = lwla_send_bitstream(sdi->conn, bitstream_map[idx]);
+               if (ret == SR_OK)
+                       devc->cur_clock_source = selected;
+               return ret;
        }
        return SR_OK;
 }