summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Shachnev <mitya57@gmail.com>2018-11-10 13:08:25 +0300
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-11-11 08:58:27 +0000
commitafb7f76efafcb04e430168416d9d74113bde13bc (patch)
tree85660001867ae5bfb3bea7260ff03878b7629df9
parent200822ca61732693cc97802b953cd846654eb319 (diff)
Make pduFromStream work on big endian
(char *) (&code) is pointing to the correct byte on little endian systems, but on big endian it is pointing to the wrong byte. This caused tst_QModbusPdu::testQModbusResponseStreamOperator to fail on big endian. Change-Id: Icf374ed71429154b362fb074fbeb5501ea6095e0 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Lisandro Damián Nicanor Pérez Meyer <perezmeyer@gmail.com>
-rw-r--r--src/serialbus/qmodbuspdu.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/serialbus/qmodbuspdu.cpp b/src/serialbus/qmodbuspdu.cpp
index 350dc76..d3870f8 100644
--- a/src/serialbus/qmodbuspdu.cpp
+++ b/src/serialbus/qmodbuspdu.cpp
@@ -105,9 +105,10 @@ static int minimumDataSize(const QModbusPdu &pdu, Type type)
static QDataStream &pduFromStream(QDataStream &stream, QModbusPdu &pdu, Type type)
{
- QModbusPdu::FunctionCode code = QModbusPdu::Invalid;
- if (stream.readRawData((char *) (&code), sizeof(quint8)) != sizeof(quint8))
+ quint8 codeByte = 0;
+ if (stream.readRawData((char *) (&codeByte), sizeof(quint8)) != sizeof(quint8))
return stream;
+ QModbusPdu::FunctionCode code = (QModbusPdu::FunctionCode) codeByte;
pdu.setFunctionCode(code);
auto needsAdditionalRead = [](QModbusPdu &pdu, int size) -> bool {