From a4a6d21b138b95b3ed3994e0fd78a88b698d400a Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 8 Oct 2022 12:50:22 -0400 Subject: [PATCH] cwUi.cpp : Fix problem in _get_msg_from_recv_buffer() where shift amount could exceed the elements in the buffer. --- cwUi.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/cwUi.cpp b/cwUi.cpp index 285fb4e..da8df6d 100644 --- a/cwUi.cpp +++ b/cwUi.cpp @@ -1058,6 +1058,7 @@ namespace cw return cwLogError(kBufTooSmallRC,"The UI input buffer (%i) is too small.", p->recvBufN); memcpy(p->recvBuf + p->recvBufIdx, msg, msgByteN ); + p->recvBufIdx += msgByteN; return kOkRC; @@ -1080,21 +1081,21 @@ namespace cw } // locate the end of the next msg. - for(i=0; p->recvBuf[i]!=0 and irecvBufIdx; ++i) - {} - - // if the end of the next msg was found - if( p->recvBuf[i] == 0 ) + if( p->recvBufIdx > 0 ) { - p->recvShiftN = i+1; - msg = p->recvBuf; + for(i=0; p->recvBuf[i]!=0 and irecvBufIdx; ++i) + {} + + // if the end of the next msg was found + if( irecvBufIdx && p->recvBuf[i] == 0 ) + { + p->recvShiftN = i+1; + msg = p->recvBuf; + } } - + return msg; } - - - } }