From 0ae67aa271333a14e2c75920e2cb79439ec141be Mon Sep 17 00:00:00 2001 From: maidnl Date: Mon, 17 Jun 2024 12:00:48 +0200 Subject: [PATCH] add nullptr check, however... this is just a good practice but in practice eth_if cannot be ever nullprt --- libraries/Ethernet/src/Ethernet.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 2e0f1a94f..a33a03bbe 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -51,6 +51,10 @@ int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPA } int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) { + if(eth_if == nullptr) { + return 0; + } + config(ip, dns, gateway, subnet); eth_if->set_dhcp(false); @@ -68,6 +72,9 @@ void arduino::EthernetClass::end() { } EthernetLinkStatus arduino::EthernetClass::linkStatus() { + if(eth_if == nullptr) { + return LinkOFF; + } return (eth_if->get_connection_status() == NSAPI_STATUS_GLOBAL_UP ? LinkON : LinkOFF); } @@ -77,7 +84,9 @@ EthernetHardwareStatus arduino::EthernetClass::hardwareStatus() { int arduino::EthernetClass::disconnect() { - eth_if->disconnect(); + if(eth_if != nullptr) { + eth_if->disconnect(); + } return 1; }