Make sur we always return even length

This commit is contained in:
Geoffrey Merck 2020-05-14 22:01:38 +02:00
parent c413c3a855
commit 2165b38379

View file

@ -107,6 +107,7 @@ unsigned int CFMNetwork::read(unsigned char* data, unsigned int space)
{
assert(data != NULL);
unsigned int bytes = m_buffer.dataSize();
if (bytes == 0U)
return 0U;
@ -114,6 +115,10 @@ unsigned int CFMNetwork::read(unsigned char* data, unsigned int space)
if (bytes < space)
space = bytes;
//we store usignedshorts, therefore ensure we always return and even number of data
if(space > 0 && space % 2 != 0)
space--;//round down to multiple of 2
m_buffer.getData(data, space);
return space;