From 240388ed7b17b8f0b426248c6d66a1034f208c6c Mon Sep 17 00:00:00 2001 From: Mike Cookson <144849826+mgcookson@users.noreply.github.com> Date: Mon, 17 Mar 2025 16:55:50 -0400 Subject: [PATCH 1/2] Do not attempt to read fixed sized result data when indicated length of that data is zero --- libraries/WiFiS3/src/Modem.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/WiFiS3/src/Modem.cpp b/libraries/WiFiS3/src/Modem.cpp index d20b1bc7..9665634c 100644 --- a/libraries/WiFiS3/src/Modem.cpp +++ b/libraries/WiFiS3/src/Modem.cpp @@ -298,6 +298,9 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_ sized_read_size = atoi(data_res.c_str()); data_res.clear(); + if (sized_read_size == 0) { + state = at_parse_state_t::Res; + } } else if(c == '\r') { state = at_parse_state_t::ResWaitLF; } else if(c == '\n') { From f048f7f439ff4051152c1ab96819a557c34dd2ae Mon Sep 17 00:00:00 2001 From: Mike Cookson <144849826+mgcookson@users.noreply.github.com> Date: Tue, 18 Mar 2025 11:09:10 -0400 Subject: [PATCH 2/2] Improve code readability --- libraries/WiFiS3/src/Modem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/WiFiS3/src/Modem.cpp b/libraries/WiFiS3/src/Modem.cpp index 9665634c..44303d9a 100644 --- a/libraries/WiFiS3/src/Modem.cpp +++ b/libraries/WiFiS3/src/Modem.cpp @@ -289,16 +289,16 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_ * in case multiple parameters separated by ',' are sent, they will be present in data_res * - if we encounter we need to wait for * - if we encounter we need to parse the response status - * - if we encounter '|', the next token will contain binary sized data, the current value in + * - if we encounter '|', the next token will contain binary sized data, the current value * in data_res contains the length of the next token */ if(c == '|') { // sized read, the previous parameter is the length - state = at_parse_state_t::Sized; - sized_read_size = atoi(data_res.c_str()); data_res.clear(); - if (sized_read_size == 0) { + if (sized_read_size != 0) { + state = at_parse_state_t::Sized; + } else { state = at_parse_state_t::Res; } } else if(c == '\r') {