From: Gerhard Sittig Date: Wed, 21 Feb 2018 16:56:50 +0000 (+0100) Subject: kern-scale: style nits, var decl vs assignment, copy loop vs memmove X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7a65106e00dd64503bb160c0bb945baee76d0f63;p=libsigrok.git kern-scale: style nits, var decl vs assignment, copy loop vs memmove --- diff --git a/src/hardware/kern-scale/protocol.c b/src/hardware/kern-scale/protocol.c index 5d3541df..722e0625 100644 --- a/src/hardware/kern-scale/protocol.c +++ b/src/hardware/kern-scale/protocol.c @@ -65,7 +65,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, void *info) { struct scale_info *scale; struct dev_context *devc; - int len, i, offset = 0; + int len, offset; struct sr_serial_dev_inst *serial; scale = (struct scale_info *)sdi->driver; @@ -85,6 +85,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) >= scale->packet_size) { if (scale->packet_valid(devc->buf + offset)) { handle_packet(devc->buf + offset, sdi, info); @@ -95,8 +96,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 (offset < devc->buflen) + memmove(devc->buf, devc->buf + offset, devc->buflen - offset); devc->buflen -= offset; }