From: Gerhard Sittig Date: Wed, 7 Feb 2018 21:34:35 +0000 (+0100) Subject: serial-dmm: style nit (init vs assign, memmove(3)) X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=51e1f5661c7ff12fa902643d5c3f0fd0f7e43d52;p=libsigrok.git serial-dmm: style nit (init vs assign, memmove(3)) Move the initial assignment to the 'offset' variable to the very spot where it gets evaluated and subsequently manipulated. Replace a DIY copy loop with the corresponding memmove(3) call. --- diff --git a/src/hardware/serial-dmm/protocol.c b/src/hardware/serial-dmm/protocol.c index 39bd965b..9d3bc916 100644 --- a/src/hardware/serial-dmm/protocol.c +++ b/src/hardware/serial-dmm/protocol.c @@ -116,7 +116,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info) { struct dmm_info *dmm; struct dev_context *devc; - int len, i, offset = 0; + int len, offset; struct sr_serial_dev_inst *serial; dmm = (struct dmm_info *)sdi->driver; @@ -136,6 +136,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info) devc->buflen += len; /* Now look for packets in that data. */ + offset = 0; while ((devc->buflen - offset) >= dmm->packet_size) { if (dmm->packet_valid(devc->buf + offset)) { handle_packet(devc->buf + offset, sdi, info); @@ -154,8 +155,8 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info) } /* If we have any data left, move it to the beginning of our buffer. */ - for (i = 0; i < devc->buflen - offset; i++) - devc->buf[i] = devc->buf[offset + i]; + if (devc->buflen > offset) + memmove(devc->buf, devc->buf + offset, devc->buflen - offset); devc->buflen -= offset; }