From a9f8080ee76e02c22621177f921db301bc26924c Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 12 Aug 2021 22:06:51 -0700 Subject: [PATCH] cope with race on available() vs read() found while looking at #838 --- src/mesh/StreamAPI.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mesh/StreamAPI.cpp b/src/mesh/StreamAPI.cpp index 3e52506c..e930f4f7 100644 --- a/src/mesh/StreamAPI.cpp +++ b/src/mesh/StreamAPI.cpp @@ -26,7 +26,11 @@ int32_t StreamAPI::readStream() return recentRx ? 5 : 250; } else { while (stream->available()) { // Currently we never want to block - uint8_t c = stream->read(); + int cInt = stream->read(); + if(cInt < 0) + break; // We ran out of characters (even though available said otherwise) - this can happen on rf52 adafruit arduino + + uint8_t c = (uint8_t) cInt; // Use the read pointer for a little state machine, first look for framing, then length bytes, then payload size_t ptr = rxPtr;