]> sigrok.org Git - libsigrok.git/commitdiff
drivers/input: Remove some hardcoded values.
authorUwe Hermann <redacted>
Tue, 25 Jul 2017 20:07:11 +0000 (22:07 +0200)
committerUwe Hermann <redacted>
Mon, 31 Jul 2017 14:23:31 +0000 (16:23 +0200)
src/hardware/brymen-dmm/api.c
src/hardware/colead-slm/protocol.c
src/hardware/fluke-dmm/api.c
src/input/binary.c
src/input/chronovu_la8.c
src/input/trace32_ad.c
src/input/wav.c
src/session_driver.c

index 01e56112491832eb00f7e19924d4c1d165c4eb80..ce6f1f33e4f4c8e832fa34232a74f04698d89f13 100644 (file)
@@ -61,7 +61,7 @@ static GSList *brymen_scan(struct sr_dev_driver *di, const char *conn,
                goto scan_cleanup;
        }
 
-       len = 128;
+       len = sizeof(buf);
        ret = brymen_stream_detect(serial, buf, &len, brymen_packet_length,
                             brymen_packet_is_valid, 1000, 9600);
        if (ret != SR_OK)
index b577f236c0ac85de0ba475a9338660ba63379b78..570e7db33a6a918eecff07f11bf2a9817dcd09be 100644 (file)
@@ -202,7 +202,7 @@ SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data)
 
        serial = sdi->conn;
        if (devc->state == IDLE) {
-               if (serial_read_nonblocking(serial, buf, 128) != 1 || buf[0] != 0x10)
+               if (serial_read_nonblocking(serial, buf, sizeof(buf)) != 1 || buf[0] != 0x10)
                        /* Nothing there, or caught the tail end of a previous packet,
                         * or some garbage. Unless it's a single "data ready" byte,
                         * we don't want it. */
index b0cee61c8396d865bbade1083775cdfa68a8ebdf..f533f1c5df7d7a2731f187b28779efea7c709944 100644 (file)
@@ -90,7 +90,7 @@ static GSList *fluke_scan(struct sr_dev_driver *di, const char *conn,
 
                /* Response is first a CMD_ACK byte (ASCII '0' for OK,
                 * or '1' to signify an error. */
-               len = 128;
+               len = sizeof(buf);
                serial_readline(serial, &b, &len, 150);
                if (len != 1)
                        continue;
@@ -98,7 +98,7 @@ static GSList *fluke_scan(struct sr_dev_driver *di, const char *conn,
                        continue;
 
                /* If CMD_ACK was OK, ID string follows. */
-               len = 128;
+               len = sizeof(buf);
                serial_readline(serial, &b, &len, 850);
                if (len < 10)
                        continue;
index 91e4d3c434e45cdcfa65b3597e2f16c8476af9cc..013621373c71dd4eed995c19980fed76c1b13cbc 100644 (file)
@@ -56,7 +56,7 @@ static int init(struct sr_input *in, GHashTable *options)
        inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate"));
 
        for (i = 0; i < num_channels; i++) {
-               snprintf(name, 16, "%d", i);
+               snprintf(name, sizeof(name), "%d", i);
                sr_channel_new(in->sdi, i, SR_CHANNEL_LOGIC, TRUE, name);
        }
 
index 6c5707330934bb833305e0a4195241cb04aae505..531258ff947835a425a5105b33e7827b7f6f2ea4 100644 (file)
@@ -67,7 +67,7 @@ static int init(struct sr_input *in, GHashTable *options)
        inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate"));
 
        for (i = 0; i < num_channels; i++) {
-               snprintf(name, 16, "%d", i);
+               snprintf(name, sizeof(name), "%d", i);
                sr_channel_new(in->sdi, i, SR_CHANNEL_LOGIC, TRUE, name);
        }
 
index 8cbd4d0721d9da1c52ff5d1b099340feed1111be..7817457f81178fdb306bdac1bcd271658dce7d87 100644 (file)
@@ -291,13 +291,13 @@ static void create_channels(struct sr_input *in)
                        continue;
 
                for (channel = 0; channel < 16; channel++) {
-                       snprintf(name, 8, "%c%d", get_pod_name_from_id(pod), channel);
+                       snprintf(name, sizeof(name), "%c%d", get_pod_name_from_id(pod), channel);
                        inc->channels[pod][channel] =
                                sr_channel_new(in->sdi, chan_id, SR_CHANNEL_LOGIC, TRUE, name);
                        chan_id++;
                }
 
-               snprintf(name, 8, "CLK%c", get_pod_name_from_id(pod));
+               snprintf(name, sizeof(name), "CLK%c", get_pod_name_from_id(pod));
                inc->channels[pod][16] =
                        sr_channel_new(in->sdi, chan_id, SR_CHANNEL_LOGIC, TRUE, name);
                chan_id++;
index 35247112b05de8ac45e665a444f5a29e2155de2a..a1751243f467729c8ee7b2dbc61f3ca753906fc9 100644 (file)
@@ -331,7 +331,7 @@ static int receive(struct sr_input *in, GString *buf)
                        return ret;
 
                for (int i = 0; i < inc->num_channels; i++) {
-                       snprintf(channelname, 8, "CH%d", i + 1);
+                       snprintf(channelname, sizeof(channelname), "CH%d", i + 1);
                        sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname);
                }
 
index a102fdd7ee3a9affa0939e5c73ae64d1c577d0cb..c6af3b6dc04342fe136080f0315fef3ddf275696 100644 (file)
@@ -92,7 +92,7 @@ static gboolean stream_session_data(struct sr_dev_inst *sdi)
                                sr_dbg("Opened %s.", vdev->capturefile);
                        } else {
                                /* Try as first chunk filename. */
-                               snprintf(capturefile, 15, "%s-1", vdev->capturefile);
+                               snprintf(capturefile, sizeof(capturefile) - 1, "%s-1", vdev->capturefile);
                                if (zip_stat(vdev->archive, capturefile, 0, &zs) != -1) {
                                        vdev->cur_chunk = 1;
                                        if (!(vdev->capfile = zip_fopen(vdev->archive,
@@ -108,7 +108,7 @@ static gboolean stream_session_data(struct sr_dev_inst *sdi)
                } else {
                        /* Capture data is chunked, advance to the next chunk. */
                        vdev->cur_chunk++;
-                       snprintf(capturefile, 15, "%s-%d", vdev->capturefile,
+                       snprintf(capturefile, sizeof(capturefile) - 1, "%s-%d", vdev->capturefile,
                                        vdev->cur_chunk);
                        if (zip_stat(vdev->archive, capturefile, 0, &zs) != -1) {
                                if (!(vdev->capfile = zip_fopen(vdev->archive,