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); return cwLogError(kBufTooSmallRC,"The UI input buffer (%i) is too small.", p->recvBufN);
memcpy(p->recvBuf + p->recvBufIdx, msg, msgByteN ); memcpy(p->recvBuf + p->recvBufIdx, msg, msgByteN );
p->recvBufIdx += msgByteN; p->recvBufIdx += msgByteN;
return kOkRC; return kOkRC;
@ -1080,21 +1081,21 @@ namespace cw
} }
// locate the end of the next msg. // locate the end of the next msg.
for(i=0; p->recvBuf[i]!=0 and i<p->recvBufIdx; ++i) if( p->recvBufIdx > 0 )
{}
// if the end of the next msg was found
if( p->recvBuf[i] == 0 )
{ {
p->recvShiftN = i+1; for(i=0; p->recvBuf[i]!=0 and i<p->recvBufIdx; ++i)
msg = p->recvBuf; {}
// if the end of the next msg was found
if( i<p->recvBufIdx && p->recvBuf[i] == 0 )
{
p->recvShiftN = i+1;
msg = p->recvBuf;
}
} }
return msg; return msg;
} }
} }
} }