[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] NS2 problem with Packet::datalen() function (packet.h)



NS: 2.1b7
OS: Red Hat Linux release 7.0 (Guinness) (kernel 2.2.17-14smp)

Hello,

As you noticed, the function Packet::datalen() has a bug and returns
sizeof(AppData) instead of returning the real size of data that was allocated.
In fact, the virtual call of int size() function is not performed properly
between class AppData and class PacketData because functions have different
signatures:

virtual int AppData::size() const;

virtual int PacketData::size();

Const is missing in the second declaration. Therefore, those functions do not
have the same signatures and the virtual call cannot be performed.

To fix it, make PacketData::size() a CONST function.

in file packet.h:
virtual int size() const { return datalen_; } // Bug if const is missing

-- 
Arnaud TROEL - PhD Student - Solidor Project
IRISA-INRIA, Campus de Beaulieu, 35042 Rennes cedex, France
Phone: +33 (0) 2 99 84 72 93