[AGENT++] Improvements in Pdu::operator+=(const Vb&)
maom_onet at poczta.onet.pl
maom_onet at poczta.onet.pl
Mon Sep 20 14:22:49 CEST 2004
Hi,
the operator looks like this:
// append operator, appends a string
Pdu& Pdu::operator+=(const Vb &vb)
{
if (vb_count + 1> PDU_MAX_VBS) // do we have room?
return *this;
vbs[vb_count] = new Vb(vb); // add the new one
if (vbs[vb_count]) // up the vb count on success
{
++vb_count;
validity = true; // set up validity
}
return *this; // return self reference
}
First, the comment about appending a string is is a bit odd (copy&paste issue?). Second, I believe that the function should refuse to add an invalid Vb. Finally, it should check if the copy is valid.
E.g.,
if (vb_count + 1> PDU_MAX_VBS) // do we have room?
return *this;
if (!vb->valid())
return *this;
vbs[vb_count] = new Vb(vb); // add the new one
if (vbs[vb_count]) // up the vb count on success
{
if (vbs[vb_count]->valid())
{
++vb_count;
validity = true; // set up validity
}
else
{
delete vbs[vb_count];
vbs[vb_count] = 0; // ;-)
}
}
return *this; // return self reference
}
Marek
More information about the AGENTPP
mailing list