Skip to content

Commit 0ae67aa

Browse files
committed
add nullptr check, however...
this is just a good practice but in practice eth_if cannot be ever nullprt
1 parent 0108ded commit 0ae67aa

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: libraries/Ethernet/src/Ethernet.cpp

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

5353
int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) {
54+
if(eth_if == nullptr) {
55+
return 0;
56+
}
57+
5458
config(ip, dns, gateway, subnet);
5559

5660
eth_if->set_dhcp(false);
@@ -68,6 +72,9 @@ void arduino::EthernetClass::end() {
6872
}
6973

7074
EthernetLinkStatus arduino::EthernetClass::linkStatus() {
75+
if(eth_if == nullptr) {
76+
return LinkOFF;
77+
}
7178
return (eth_if->get_connection_status() == NSAPI_STATUS_GLOBAL_UP ? LinkON : LinkOFF);
7279
}
7380

@@ -77,7 +84,9 @@ EthernetHardwareStatus arduino::EthernetClass::hardwareStatus() {
7784

7885

7986
int arduino::EthernetClass::disconnect() {
80-
eth_if->disconnect();
87+
if(eth_if != nullptr) {
88+
eth_if->disconnect();
89+
}
8190
return 1;
8291
}
8392

0 commit comments

Comments
 (0)