From 4fc79291b9b68d0f6a99dc8223a5d2ffcffac817 Mon Sep 17 00:00:00 2001 From: "Peter D. Barnes, Jr." Date: Wed, 22 May 2013 12:57:58 -0700 Subject: [PATCH] Use PacketTagList::TagData::MAX_SIZE in DeviceNameTag --- src/network/utils/packet-socket.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/network/utils/packet-socket.cc b/src/network/utils/packet-socket.cc index 881bca33c..b8d81edc8 100644 --- a/src/network/utils/packet-socket.cc +++ b/src/network/utils/packet-socket.cc @@ -617,19 +617,20 @@ DeviceNameTag::GetInstanceTypeId (void) const uint32_t DeviceNameTag::GetSerializedSize (void) const { - uint32_t s = 1 + m_deviceName.size(); - return ( s >= PACKET_TAG_MAX_SIZE)?PACKET_TAG_MAX_SIZE:s; + uint32_t s = 1 + m_deviceName.size(); // +1 for name length field + s = std::min (s, (uint32_t)PacketTagList::TagData::MAX_SIZE); + return s; } void DeviceNameTag::Serialize (TagBuffer i) const { const char *n = m_deviceName.c_str(); - uint8_t l = (uint8_t) strlen (n); + uint8_t l = (uint8_t) m_deviceName.size (); - if ( ( 1 + l ) > PACKET_TAG_MAX_SIZE ) l = PACKET_TAG_MAX_SIZE - 1; + l = std::min ((uint32_t)l, (uint32_t)PacketTagList::TagData::MAX_SIZE - 1); i.WriteU8 (l); - i.Write ( (uint8_t*) n , (uint32_t) l ); + i.Write ( (uint8_t*) n , (uint32_t) l); } void DeviceNameTag::Deserialize (TagBuffer i)