From: Gerhard Sittig Date: Wed, 21 Feb 2018 17:04:29 +0000 (+0100) Subject: link-mso19: improve endianess conversion, avoid mem access alignment issue X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=411b2f68227398fa7bdde653a37d3e739277fc08;p=libsigrok.git link-mso19: improve endianess conversion, avoid mem access alignment issue Prefer sigrok's endianess conversion helper over the inet htons() routine which is harder to read (is "network order" little or big?). Writing the conversion results in units of bytes also avoids misaligned memory access. The header length is odd, each payload item got written as an uint16_t item to an odd address. --- diff --git a/src/hardware/link-mso19/protocol.c b/src/hardware/link-mso19/protocol.c index b0cb2d8a..8721ec2b 100644 --- a/src/hardware/link-mso19/protocol.c +++ b/src/hardware/link-mso19/protocol.c @@ -48,8 +48,8 @@ SR_PRIV int mso_send_control_message(struct sr_serial_dev_inst *serial, p += sizeof(mso_head); for (i = 0; i < n; i++) { - *(uint16_t *) p = g_htons(payload[i]); - p += 2; + WB16(p, payload[i]); + p += sizeof(uint16_t); } memcpy(p, mso_foot, sizeof(mso_foot));