From: Gerhard Sittig Date: Wed, 21 Feb 2018 16:58:41 +0000 (+0100) Subject: mic-985xx: style nits, var decl vs assignment, copy loop vs memmove X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c3720703330000d837ca0ca2895082ffe362452c;p=libsigrok.git mic-985xx: style nits, var decl vs assignment, copy loop vs memmove --- diff --git a/src/hardware/mic-985xx/protocol.c b/src/hardware/mic-985xx/protocol.c index af567ebd..2218f32b 100644 --- a/src/hardware/mic-985xx/protocol.c +++ b/src/hardware/mic-985xx/protocol.c @@ -150,7 +150,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, int idx) { struct dev_context *devc; struct sr_serial_dev_inst *serial; - int len, i, offset = 0; + int len, offset; devc = sdi->priv; serial = sdi->conn; @@ -166,6 +166,7 @@ static void handle_new_data(struct sr_dev_inst *sdi, int idx) devc->buflen += len; /* Now look for packets in that data. */ + offset = 0; while ((devc->buflen - offset) >= mic_devs[idx].packet_size) { if (mic_devs[idx].packet_valid(devc->buf + offset)) { handle_packet(devc->buf + offset, sdi, idx); @@ -176,8 +177,8 @@ static void handle_new_data(struct sr_dev_inst *sdi, int idx) } /* 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; }