bug 217: avoid unsigned/signed confusion. Used signed all the time.

This commit is contained in:
Mathieu Lacage
2008-06-21 08:11:10 -07:00
parent 9008e089ae
commit 0c35c2b60f
2 changed files with 36 additions and 25 deletions

View File

@@ -25,6 +25,7 @@ NS_LOG_COMPONENT_DEFINE ("TagList");
#define USE_FREE_LIST 1
#define FREE_LIST_SIZE 1000
#define OFFSET_MAX (2147483647)
namespace ns3 {
@@ -99,7 +100,7 @@ TagList::Iterator::PrepareForNext (void)
}
}
}
TagList::Iterator::Iterator (uint8_t *start, uint8_t *end, uint32_t offsetStart, uint32_t offsetEnd)
TagList::Iterator::Iterator (uint8_t *start, uint8_t *end, int32_t offsetStart, int32_t offsetEnd)
: m_current (start),
m_end (end),
m_offsetStart (offsetStart),
@@ -158,7 +159,7 @@ TagList::~TagList ()
}
TagBuffer
TagList::Add (TypeId tid, uint32_t bufferSize, uint32_t start, uint32_t end)
TagList::Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
{
NS_LOG_FUNCTION (this << tid << bufferSize << start << end);
uint32_t spaceNeeded = m_used + bufferSize + 4 + 4 + 4 + 4;
@@ -191,7 +192,7 @@ void
TagList::Add (const TagList &o)
{
NS_LOG_FUNCTION (this << &o);
TagList::Iterator i = o.Begin (0, 0xffffffff);
TagList::Iterator i = o.BeginAll ();
while (i.HasNext ())
{
TagList::Iterator::Item item = i.Next ();
@@ -210,7 +211,16 @@ TagList::RemoveAll (void)
}
TagList::Iterator
TagList::Begin (uint32_t offsetStart, uint32_t offsetEnd) const
TagList::BeginAll (void) const
{
NS_LOG_FUNCTION (this);
// I am not totally sure but I might need to use
// INT32_MIN instead of zero below.
return Begin (0, OFFSET_MAX);
}
TagList::Iterator
TagList::Begin (int32_t offsetStart, int32_t offsetEnd) const
{
NS_LOG_FUNCTION (this << offsetStart << offsetEnd);
if (m_data == 0)
@@ -224,10 +234,10 @@ TagList::Begin (uint32_t offsetStart, uint32_t offsetEnd) const
}
bool
TagList::IsDirtyAtEnd (uint32_t appendOffset)
TagList::IsDirtyAtEnd (int32_t appendOffset)
{
NS_LOG_FUNCTION (this << appendOffset);
TagList::Iterator i = Begin (0, 0xffffffff);
TagList::Iterator i = BeginAll ();
while (i.HasNext ())
{
TagList::Iterator::Item item = i.Next ();
@@ -240,10 +250,10 @@ TagList::IsDirtyAtEnd (uint32_t appendOffset)
}
bool
TagList::IsDirtyAtStart (uint32_t prependOffset)
TagList::IsDirtyAtStart (int32_t prependOffset)
{
NS_LOG_FUNCTION (this << prependOffset);
TagList::Iterator i = Begin (0, 0xffffffff);
TagList::Iterator i = BeginAll ();
while (i.HasNext ())
{
TagList::Iterator::Item item = i.Next ();
@@ -256,7 +266,7 @@ TagList::IsDirtyAtStart (uint32_t prependOffset)
}
void
TagList::AddAtEnd (int32_t adjustment, uint32_t appendOffset)
TagList::AddAtEnd (int32_t adjustment, int32_t appendOffset)
{
NS_LOG_FUNCTION (this << adjustment << appendOffset);
if (adjustment == 0 && !IsDirtyAtEnd (appendOffset))
@@ -264,7 +274,7 @@ TagList::AddAtEnd (int32_t adjustment, uint32_t appendOffset)
return;
}
TagList list;
TagList::Iterator i = Begin (0, 0xffffffff);
TagList::Iterator i = BeginAll ();
while (i.HasNext ())
{
TagList::Iterator::Item item = i.Next ();
@@ -290,7 +300,7 @@ TagList::AddAtEnd (int32_t adjustment, uint32_t appendOffset)
}
void
TagList::AddAtStart (int32_t adjustment, uint32_t prependOffset)
TagList::AddAtStart (int32_t adjustment, int32_t prependOffset)
{
NS_LOG_FUNCTION (this << adjustment << prependOffset);
if (adjustment == 0 && !IsDirtyAtStart (prependOffset))
@@ -298,7 +308,7 @@ TagList::AddAtStart (int32_t adjustment, uint32_t prependOffset)
return;
}
TagList list;
TagList::Iterator i = Begin (0, 0xffffffff);
TagList::Iterator i = BeginAll ();
while (i.HasNext ())
{
TagList::Iterator::Item item = i.Next ();

View File

@@ -76,8 +76,8 @@ public:
{
TypeId tid;
uint32_t size;
uint32_t start;
uint32_t end;
int32_t start;
int32_t end;
TagBuffer buf;
Item (TagBuffer buf);
private:
@@ -89,16 +89,16 @@ public:
uint32_t GetOffsetStart (void) const;
private:
friend class TagList;
Iterator (uint8_t *start, uint8_t *end, uint32_t offsetStart, uint32_t offsetEnd);
Iterator (uint8_t *start, uint8_t *end, int32_t offsetStart, int32_t offsetEnd);
void PrepareForNext (void);
uint8_t *m_current;
uint8_t *m_end;
uint32_t m_offsetStart;
uint32_t m_offsetEnd;
int32_t m_offsetStart;
int32_t m_offsetEnd;
uint32_t m_nextTid;
uint32_t m_nextSize;
uint32_t m_nextStart;
uint32_t m_nextEnd;
int32_t m_nextStart;
int32_t m_nextEnd;
};
TagList ();
@@ -116,7 +116,7 @@ public:
*
*
*/
TagBuffer Add (TypeId tid, uint32_t bufferSize, uint32_t start, uint32_t end);
TagBuffer Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end);
/**
* \param o the other list of tags to aggregate.
@@ -138,24 +138,25 @@ public:
* in this list: the boundaries of each tag as reported by their start and
* end offsets will be included within the input offsetStart and offsetEnd.
*/
TagList::Iterator Begin (uint32_t offsetStart, uint32_t offsetEnd) const;
TagList::Iterator Begin (int32_t offsetStart, int32_t offsetEnd) const;
/**
* Adjust the offsets stored internally by the adjustment delta and
* make sure that all offsets are smaller than appendOffset which represents
* the location where new bytes have been added to the byte buffer.
*/
void AddAtEnd (int32_t adjustment, uint32_t appendOffset);
void AddAtEnd (int32_t adjustment, int32_t appendOffset);
/**
* Adjust the offsets stored internally by the adjustment delta and
* make sure that all offsets are bigger than prependOffset which represents
* the location where new bytes have been added to the byte buffer.
*/
void AddAtStart (int32_t adjustment, uint32_t prependOffset);
void AddAtStart (int32_t adjustment, int32_t prependOffset);
private:
bool IsDirtyAtEnd (uint32_t appendOffset);
bool IsDirtyAtStart (uint32_t prependOffset);
bool IsDirtyAtEnd (int32_t appendOffset);
bool IsDirtyAtStart (int32_t prependOffset);
TagList::Iterator BeginAll (void) const;
struct TagListData *Allocate (uint32_t size);
void Deallocate (struct TagListData *data);