Skip to content

Commit

Permalink
fix(modem): Fixed clang-tidy warnings
Browse files Browse the repository at this point in the history
* private field 'netif' is not used [clang-diagnostic-unused-private-field]
* private field 'instance' is not used [clang-diagnostic-unused-private-field]
* Call to virtual method 'FdTerminal::stop' during destruction bypasses virtual dispatch [clang-analyzer-optin.cplusplus.VirtualCall]
* unused variable 'TAG' [clang-diagnostic-unused-const-variable]
* Null pointer passed as 2nd argument to memory copy function [clang-analyzer-unix.cstring.NullArg]
* Array access (from variable 'data') results in a null pointer dereference [clang-analyzer-core.NullDereference]
  • Loading branch information
david-cermak committed Jun 7, 2024
1 parent 5d69d3f commit 70fa3af
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class CMux {
size_t frame_header_offset;
uint8_t *payload_start;
size_t total_payload_size;
int instance;
int sabm_ack;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class Netif {
static void on_ppp_changed(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);

std::shared_ptr<DTE> ppp_dte;
esp_netif_t *netif;
struct ppp_netif_driver driver {};
SignalGroup signal;
static const size_t PPP_STARTED = SignalGroup::bit0;
Expand Down
5 changes: 4 additions & 1 deletion components/esp_modem/src/esp_modem_cmux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool CMux::data_available(uint8_t *data, size_t len)
return false;
}
} else if ((type & FT_UIH) == FT_UIH && dlci == 0) { // notify the internal DISC command
if ((len > 0 && (data[0] & 0xE1) == 0xE1) || (data == nullptr)) {
if ((data == nullptr) || (len > 0 && (data[0] & 0xE1) == 0xE1)) {
// Not a DISC, ignore (MSC frame)
return true;
}
Expand Down Expand Up @@ -346,6 +346,9 @@ bool CMux::on_cmux_data(uint8_t *data, size_t actual_len)
actual_len = term->read(data, buffer.size);
#endif
}
if (data == nullptr) {
return false;
}
ESP_LOG_BUFFER_HEXDUMP("CMUX Received", data, actual_len, ESP_LOG_VERBOSE);
CMuxFrame frame = { .ptr = data, .len = actual_len };
while (frame.len > 0) {
Expand Down
2 changes: 1 addition & 1 deletion components/esp_modem/src/esp_modem_netif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void Netif::receive(uint8_t *data, size_t len)
}

Netif::Netif(std::shared_ptr<DTE> e, esp_netif_t *ppp_netif) :
ppp_dte(std::move(e)), netif(ppp_netif)
ppp_dte(std::move(e))
{
driver.base.netif = ppp_netif;
driver.ppp = this;
Expand Down
14 changes: 9 additions & 5 deletions components/esp_modem/src/esp_modem_netif_linux.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -29,20 +29,24 @@ esp_err_t Netif::esp_modem_post_attach(esp_netif_t *esp_netif, void *args)

void Netif::receive(uint8_t *data, size_t len)
{
esp_netif_receive(netif, data, len);
esp_netif_receive(driver.base.netif, data, len);
}

Netif::Netif(std::shared_ptr<DTE> e, esp_netif_t *ppp_netif) :
ppp_dte(std::move(e)), netif(ppp_netif) {}
ppp_dte(std::move(e))
{
driver.base.netif = ppp_netif;
driver.ppp = this;
}

void Netif::start()
{
ppp_dte->set_read_cb([this](uint8_t *data, size_t len) -> bool {
receive(data, len);
return true;
});
netif->transmit = esp_modem_dte_transmit;
netif->ctx = (void *)this;
driver.base.netif->transmit = esp_modem_dte_transmit;
driver.base.netif->ctx = (void *)this;
signal.set(PPP_STARTED);
}

Expand Down
2 changes: 1 addition & 1 deletion components/esp_modem/src/esp_modem_term_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int FdTerminal::write(uint8_t *data, size_t len)

FdTerminal::~FdTerminal()
{
stop();
FdTerminal::stop();
}

} // namespace esp_modem
2 changes: 1 addition & 1 deletion components/esp_modem/src/esp_modem_vfs_uart_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "uart_resource.hpp"
#include "vfs_resource/vfs_create.hpp"

constexpr const char *TAG = "vfs_uart_creator";
[[maybe_unused]] constexpr const char *TAG = "vfs_uart_creator";


struct esp_modem_vfs_resource {
Expand Down

0 comments on commit 70fa3af

Please sign in to comment.