From: Uwe Hermann Date: Tue, 25 Jul 2017 20:07:11 +0000 (+0200) Subject: drivers/input: Remove some hardcoded values. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=00ed77f27c85462cae238ee433dbf0f606eaaf84;p=libsigrok.git drivers/input: Remove some hardcoded values. --- diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index 01e56112..ce6f1f33 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -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) diff --git a/src/hardware/colead-slm/protocol.c b/src/hardware/colead-slm/protocol.c index b577f236..570e7db3 100644 --- a/src/hardware/colead-slm/protocol.c +++ b/src/hardware/colead-slm/protocol.c @@ -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. */ diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index b0cee61c..f533f1c5 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -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; diff --git a/src/input/binary.c b/src/input/binary.c index 91e4d3c4..01362137 100644 --- a/src/input/binary.c +++ b/src/input/binary.c @@ -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); } diff --git a/src/input/chronovu_la8.c b/src/input/chronovu_la8.c index 6c570733..531258ff 100644 --- a/src/input/chronovu_la8.c +++ b/src/input/chronovu_la8.c @@ -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); } diff --git a/src/input/trace32_ad.c b/src/input/trace32_ad.c index 8cbd4d07..7817457f 100644 --- a/src/input/trace32_ad.c +++ b/src/input/trace32_ad.c @@ -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++; diff --git a/src/input/wav.c b/src/input/wav.c index 35247112..a1751243 100644 --- a/src/input/wav.c +++ b/src/input/wav.c @@ -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); } diff --git a/src/session_driver.c b/src/session_driver.c index a102fdd7..c6af3b6d 100644 --- a/src/session_driver.c +++ b/src/session_driver.c @@ -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,