Skip to content

Commit 3749dc1

Browse files
maidnlpennam
authored andcommitted
Ethernet: add eth_if nullptr checks
1 parent 3e6aa5e commit 3749dc1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

libraries/Ethernet/src/Ethernet.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPA
4949
}
5050

5151
int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) {
52+
if(eth_if == nullptr) {
53+
return 0;
54+
}
55+
5256
config(ip, dns, gateway, subnet);
5357

5458
eth_if->set_dhcp(false);
@@ -66,6 +70,9 @@ void arduino::EthernetClass::end() {
6670
}
6771

6872
EthernetLinkStatus arduino::EthernetClass::linkStatus() {
73+
if(eth_if == nullptr) {
74+
return LinkOFF;
75+
}
6976
return (eth_if->get_connection_status() == NSAPI_STATUS_GLOBAL_UP ? LinkON : LinkOFF);
7077
}
7178

@@ -75,7 +82,9 @@ EthernetHardwareStatus arduino::EthernetClass::hardwareStatus() {
7582

7683

7784
int arduino::EthernetClass::disconnect() {
78-
eth_if->disconnect();
85+
if(eth_if != nullptr) {
86+
eth_if->disconnect();
87+
}
7988
return 1;
8089
}
8190

0 commit comments

Comments
 (0)