From f909638d71209532b2d3197fd72a56fb52a087be Mon Sep 17 00:00:00 2001 From: tbnobody Date: Wed, 12 Jul 2023 16:59:16 +0200 Subject: [PATCH] The return value has to be initialized to false and set to true only when successful --- src/MqttClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index 6a804d2..361f503 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -101,7 +101,7 @@ bool MqttClient::disconnected() const { } bool MqttClient::connect() { - bool result = true; + bool result = false; if (_state == State::disconnected) { EMC_SEMAPHORE_TAKE(); if (_addPacketFront(_cleanSession, @@ -114,6 +114,7 @@ bool MqttClient::connect() { _willPayloadLength, (uint16_t)(_keepAlive / 1000), // 32b to 16b doesn't overflow because it comes from 16b orignally _clientId)) { + result = true; _state = State::connectingTcp1; #if defined(ARDUINO_ARCH_ESP32) if (_useInternalTask == espMqttClientTypes::UseInternalTask::YES) { @@ -124,7 +125,6 @@ bool MqttClient::connect() { EMC_SEMAPHORE_GIVE(); emc_log_e("Could not create CONNECT packet"); _onError(0, Error::OUT_OF_MEMORY); - result = false; } EMC_SEMAPHORE_GIVE(); }