network: fix static code analysys warnings (thanks to Natale Patriciello)

This commit is contained in:
Tommaso Pecorella
2017-02-16 22:57:45 +01:00
parent cf60d40b72
commit 5de3f7525c
3 changed files with 14 additions and 21 deletions

View File

@@ -632,16 +632,18 @@ Buffer::Serialize (uint8_t* buffer, uint32_t maxSize) const
// Add the actual data
if (size + ((dataEndLength + 3) & (~3)) <= maxSize)
{
size += (dataEndLength + 3) & (~3);
memcpy (p, m_data->m_data+m_zeroAreaStart,dataEndLength);
p += (((dataEndLength + 3) & (~3))/4); // Advance p, insuring 4 byte boundary
// The following line is unnecessary.
// size += (dataEndLength + 3) & (~3);
memcpy (p, m_data->m_data+m_zeroAreaStart, dataEndLength);
// The following line is unnecessary.
// p += (((dataEndLength + 3) & (~3))/4); // Advance p, insuring 4 byte boundary
}
else
{
return 0;
}
// Serialzed everything successfully
// Serialized everything successfully
return 1;
}
@@ -680,7 +682,8 @@ Buffer::Deserialize (const uint8_t *buffer, uint32_t size)
Buffer::Iterator tmp = End ();
tmp.Prev (dataEndLength);
tmp.Write (reinterpret_cast<uint8_t *> (const_cast<uint32_t *> (p)), dataEndLength);
p += (((dataEndLength+3)&(~3))/4); // Advance p, insuring 4 byte boundary
// The following line is unnecessary.
// p += (((dataEndLength+3)&(~3))/4); // Advance p, insuring 4 byte boundary
sizeCheck -= ((dataEndLength+3)&(~3));
NS_ASSERT (sizeCheck == 0);

View File

@@ -188,9 +188,9 @@ PacketMetadata::ReadUleb128 (const uint8_t **pBuffer) const
{
NS_LOG_FUNCTION (this << &pBuffer);
const uint8_t *buffer = *pBuffer;
uint32_t result = 0;
uint32_t result;
uint8_t byte;
result = 0;
byte = buffer[0];
result = (byte & (~0x80));
if (!(byte & 0x80))
@@ -263,7 +263,6 @@ PacketMetadata::AppendValueExtra (uint32_t value, uint8_t *buffer)
byte = value & (~0x80);
buffer[1] = 0x80 | byte;
value >>= 7;
byte = value & (~0x80);
buffer[2] = value;
return;
}
@@ -586,8 +585,8 @@ PacketMetadata::Create (uint32_t size)
data->m_count = 1;
return data;
}
PacketMetadata::Deallocate (data);
NS_LOG_LOGIC ("create dealloc size="<<data->m_size);
PacketMetadata::Deallocate (data);
}
NS_LOG_LOGIC ("create alloc size="<<m_maxSize);
return PacketMetadata::Allocate (m_maxSize);

View File

@@ -653,8 +653,7 @@ Packet::Serialize (uint8_t* buffer, uint32_t maxSize) const
size += metaSize;
// serialize the metadata
uint32_t serialized =
m_metadata.Serialize (reinterpret_cast<uint8_t *> (p), metaSize);
uint32_t serialized = m_metadata.Serialize (reinterpret_cast<uint8_t *> (p), metaSize);
if (serialized)
{
// increment p by metaSize bytes
@@ -679,18 +678,10 @@ Packet::Serialize (uint8_t* buffer, uint32_t maxSize) const
// buffer. this includes 4-bytes for total
// length itself
*p++ = bufSize + 4;
size += bufSize;
// serialize the buffer
uint32_t serialized =
m_buffer.Serialize (reinterpret_cast<uint8_t *> (p), bufSize);
if (serialized)
{
// increment p by bufSize bytes
// ensuring 4-byte boundary
p += ((bufSize+3) & (~3)) / 4;
}
else
uint32_t serialized = m_buffer.Serialize (reinterpret_cast<uint8_t *> (p), bufSize);
if (!serialized)
{
return 0;
}