BUG#:8705
authormarek <marek>
Fri, 29 Jan 2010 10:08:02 +0000 (10:08 +0000)
committermarek <marek>
Fri, 29 Jan 2010 10:08:02 +0000 (10:08 +0000)
TITLE: OrderedSet overwriting memory of stored Object representations

DESCRIPTION:

src/Pegasus/Common/Buffer.h
src/Pegasus/Common/OrderedSet.h

index 4a8891662729b840fb57f3fce9e3e95f512fe270..b9298b57467622bc79d05eecb6a6a7ad2f2d1436 100644 (file)
@@ -72,6 +72,13 @@ public:
      */
     const char* getData() const;
 
+    /**
+        Returns a pointer to the character buffer with the Buffer contents.
+        This function does NOT append a null character.
+        Resulting data should NOT be used with C string processing functions.
+    */
+    char* getContentPtr();
+
     char get(Uint32 i) const;
 
     void set(Uint32 i, char x);
@@ -157,6 +164,11 @@ inline const char* Buffer::getData() const
     return _rep->data;
 }
 
+inline char* Buffer::getContentPtr()
+{
+    return _rep->data;
+}
+
 inline char Buffer::get(Uint32 i) const
 {
     return _rep->data[i];
index 75111772956fb05edb07d6d26c45cf1b2e6fd5e8..acfe33a0881af0682979a51295bc5f1754007cfc 100644 (file)
@@ -168,7 +168,7 @@ inline OrderedSet<T, R, N>::~OrderedSet()
     // avoids creation of an empty buffer getting build
     if (_size > 0)
     {
-        Node* data = (Node*) _array.getData();
+        Node* data = (Node*) _array.getContentPtr();
 
         for (Uint32 i = 0; i < _size; i++)
         {
@@ -188,7 +188,7 @@ inline void OrderedSet<T, R, N>::clear()
         memset((*_table), 0, sizeof(Node*) * N);
     if (_size > 0)
     {
-        Node* data = (Node*) _array.getData();
+        Node* data = (Node*) _array.getContentPtr();
 
         for (Uint32 i = 0; i < _size; i++)
         {
@@ -270,7 +270,7 @@ inline void OrderedSet<T, R, N>::append(const T& x)
 
     // Now add to hash table
     {
-        Node* data = (Node*) _array.getData();
+        Node* data = (Node*) _array.getContentPtr();
         (*_table)[code] = &data[_size];
     }
 
@@ -292,7 +292,7 @@ inline void OrderedSet<T, R, N>::remove(Uint32 index)
 
     // Remove node from array (dynamic, ordered list)
     {
-        Node* node = (Node*) _array.getData() + index;
+        Node* node = (Node*) _array.getContentPtr() + index;
         node->rep->decreaseOwnerCount();
         node->rep->Dec();
         _array.remove(index * Uint32(sizeof(Node)), Uint32(sizeof(Node)));
@@ -351,7 +351,7 @@ inline T& OrderedSet<T, R, N>::operator[](Uint32 index)
     if (index >= _size)
         throw IndexOutOfBoundsException();
 
-    const Node* node = (const Node*) _array.getData() + index;
+    const Node* node = (const Node*) _array.getContentPtr() + index;
     return *const_cast<T*>(reinterpret_cast<const T*>(node));
 }
 
@@ -368,7 +368,7 @@ void OrderedSet<T, R, N>::_reorganize()
        current state of the dynamic, ordered list
     */
     memset((*_table), 0, sizeof(Node*) * N);
-    Node* data = (Node*) _array.getData();
+    Node* data = (Node*) _array.getContentPtr();
 
     for (Uint32 i = 0; i < _size; i++)
     {