Fix several potential null pointers

Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
Sara Damiano
2020-04-15 08:34:44 -04:00
parent eb9358f440
commit dbd677e6e7
4 changed files with 49 additions and 21 deletions

View File

@@ -315,7 +315,10 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
// if the status is anything but 3, there are no connections open // if the status is anything but 3, there are no connections open
waitResponse(); // Returns an OK after the status waitResponse(); // Returns an OK after the status
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) { for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
sockets[muxNo]->sock_connected = false; GsmClientESP8266* sock = sockets[muxNo];
if (sock) {
sock->sock_connected = false;
}
} }
return false; return false;
} }
@@ -336,7 +339,10 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
if (has_status == 2) break; // once we get to the ok, stop if (has_status == 2) break; // once we get to the ok, stop
} }
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) { for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
sockets[muxNo]->sock_connected = verified_connections[muxNo]; GsmClientESP8266* sock = sockets[muxNo];
if (sock) {
sock->sock_connected = verified_connections[muxNo];
}
} }
return verified_connections[mux]; return verified_connections[mux];
} }

View File

@@ -217,8 +217,13 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
bool restartImpl() { bool restartImpl() {
if (!testAT()) { return false; } if (!testAT()) { return false; }
sendAT(GF("+REBOOT")); sendAT(GF("+REBOOT"));
// Should return an 'OK' after reboot command is sent
if (waitResponse(10000L) != 1) { return false; } if (waitResponse(10000L) != 1) { return false; }
delay(3000L); // TODO(?): Test this delay! // After booting, modem sends out messages as each of its
// internal modules loads. The final message is "PB DONE".
if (waitResponse(40000L, GF(GSM_NL "PB DONE")) != 1) {
return false;
}
return init(); return init();
} }
@@ -574,7 +579,13 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
if (waitResponse(GF("+CIPCLOSE:")) != 1) { return false; } if (waitResponse(GF("+CIPCLOSE:")) != 1) { return false; }
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) { for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
// +CIPCLOSE:<link0_state>,<link1_state>,...,<link9_state> // +CIPCLOSE:<link0_state>,<link1_state>,...,<link9_state>
sockets[muxNo]->sock_connected = stream.parseInt(); bool thisMuxState = stream.parseInt();
// Need to make sure a socket instace for the socket number exists
// before setting its state
GsmClientSim5360* sock = sockets[muxNo];
if (sock) {
sock->sock_connected = thisMuxState;
}
} }
waitResponse(); // Should be an OK at the end waitResponse(); // Should be an OK at the end
return sockets[mux]->sock_connected; return sockets[mux]->sock_connected;

View File

@@ -672,7 +672,13 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
} }
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) { for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
// +CIPCLOSE:<link0_state>,<link1_state>,...,<link9_state> // +CIPCLOSE:<link0_state>,<link1_state>,...,<link9_state>
sockets[muxNo]->sock_connected = stream.parseInt(); bool thisMuxState = stream.parseInt();
// Need to make sure a socket instace for the socket number exists
// before setting its state
GsmClientSim7600* sock = sockets[muxNo];
if (sock) {
sock->sock_connected = thisMuxState;
}
} }
waitResponse(); // Should be an OK at the end waitResponse(); // Should be an OK at the end
return sockets[mux]->sock_connected; return sockets[mux]->sock_connected;

View File

@@ -571,7 +571,9 @@ class TinyGsmSequansMonarch
// six possible sockets. // six possible sockets.
sendAT(GF("+SQNSS")); sendAT(GF("+SQNSS"));
for (int muxNo = 1; muxNo <= TINY_GSM_MUX_COUNT; muxNo++) { for (int muxNo = 1; muxNo <= TINY_GSM_MUX_COUNT; muxNo++) {
if (waitResponse(GFP(GSM_OK), GF(GSM_NL "+SQNSS: ")) != 2) { break; } if (waitResponse(GFP(GSM_OK), GF(GSM_NL "+SQNSS: ")) != 2) {
break;
}
uint8_t status = 0; uint8_t status = 0;
// if (streamGetIntBefore(',') != muxNo) { // check the mux no // if (streamGetIntBefore(',') != muxNo) { // check the mux no
// DBG("### Warning: misaligned mux numbers!"); // DBG("### Warning: misaligned mux numbers!");
@@ -588,10 +590,13 @@ class TinyGsmSequansMonarch
// SOCK_LISTENING = 4, // SOCK_LISTENING = 4,
// SOCK_INCOMING = 5, // SOCK_INCOMING = 5,
// SOCK_OPENING = 6, // SOCK_OPENING = 6,
sockets[muxNo % TINY_GSM_MUX_COUNT]->sock_connected = GsmClientSequansMonarch* sock = sockets[mux % TINY_GSM_MUX_COUNT];
if (sock) {
sock->sock_connected =
((status != SOCK_CLOSED) && (status != SOCK_INCOMING) && ((status != SOCK_CLOSED) && (status != SOCK_INCOMING) &&
(status != SOCK_OPENING)); (status != SOCK_OPENING));
} }
}
waitResponse(); // Should be an OK at the end waitResponse(); // Should be an OK at the end
return sockets[mux % TINY_GSM_MUX_COUNT]->sock_connected; return sockets[mux % TINY_GSM_MUX_COUNT]->sock_connected;
} }
@@ -601,7 +606,7 @@ class TinyGsmSequansMonarch
*/ */
public: public:
// TODO(vshymanskyy): Optimize this! // TODO(vshymanskyy): Optimize this!
int8_t waitResponse(uint32_t timeout_ms, String& data, int8_t waitResponse(uint32_t timeout_ms, String & data,
GsmConstStr r1 = GFP(GSM_OK), GsmConstStr r1 = GFP(GSM_OK),
GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r2 = GFP(GSM_ERROR),
#if defined TINY_GSM_DEBUG #if defined TINY_GSM_DEBUG
@@ -705,6 +710,6 @@ class TinyGsmSequansMonarch
Stream& stream; Stream& stream;
GsmClientSequansMonarch* sockets[TINY_GSM_MUX_COUNT]; GsmClientSequansMonarch* sockets[TINY_GSM_MUX_COUNT];
const char* gsmNL = GSM_NL; const char* gsmNL = GSM_NL;
}; };
#endif // SRC_TINYGSMCLIENTSEQUANSMONARCH_H_ #endif // SRC_TINYGSMCLIENTSEQUANSMONARCH_H_