From 58ec60b247300636a825fa1322757ab49e2f07f9 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Sun, 17 Apr 2022 17:11:14 +0200 Subject: [PATCH] Fix incorrect use of variable 'dup' --- mqttpacket.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mqttpacket.cpp b/mqttpacket.cpp index fed7cbb..1fc8ab0 100644 --- a/mqttpacket.cpp +++ b/mqttpacket.cpp @@ -845,13 +845,13 @@ void MqttPacket::handleUnsubscribe() void MqttPacket::parsePublishData() { publishData.retain = (first_byte & 0b00000001); - bool dup = !!(first_byte & 0b00001000); + const bool duplicate = !!(first_byte & 0b00001000); publishData.qos = (first_byte & 0b00000110) >> 1; if (publishData.qos > 2) throw ProtocolError("QoS 3 is a protocol violation.", ReasonCodes::MalformedPacket); - if (publishData.qos == 0 && dup) + if (publishData.qos == 0 && duplicate) throw ProtocolError("Duplicate flag is set for QoS 0 packet. This is illegal.", ReasonCodes::MalformedPacket); publishData.topic = readBytesToString(true, true); @@ -957,7 +957,8 @@ void MqttPacket::handlePublish() parsePublishData(); #ifndef NDEBUG - logger->logf(LOG_DEBUG, "Publish received, topic '%s'. QoS=%d. Retain=%d, dup=%d", publishData.topic.c_str(), publishData.qos, publishData.retain, dup); + const bool duplicate = !!(first_byte & 0b00001000); + logger->logf(LOG_DEBUG, "Publish received, topic '%s'. QoS=%d. Retain=%d, dup=%d", publishData.topic.c_str(), publishData.qos, publishData.retain, duplicate); #endif ReasonCodes ackCode = ReasonCodes::Success; -- libgit2 0.21.4