Skip to content

Commit

Permalink
The return value has to be initialized to false and set to true only …
Browse files Browse the repository at this point in the history
…when successful
  • Loading branch information
tbnobody authored Jul 12, 2023
1 parent 054d9be commit f909638
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/MqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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();
}
Expand Down

0 comments on commit f909638

Please sign in to comment.