summaryrefslogtreecommitdiffstats
path: root/src/plugins/canbus/tinycan
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2016-07-10 19:15:31 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2016-07-12 09:03:27 +0000
commit464eb11843cabfecf108724688fe172de250782e (patch)
treeff4b2bd74c0818852870b2d2459b1ed11fe0e739 /src/plugins/canbus/tinycan
parent4cd1146041e788ceb1d8fb283f5257e743579843 (diff)
Fix logic with the wrong priority of operations
The assignment '=' operator has a lower priority, than the comparison '==, !=' operators. Thus, the result of logical statements is wrong. Change-Id: Iab281f1f3dd95b59da94379fd68a45f75e2dd5ac Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/plugins/canbus/tinycan')
-rw-r--r--src/plugins/canbus/tinycan/tinycanbackend.cpp46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/plugins/canbus/tinycan/tinycanbackend.cpp b/src/plugins/canbus/tinycan/tinycanbackend.cpp
index 530959a..b86e5f9 100644
--- a/src/plugins/canbus/tinycan/tinycanbackend.cpp
+++ b/src/plugins/canbus/tinycan/tinycanbackend.cpp
@@ -170,21 +170,30 @@ bool TinyCanBackendPrivate::open()
{
Q_Q(TinyCanBackend);
- char options[] = "AutoConnect=1;AutoReopen=0";
- if (int ret = ::CanSetOptions(options) < 0) {
- q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
- return false;
+ {
+ char options[] = "AutoConnect=1;AutoReopen=0";
+ const int ret = ::CanSetOptions(options);
+ if (ret < 0) {
+ q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
+ return false;
+ }
}
- if (int ret = ::CanDeviceOpen(channelIndex, nullptr) < 0) {
- q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
- return false;
+ {
+ const int ret = ::CanDeviceOpen(channelIndex, nullptr);
+ if (ret < 0) {
+ q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
+ return false;
+ }
}
- if (int ret = ::CanSetMode(channelIndex, OP_CAN_START, CAN_CMD_ALL_CLEAR) < 0) {
- q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
- ::CanDeviceClose(channelIndex);
- return false;
+ {
+ const int ret = ::CanSetMode(channelIndex, OP_CAN_START, CAN_CMD_ALL_CLEAR);
+ if (ret < 0) {
+ q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
+ ::CanDeviceClose(channelIndex);
+ return false;
+ }
}
isOpen = true;
@@ -195,7 +204,8 @@ void TinyCanBackendPrivate::close()
{
Q_Q(TinyCanBackend);
- if (int ret = ::CanDeviceClose(channelIndex) < 0)
+ const int ret = ::CanDeviceClose(channelIndex);
+ if (ret < 0)
q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
isOpen = false;
@@ -353,7 +363,8 @@ void TinyCanBackendPrivate::canWriteNotification()
const qint32 messagesToWrite = 1;
::memcpy(message.Data.Bytes, payload.constData(), sizeof(message.Data.Bytes));
- if (int ret = ::CanTransmit(channelIndex, &message, messagesToWrite) < 0)
+ const int ret = ::CanTransmit(channelIndex, &message, messagesToWrite);
+ if (ret < 0)
q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::WriteError);
else
emit q->framesWritten(messagesToWrite);
@@ -386,7 +397,8 @@ void TinyCanBackendPrivate::canReadNotification()
::memset(&message, 0, sizeof(message));
const int messagesToRead = 1;
- if (int ret = ::CanReceive(channelIndex, &message, messagesToRead) < 0) {
+ const int ret = ::CanReceive(channelIndex, &message, messagesToRead);
+ if (ret < 0) {
q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ReadError);
TDeviceStatus status;
@@ -428,7 +440,8 @@ void TinyCanBackendPrivate::startupDriver()
Q_Q(TinyCanBackend);
if (driverRefCount == 0) {
- if (int ret = ::CanInitDriver(nullptr) < 0) {
+ const int ret = ::CanInitDriver(nullptr);
+ if (ret < 0) {
q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError);
return;
}
@@ -468,7 +481,8 @@ bool TinyCanBackendPrivate::setBitRate(int bitrate)
}
if (isOpen) {
- if (int ret = ::CanSetSpeed(channelIndex, bitrateCode) < 0) {
+ const int ret = ::CanSetSpeed(channelIndex, bitrateCode);
+ if (ret < 0) {
q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConfigurationError);
return false;
}