mirror of
				https://github.com/KevinMidboe/TinyGSM.git
				synced 2025-10-29 18:00:18 +00:00 
			
		
		
		
	Fix several potential null pointers
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
		| @@ -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]; | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -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; | ||||||
|   | |||||||
| @@ -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; | ||||||
|   | |||||||
| @@ -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,28 +590,31 @@ 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]; | ||||||
|           ((status != SOCK_CLOSED) && (status != SOCK_INCOMING) && |       if (sock) { | ||||||
|            (status != SOCK_OPENING)); |         sock->sock_connected = | ||||||
|  |             ((status != SOCK_CLOSED) && (status != SOCK_INCOMING) && | ||||||
|  |              (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; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /* |     /* | ||||||
|    * Utilities |      * Utilities | ||||||
|    */ |      */ | ||||||
|  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 | ||||||
|                       GsmConstStr r3 = GFP(GSM_CME_ERROR), |                         GsmConstStr r3 = GFP(GSM_CME_ERROR), | ||||||
| #else | #else | ||||||
|                       GsmConstStr r3 = NULL, |                         GsmConstStr r3 = NULL, | ||||||
| #endif | #endif | ||||||
|                       GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { |                         GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { | ||||||
|     /*String r1s(r1); r1s.trim(); |     /*String r1s(r1); r1s.trim(); | ||||||
|     String r2s(r2); r2s.trim(); |     String r2s(r2); r2s.trim(); | ||||||
|     String r3s(r3); r3s.trim(); |     String r3s(r3); r3s.trim(); | ||||||
| @@ -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_ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user