From: Gerhard Sittig Date: Wed, 21 Feb 2018 16:55:07 +0000 (+0100) Subject: center-3xx: style nits, var decl vs assignment, copy loop vs memmove X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=0f6ff97bf8c6f5a586e106e92f1cc86b508f932e;p=libsigrok.git center-3xx: style nits, var decl vs assignment, copy loop vs memmove --- diff --git a/src/hardware/center-3xx/protocol.c b/src/hardware/center-3xx/protocol.c index 2a02b68e..81868b06 100644 --- a/src/hardware/center-3xx/protocol.c +++ b/src/hardware/center-3xx/protocol.c @@ -177,7 +177,7 @@ static gboolean 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, ret = FALSE; + int len, offset, ret = FALSE; devc = sdi->priv; serial = sdi->conn; @@ -193,6 +193,7 @@ static gboolean 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) >= center_devs[idx].packet_size) { if (center_devs[idx].packet_valid(devc->buf + offset)) { handle_packet(devc->buf + offset, sdi, idx); @@ -204,8 +205,8 @@ static gboolean 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; return ret;