cwUi.cpp : Fix problem in _get_msg_from_recv_buffer() where shift amount could exceed the elements in the buffer.

This commit is contained in:
kevin 2022-10-08 12:50:22 -04:00
parent f82c440e33
commit a4a6d21b13

View File

@ -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.
if( p->recvBufIdx > 0 )
{
for(i=0; p->recvBuf[i]!=0 and i<p->recvBufIdx; ++i)
{}
// if the end of the next msg was found
if( p->recvBuf[i] == 0 )
if( i<p->recvBufIdx && p->recvBuf[i] == 0 )
{
p->recvShiftN = i+1;
msg = p->recvBuf;
}
}
return msg;
}
}
}