Use PacketTagList::TagData::MAX_SIZE in DeviceNameTag ptl
authorPeter D. Barnes, Jr. <barnes26@llnl.gov>
Wed, 22 May 2013 12:57:58 -0700
branchptl
changeset 9770 d9bc7131bb68
parent 9769 44c102578159
child 9771 ddea5860c58c
child 9772 698340cf6d37
Use PacketTagList::TagData::MAX_SIZE in DeviceNameTag
src/network/utils/packet-socket.cc
--- a/src/network/utils/packet-socket.cc	Wed Nov 14 00:07:50 2012 -0800
+++ b/src/network/utils/packet-socket.cc	Wed May 22 12:57:58 2013 -0700
@@ -617,19 +617,20 @@
 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)